You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wrapping a bound method with a @classmethod no longer works #90920
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/rhettinger'closed_at=Nonecreated_at=<Date2022-02-16.01:56:29.217>labels= ['interpreter-core', 'type-bug', '3.9', '3.10', '3.11']
title='Wrapping a bound method with a @classmethod no longer works'updated_at=<Date2022-02-17.20:02:42.052>user='https://github.com/msullivan'
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)
This seems like a reasonable fix. I'll wait a bit so that others can comment as well.
FWIW, we looking a potentially reverting the whole line of development starting with that commit. It has caused a number of problems and no longer looks tenable. See https://bugs.python.org/issue45356
Activity
msullivan commentedon Feb 16, 2022
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)
rhettinger commentedon Feb 17, 2022
This seems like a reasonable fix. I'll wait a bit so that others can comment as well.
FWIW, we looking a potentially reverting the whole line of development starting with that commit. It has caused a number of problems and no longer looks tenable. See https://bugs.python.org/issue45356
iritkatriel commentedon Oct 7, 2022
The PR was merged, and I think it resolves this issue.
iritkatriel commentedon Oct 7, 2022
Unless it can still be backported.