Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/test/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix wrapping bound methods with @classmethod
8 changes: 0 additions & 8 deletions Objects/classobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
};

Expand Down