mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-46764: Fix wrapping bound method with @classmethod (#31367)
This commit is contained in:
parent
d1b2e989be
commit
a918589578
3 changed files with 11 additions and 8 deletions
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
Fix wrapping bound methods with @classmethod
|
||||
|
|
@ -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,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue