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 — Changed behavior of <instancemethod>.__get__ in Python 3.11 · Issue #113157 · python/cpython

Changed behavior of <instancemethod>.__get__ in Python 3.11 #113157

New issue
Copy link
New issue
Copy link
Closed
Closed
Changed behavior of <instancemethod>.__get__ in Python 3.11#113157
Copy link
Assignees
rhettinger
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@mschmitzer
mschmitzer
opened on Dec 15, 2023
Issue body actions

Bug report

Bug description:

There is a change in behavior in Python 3.11 that does not seem to be described in the "what's new" document.

In the following code:

class A:
    def meth(self):
      print(self)

class B:
    pass

a = A()
b = B()
b.meth = a.meth.__get__(b, B)
b.meth()

The b.meth() call receives a as the self argument up to Python 3.10, but b in 3.11 and 3.12.

This pattern is used by the Pyramid framework. The change breaks Pyramid applications that use add_request_method(someobject.somemethod, "name").

I have to admit that I do not understand the descriptor protocol (or the documentation of __get__) well enough to say whether this is a legitimate use case, but it does exist in the wild.

CPython versions tested on:

3.9, 3.10, 3.11, 3.12

Operating systems tested on:

Linux

Linked PRs

  • gh-113157 gh-89519: Fix method descriptors #113233
  • gh-113157: Document and test __get__ for MethodType #115492

Activity

  1. mschmitzer
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Dec 15, 2023
  2. Eclips4 commented on Dec 15, 2023

    @Eclips4
    Eclips4
    on Dec 15, 2023
    Member
    More actions

    Bisected to a918589
    cc @msullivan @rhettinger

  3. rhettinger
    self-assigned this
    on Dec 17, 2023
  4. rhettinger commented on Dec 17, 2023

    @rhettinger
    rhettinger
    on Dec 17, 2023
    Contributor
    More actions

    @MarcSchmitzer is correct and the "return a" behavior should be restored.

    For Python 3.13, this is straightforward. Since classmethod descriptor chaining has now been removed, we can just add back method_descr_get to PyMethod_Type.

    For Python 3.11 and Python 3.12, the situation is more complex and we can't fix any one aspect of the problem without breaking something else. Here are the options that come to mind:

    1. Leave Python 3.11 and 3.12 as-is. But that would be a problem for the Pyramid framework.
    2. Revert a918589 . But that would break @msullivan 's use case.
    3. Apply the 3.13 solution to 3.11 and 3.12. This is the cleanest way in the sense that we will have fully restored the original long-standing behaviors before the classmethod descriptor chaining trainwreck began. However, this path breaks having classmethod wrap property which is something that we know people use — that is why we went through a deprecation period to finally remove it in 3.13.
  5. rhettinger
    added a commit that references this issue on Dec 17, 2023

    pythongh-113157 pythongh-89519 Restore behaviors before classmethod d…

    172f34a
  6. rhettinger commented on Dec 19, 2023

    @rhettinger
    rhettinger
    on Dec 19, 2023
    Contributor
    More actions

    @msullivan Would you be okay with reverting a918589 ? We wouldn't have gone down that path had we known that it would break another part of the API.

  7. rhettinger commented on Dec 21, 2023

    @rhettinger
    rhettinger
    on Dec 21, 2023
    Contributor
    More actions

    For 3.11 and 3.12, I suggest that we revert a918589

    Any objections?

  8. rhettinger
    added a commit that references this issue on Dec 21, 2023

    gh-113157 gh-89519: Fix method descriptors (gh-113233)

    d058eae
  9. erlend-aasland commented on Dec 22, 2023

    @erlend-aasland
    erlend-aasland
    on Dec 22, 2023
    Contributor
    More actions

    For 3.11 and 3.12, I suggest that we revert a918589

    Any objections?

    cc. @pablogsal as 3.11 RM, and @Yhg1s as 3.12 RM.

  10. facebook-github-bot
    added a commit that references this issue on Dec 22, 2023

    gh-89519 & gh-113157 (Remove classmethod descriptor chaining, depreca…

    f508768
  11. ryan-duve
    added a commit that references this issue on Dec 26, 2023

    pythongh-113157 pythongh-89519: Fix method descriptors (pythongh-113233)

    278a514
  12. kulikjak
    added a commit that references this issue on Jan 22, 2024

    pythongh-113157 pythongh-89519: Fix method descriptors (pythongh-113233)

    b9f2300
  13. aisk
    added a commit that references this issue on Feb 11, 2024

    pythongh-113157 pythongh-89519: Fix method descriptors (pythongh-113233)

    ead59a8
  14. rhettinger
    added 2 commits that reference this issue on Feb 14, 2024

    pythongh-113157: Document and test __get__ for MethodType

    17144a5

    gh-113157: Document and test __get__ for MethodType (gh-115492)

    acda175
  15. woodruffw
    added a commit that references this issue on Mar 4, 2024

    pythongh-113157: Document and test __get__ for MethodType (pythongh-1…

    2bf8232
  16. diegorusso
    added a commit that references this issue on Apr 17, 2024

    pythongh-113157: Document and test __get__ for MethodType (pythongh-1…

    eb3c03c
  17. Glyphack
    added a commit that references this issue on Sep 2, 2024

    pythongh-113157 pythongh-89519: Fix method descriptors (pythongh-113233)

    602f955
  18. LukasWoodtli
    added a commit that references this issue on Jan 22, 2025

    pythongh-113157: Document and test __get__ for MethodType (pythongh-1…

    378ae21
  19. hugovk commented on Oct 23, 2026

    @hugovk
    hugovk
    on Oct 23, 2026
    Member
    More actions

    3.11 and 3.12 are now security-only.

  20. hugovk
    closed this as completedon Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @rhettinger
    rhettinger

Labels

type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

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.