[issue46764] Wrapping a bound method with a @classmethod no longer works
New submission from Michael J. Sullivan : 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) -- components: Interpreter Core messages: 413310 nosy: msullivan priority: normal severity: normal status: open title: Wrapping a bound method with a @classmethod no longer works versions: Python 3.10, Python 3.11, Python 3.9 ___ Python tracker <https://bugs.python.org/issue46764> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46764] Wrapping a bound method with a @classmethod no longer works
Change by Michael J. Sullivan : -- keywords: +patch pull_requests: +29517 stage: -> patch review pull_request: https://github.com/python/cpython/pull/31367 ___ Python tracker <https://bugs.python.org/issue46764> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36878] ast.parse with type_comments=True should allow extra text after # type: ignore
Change by Michael J. Sullivan : -- pull_requests: +13419 ___ Python tracker <https://bugs.python.org/issue36878> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36878] ast.parse with type_comments=True should allow extra text after # type: ignore
Michael J. Sullivan added the comment: I think this is done! -- ___ Python tracker <https://bugs.python.org/issue36878> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37017] Use LOAD_METHOD optimization in CallMethod C API functions
New submission from Michael J. Sullivan : The different varieties of PyObject_CallMethod* routines all operate by doing a PyObject_GetAttr to fetch an object to call. It seems likely to be worthwhile to take advantage of the LOAD_METHOD optimization that avoids creating a bound method object when calling a method. -- components: Extension Modules messages: 343259 nosy: msullivan priority: normal severity: normal status: open title: Use LOAD_METHOD optimization in CallMethod C API functions versions: Python 3.8 ___ Python tracker <https://bugs.python.org/issue37017> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37017] Use LOAD_METHOD optimization in CallMethod C API functions
Change by Michael J. Sullivan : -- keywords: +patch pull_requests: +13433 stage: -> patch review ___ Python tracker <https://bugs.python.org/issue37017> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37017] Use LOAD_METHOD optimization in CallMethod C API functions
Change by Michael J. Sullivan : -- nosy: +brett.cannon, serhiy.storchaka, vstinner, yselivanov ___ Python tracker <https://bugs.python.org/issue37017> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37017] Use LOAD_METHOD optimization in CallMethod C API functions
Michael J. Sullivan added the comment: I believe that this is orthogonal to PEP 590. PyObject_CallMethodObjArgs and friends take varargs which need to be copied into an array one way or another. It is easy (and efficient) to prepend the base while copying the function arguments into the array (see the attached PR). I don't think that vector call will change anything about this. -- ___ Python tracker <https://bugs.python.org/issue37017> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com