[Python-checkins] bpo-46764: Fix wrapping bound method with @classmethod (#31367)
rhettinger
webhook-mailer at python.org
Thu May 5 00:00:38 EDT 2022
https://github.com/python/cpython/commit/a918589578a2a807396c5f6afab7b59ab692c642
commit: a918589578a2a807396c5f6afab7b59ab692c642
branch: main
author: Michael J. Sullivan <sully at msully.net>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2022-05-04T23:00:21-05:00
summary:
bpo-46764: Fix wrapping bound method with @classmethod (#31367)
files:
A Misc/NEWS.d/next/Core and Builtins/2022-02-16-03-23-38.bpo-46764.wEY4bS.rst
M Lib/test/test_decorators.py
M Objects/classobject.c
diff --git a/Lib/test/test_decorators.py b/Lib/test/test_decorators.py
index 57a741ffd2974..a6baa3ad1dd6b 100644
--- a/Lib/test/test_decorators.py
+++ b/Lib/test/test_decorators.py
@@ -330,6 +330,16 @@ def outer(cls):
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 0000000000000..f69793cd2d7b8
--- /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 cf731358e41c4..b9708ba0e41a3 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,
};
More information about the Python-checkins
mailing list