From: Michael J. Sullivan Date: Thu, 5 May 2022 04:00:21 +0000 (-0700) Subject: bpo-46764: Fix wrapping bound method with @classmethod (#31367) X-Git-Tag: v3.11.0b1~48 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a918589578a2a807396c5f6afab7b59ab692c642;p=thirdparty%2FPython%2Fcpython.git bpo-46764: Fix wrapping bound method with @classmethod (#31367) --- diff --git a/Lib/test/test_decorators.py b/Lib/test/test_decorators.py index 57a741ffd297..a6baa3ad1dd6 100644 --- a/Lib/test/test_decorators.py +++ b/Lib/test/test_decorators.py @@ -330,6 +330,16 @@ class TestDecorators(unittest.TestCase): self.assertEqual(Class().inner(), 'spam') self.assertEqual(Class().outer(), 'eggs') + def test_bound_function_inside_classmethod(self): + class A: + def foo(self, cls): + return 'spam' + + class B: + bar = classmethod(A().foo) + + self.assertEqual(B.bar(), 'spam') + def test_wrapped_classmethod_inside_classmethod(self): class MyClassMethod1: def __init__(self, func): diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-02-16-03-23-38.bpo-46764.wEY4bS.rst b/Misc/NEWS.d/next/Core and Builtins/2022-02-16-03-23-38.bpo-46764.wEY4bS.rst new file mode 100644 index 000000000000..f69793cd2d7b --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-02-16-03-23-38.bpo-46764.wEY4bS.rst @@ -0,0 +1 @@ +Fix wrapping bound methods with @classmethod diff --git a/Objects/classobject.c b/Objects/classobject.c index cf731358e41c..b9708ba0e41a 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -321,13 +321,6 @@ method_traverse(PyMethodObject *im, visitproc visit, void *arg) return 0; } -static PyObject * -method_descr_get(PyObject *meth, PyObject *obj, PyObject *cls) -{ - Py_INCREF(meth); - return meth; -} - PyTypeObject PyMethod_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) .tp_name = "method", @@ -348,7 +341,6 @@ PyTypeObject PyMethod_Type = { .tp_methods = method_methods, .tp_members = method_memberlist, .tp_getset = method_getset, - .tp_descr_get = method_descr_get, .tp_new = method_new, };