8000 bpo-46764: Fix wrapping bound method with @classmethod (#31367) · python/cpython@a918589 · GitHub
[go: up one dir, main page]

Skip to content

Commit a918589

Browse files
authored
bpo-46764: Fix wrapping bound method with @classmethod (#31367)
1 parent d1b2e98 commit a918589

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

Lib/test/test_decorators.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,16 @@ def outer(cls):
330330
self.assertEqual(Class().inner(), 'spam')
331331
self.assertEqual(Class().outer(), 'eggs')
332332

333+
def test_bound_function_inside_classmethod(self):
334+
class A:
335+
def foo(self, cls):
336+
return 'spam'
337+
338+
class B:
339+
bar = classmethod(A().foo)
340+
341+
self.assertEqual(B.bar(), 'spam')
342+
333343
def test_wrapped_classmethod_inside_classmethod(self):
334344
class MyClassMethod1:
335345
def __init__(self, func):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix wrapping bound methods with @classmethod

Objects/classobject.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,6 @@ method_traverse(PyMethodObject *im, visitproc visit, void *arg)
321321
return 0;
322322
}
323323

324-
static PyObject *
325-
method_descr_get(PyObject *meth, PyObject *obj, PyObject *cls)
326-
{
327-
Py_INCREF(meth);
328-
return meth;
329-
}
330-
331324
PyTypeObject PyMethod_Type = {
332325
PyVarObject_HEAD_INIT(&PyType_Type, 0)
333326
.tp_name = "method",
@@ -348,7 +341,6 @@ PyTypeObject PyMethod_Type = {
348341
.tp_methods = method_methods,
349342
.tp_members = method_memberlist,
350343
.tp_getset = method_getset,
351-
.tp_descr_get = method_descr_get,
352344
.tp_new = method_new,
353345
};
354346

0 commit comments

Comments
 (0)
0