This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author msullivan
Recipients msullivan
Date 2022-02-16.01:56:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1644976589.23.0.130675982792.issue46764@roundup.psfhosted.org>
In-reply-to
Content
class A:
    def foo(self, cls): return 1

class B: pass

class B:
    bar = classmethod(A().foo)

B.bar()


In Python 3.8 and prior, this worked. Since Python 3.9, it produces "TypeError: A.foo() missing 1 required positional argument: 'cls'"

I tracked it down, and the issue was introduced by https://github.com/python/cpython/pull/8405/files, which makes classmethod's tp_descr_get invoke its argument tp_descr_get when present instead of calling PyMethod_New. That this was a semantics change that could break existing code may have been missed (though it is a fairly obscure such change).

The reason it breaks this case in particular of bound methods, though, is that bound methods have a tp_descr_get that does nothing (increfs the method and then returns it). Dropping that tp_descr_get fixes this issue and doesn't introduce any test failures. Not sure if there is some potential downstream breakage of that?

(This issue was originally reported to me by Jared Hance)
History
Date User Action Args
2022-02-16 01:56:29msullivansetrecipients: + msullivan
2022-02-16 01:56:29msullivansetmessageid: <1644976589.23.0.130675982792.issue46764@roundup.psfhosted.org>
2022-02-16 01:56:29msullivanlinkissue46764 messages
2022-02-16 01:56:29msullivancreate