GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `functools.partialmethod` simplification · Issue #124652 · python/cpython

functools.partialmethod simplification #124652

New issue
Copy link
New issue
Copy link
Open
3 / 33 of 3 issues completed
Open
functools.partialmethod simplification#124652
3 / 33 of 3 issues completed
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@dg-pb
dg-pb
opened on Sep 27, 2024
Issue body actions

Feature or enhancement

Proposal:

Now, as partial has __get__ and Placeholder it is probably a good idea to simplify partialmethod.

So the mental model of partialmethod can simply be:

partial, which always has the first argument set to Placeholder.

So partialmethod could maybe be a subclass partial, which would potentially simplify things.

Also, maybe there is a way so that partialmethod can be made obsolete altogether.

Will see where I can get to with this.
Any ideas welcome.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

#121027
#119827 (comment)

Linked PRs

  • gh-124652: partialmethod simplifications #124788

Activity

  1. dg-pb
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Sep 27, 2024
  2. rhettinger commented on Sep 27, 2024

    @rhettinger
    rhettinger
    on Sep 27, 2024
    Contributor
    More actions

    Note that partialmethod also copies __isabstractmethod__ from the underlying callable.

    Reacted by Nice Zombies and dgpb
  3. dg-pb
    added a commit that references this issue on Sep 30, 2024

    add commented fix if merging after pythongh-124652

    a7142d5
  4. dg-pb commented on Oct 2, 2024

    @dg-pb
    dg-pb
    on Oct 2, 2024
    ContributorAuthor
    More actions

    PR is ready for review.

    Quick summary of what I have done and thought of:

    1. Considered implementing __isabstractmethod__ property for partial so that it returns it from the wrapped function. However, this is not a good idea, because in this case it would be impossible to set __isabstractmethod__ property for it. Also, it would be a divergent behaviour from FunctionType. In short, I kept the same abstract method attribute logic for partial and partialmethod as before.
    2. Relaxed trailing placeholder restriction. This way the behaviour of object is more robust, more functional and behaves naturally given functionality definition. E.g. If I know that Placeholder is for positional arguments, then trailing placeholder will convert it to "positional only". And I can not see a good reason why trailing placeholders need to be prohibited. Also, such behaviour stems naturally from definition of functionality, while forbidding or automatically trimming trailing placeholders would require special mention in documentation.
    3. partialmethod could be made redundant for standard method cases. However, there is one case that it is able to handle that could not be done without it, which is "Unknown descriptor" case, where partial needs to be applied at runtime on callable which is returned from __get__ of wrapped function.

    E.g.:

    class D:
        def __get__(self, obj, cls):
            return (lambda a, b: None)
    
    class A:
        d = D()
    
        @staticmethod
        def s(a, b):
            pass
    
        @classmethod
        def c(self, a, b):
            pass
    
        ps = staticmethod(partial(s.__wrapped__, 1))
        pc = classmethod(partial(c.__wrapped__, Placeholder, 1))
        pd = ?    # needs `partialmethod`

    Thus, I have modified partialmethod so that it does not do any heavy partial-like logic itself, but instead passes all of it to partial.

    This allowed removing partialmethod special casing from inspect.signature.

    More details in description of PR.

  5. dg-pb
    added a commit that references this issue on Oct 17, 2024

    Merge remote-tracking branch 'upstream/main' into pythongh-124652-par…

    79e9cff
  6. dg-pb commented on Jan 6, 2025

    @dg-pb
    dg-pb
    on Jan 6, 2025
    ContributorAuthor
    More actions

    Likely most convenient merge order

    • restricting keyword Placeholders: gh-125028: Prohibit placeholders in partial keywords #126062
    • vectorcall with bound keywords: gh-119109: improve functools.partial vectorcall with keywords #124584
    • partialmethod simplification: gh-124652: partialmethod simplifications #124788
    • allowing trailing placeholders: gh-128644: functools.partial: Allowing trailing Placeholders #128649
  7. picnixz
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Jan 7, 2025
  8. dg-pb
    added a commit that references this issue on May 8, 2025

    Merge remote-tracking branch 'upstream/main' into pythongh-124652-par…

    ec64137
  9. dg-pb
    added a commit that references this issue on Sep 9, 2025

    Merge remote-tracking branch 'upstream/main' into pythongh-124652-par…

    4dee90c
  10. serhiy-storchaka
    added sub-issues on Nov 23, 2025
    • Prohibit placeholders in partial keywords #125028
    • Missing validation for allowed constant values in ast.literal_eval() #141778
  11. serhiy-storchaka
    removed a sub-issue on Nov 23, 2025
    • Missing validation for allowed constant values in ast.literal_eval() #141778
  12. serhiy-storchaka
    added sub-issues on Nov 23, 2025
    • functools.partial does not re-set vector call. #119109
    • functools.partial: Allowing trailing Placeholders #128644
  13. dg-pb
    added a commit that references this issue on Sep 1, 2026

    Merge remote-tracking branch 'upstream/main' into pythongh-124652-par…

    0b38bb8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.