summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael J. Sullivan <sully@msully.net>2022-05-05 04:00:21 (GMT)
committerGitHub <noreply@github.com>2022-05-05 04:00:21 (GMT)
commita918589578a2a807396c5f6afab7b59ab692c642 (patch)
tree4a415ddc98ecfe894e49ea9c2067085caad9236a
parentd1b2e989be2bc5128d6602e4f370d0ee6f5ac476 (diff)
downloadcpython-a918589578a2a807396c5f6afab7b59ab692c642.zip
cpython-a918589578a2a807396c5f6afab7b59ab692c642.tar.gz
cpython-a918589578a2a807396c5f6afab7b59ab692c642.tar.bz2
bpo-46764: Fix wrapping bound method with @classmethod (#31367)
-rw-r--r--Lib/test/test_decorators.py10
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2022-02-16-03-23-38.bpo-46764.wEY4bS.rst1
-rw-r--r--Objects/classobject.c8
3 files changed, 11 insertions, 8 deletions
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,
};