From a918589578a2a807396c5f6afab7b59ab692c642 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Wed, 4 May 2022 21:00:21 -0700 Subject: bpo-46764: Fix wrapping bound method with @classmethod (#31367) --- Lib/test/test_decorators.py | 10 ++++++++++ .../Core and Builtins/2022-02-16-03-23-38.bpo-46764.wEY4bS.rst | 1 + Objects/classobject.c | 8 -------- 3 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-02-16-03-23-38.bpo-46764.wEY4bS.rst diff --git a/Lib/test/test_decorators.py b/Lib/test/test_decorators.py index 57a741f..a6baa3a 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 0000000..f69793c --- /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 cf73135..b9708ba 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, }; -- cgit v0.12