bpo-46764: Fix wrapping bound method with @classmethod (#31367)

This commit is contained in:
Michael J. Sullivan 2022-05-04 21:00:21 -07:00 committed by GitHub
parent d1b2e989be
commit a918589578
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions

View file

@ -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):

View file

@ -0,0 +1 @@
Fix wrapping bound methods with @classmethod

View file

@ -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,
};