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 — Add __get__ to the partial object · Issue #121027 · python/cpython

Add __get__ to the partial object #121027

New issue
Copy link
New issue
Copy link
Closed
Closed
Add __get__ to the partial object#121027
Copy link
Labels
3.14bugs and security fixesbugs and security fixestype-featureA feature request or enhancementA feature request or enhancement

Description

@serhiy-storchaka
serhiy-storchaka
opened on Jun 26, 2024
Issue body actions

Feature or enhancement

In #119827 (comment), @rhettinger proposed to add the __get__ method to the partial object in functools. This is a breaking change, although the impact may be much lesser than of adding __get__ to builtin functions. But we should follow the common procedure for such changes: first add __get__ that emits FutureWarning with suggestion to wrap partial into staticmethod and return the partial object unchanged, then change the behavior few releases later.

Linked PRs

  • gh-121027: Add a future warning in functools.partial.__get__ #121086
  • gh-121027: Make the functools.partial object a method descriptor #121089
  • [3.13] gh-121027: Add a future warning in functools.partial.__get__ (GH-121086) #121092

Activity

Next
  1. serhiy-storchaka
    added
    type-featureA feature request or enhancementA feature request or enhancement
    3.14bugs and security fixesbugs and security fixes
    on Jun 26, 2024
  2. ncoghlan commented on Jun 26, 2024

    @ncoghlan
    ncoghlan
    on Jun 26, 2024
    Contributor
    More actions

    The "Does practicality beat purity?" question also applies here.

    Yes, if we'd had the placeholder functionality all along we might never have added partialmethod, but given that we did add it, what are we gaining by adding partial.__get__ that justifies the migration cost of having to wrap instances in staticmethod to get the old behaviour back when it was actually desired?

  3. serhiy-storchaka commented on Jun 26, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Jun 26, 2024
    MemberAuthor
    More actions

    I do not know. I have not found any issue which could be solved by adding __get__ to partial. The migration cost could be not high, but the benefit is unclear to me. It may simplify the partialmethod implementation in long run, but I did not check this.

  4. serhiy-storchaka commented on Jun 26, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Jun 26, 2024
    MemberAuthor
    More actions

    For clarification, I do not oppose this feature. But there is a procedure for making breaking changes. It should not bit buried as a side effect of adding other feature.

    This can be worked around with significant core developer support if we decide the benefit of immediate change outweighs the risk. Or if we reclassify it as a bugfix.

  5. rhettinger commented on Jun 26, 2024

    @rhettinger
    rhettinger
    on Jun 26, 2024
    Contributor
    More actions

    what are we gaining by adding partial.get

    We are avoiding a problem that formerly didn't present itself. Partial is almost entirely understood as being an equivalent to a lambda or def. Before `Placeholder' was added, no one would encounter this. Now, it is a certitude.

    Without adding __get__, one user after another will have to discover the hard way that these two are not equivalent:

    set_alive2 = lambda self: self.set_state(True)  
    set_alive3 = partial(set_state, Placeholder, True)
    

    When they learn about the non-equivalence, it will break their mental model of partial() as it did for me.

    Next, they will have to discover a workaround with partialmethod() which is mostly unused, mostly unknown, and really shouldn't be necessary anymore.

    I don't think it should be acceptable to leave partial() in a non-harmonious state just because partialmethod() exists. The mental model of equivalence with lambda and def is too important.

    Reacted by Nice Zombies, Alyssa Coghlan, dgpb, Max Kühn, jfs and Jacob Chapman
  6. rhettinger commented on Jun 26, 2024

    @rhettinger
    rhettinger
    on Jun 26, 2024
    Contributor
    More actions

    Also, I don't think there is much of a downside. The docs for partial() don't promise to not act like a regular function in a class. It is certainly isn't an advertised feature of partial() that "I am just like an equivalent def or lambda but can't be used as a method."

    There might be some minor disruption but it leads to a better designed more clear outcome than being trapped into a surprising behavior that was never intended.

    If __get__ is not added, I'm thinking of withdrawing my support for Placeholder because it would make this wart prominent and it would limit natural uses of the new feature.

  7. serhiy-storchaka commented on Jun 26, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Jun 26, 2024
    MemberAuthor
    More actions

    As an option, we can add __get__ that emits a FutureWarning in 3.13 and change the behavior in 3.14. This will not delay introducion of Placeholder.

    It may be late for a beta stage, but the premise is that it will not affect much user code. If this is true, adding it in 3.13 is safe. If it is not true, it is still better than breaking that code without a warning.

    Surprisingly, it only breaks few recently added tests in the CPython test suite, and these tests were added specially to test how the code handles such weird corner case. They do not establish the correct behavior, they test that the current behavior will not be changed unintentionally.

    cc @Yhg1s as the RM

  8. rhettinger commented on Jun 26, 2024

    @rhettinger
    rhettinger
    on Jun 26, 2024
    Contributor
    More actions

    +1 for adding a FutureWarning to 3.13 if it is still possible. I expect that people with encounter it rarely and that the workaround is to just wrap partial with staticmethod making the behavior explicit.

    It would also be reasonable to just put a note in the docs. This wasn't a behavior previously promised in the docs and isn't something that people would typically encounter. I've taught partial to thousands of people and only noticed the absence of __get__ when the new Placeholder option became available.

    get the old behaviour back when it was actually desired?
    As near as I can tell, this is almost never desired. And as a code reviewer if someone wanted this behavior, it should be made explicit because almost no one knows about it and it is surprising.

  9. serhiy-storchaka
    added 3 commits that reference this issue on Jun 27, 2024

    pythongh-121027: Add a future warning in functools.partial.__get__

    b057ae6

    pythongh-121027: Make the functools.partial object a method descriptor

    5ecccee

    pythongh-121027: Make the functools.partial object a method descriptor

    693fbc7
  10. Yhg1s
    added a commit that references this issue on Jun 27, 2024

    gh-121027: Add a future warning in functools.partial.__get__ (#121086)

    db96edd
  11. miss-islington
    added a commit that references this issue on Jun 27, 2024

    pythongh-121027: Add a future warning in functools.partial.__get__ (p…

    872bb29
  12. serhiy-storchaka
    added a commit that references this issue on Jun 27, 2024

    pythongh-121027: Make the functools.partial object a method descriptor

    d752505
  13. 5 remaining items

  14. PeterJCLaw commented on Jul 4, 2024

    @PeterJCLaw
    PeterJCLaw
    on Jul 4, 2024
    Contributor
    More actions

    In #119827 (comment), @rhettinger proposed to add the __get__ method to the partial object in functools. This is a breaking change, although the impact may be much lesser than of adding __get__ to builtin functions. But we should follow the common procedure for such changes: first add __get__ that emits FutureWarning with suggestion to wrap partial into staticmethod and return the partial object unchanged, then change the behavior few releases later.

    I'm not sure whether your comment "This is a breaking change" is intended to refer to the future change to make the __get__ method return something other than self, or to the change as currently implemented, though I'm guessing the former. Either way, I wanted to highlight that the change as implemented may already be breaking for some use-cases. In particular tools which rely on introspection of code objects may be caught by this, as Jedi has been (it renders function signatures for method descriptors differently than other functions or class instances). Jedi can almost certainly cope with this, so I'm not arguing either for or against this change -- just wanted to share the impact that this has already had in case there might be other consequences of functools.partial being detected to be a descriptor.

  15. serhiy-storchaka commented on Jul 5, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Jul 5, 2024
    MemberAuthor
    More actions

    It referred to the future change, but, unfortunately, adding even trivial __get__() that returns self is a breaking change. It required changing the inspect.signature() code, and may also affect the third-party code. There is no good solution for this.

  16. estyxx
    added 2 commits that reference this issue on Jul 17, 2024

    pythongh-121027: Add a future warning in functools.partial.__get__ (p…

    86a23c9

    pythongh-121027: Make the functools.partial object a method descriptor (

    d56f949
  17. millerdev
    added 4 commits that reference this issue on Apr 8, 2025

    functools.partial will be a method descriptor

    a616fb5

    functools.partial will be a method descriptor

    7068e92

    functools.partial will be a method descriptor

    f97b11d

    functools.partial will be a method descriptor

    bc5cad9
  18. randomir
    added a commit that references this issue on Oct 17, 2025

    With py39 dropped, revert 44d628d as not needed anymore

    befbf1a
  19. Andykl
    added a commit that references this issue on Apr 3, 2026

    Futureproof `functools.partial` uses

    a0efe35
  20. LunaTheFoxgirl
    added a commit that references this issue on May 7, 2026

    Futureproof `functools.partial` uses

    1a16380
  21. james-garner-canonical
    added a commit that references this issue on Jun 23, 2026

    ci: test Ops 2.23 with Python 3.14 (#2576)

    5698b3f
  22. JelleZijlstra
    added a commit that references this issue on Sep 6, 2026

    Add `functools.partial.__get__` for Python 3.14 (#15977)

    733fe4a
  23. JerryChen97
    added a commit that references this issue on Sep 8, 2026

    Fix Python 3.14 CI failures in test_composite2.py

    e9553fb
  24. github-merge-queue
    added a commit that references this issue on Sep 10, 2026

    Fix Python 3.14 CI failures in test_composite2.py (#10125)

    1f51ae2
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

    3.14bugs and security fixesbugs and security fixestype-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 01402503 — 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.