Skip to content

Commit b45efcf

Browse files
committed
fill __module__ attribute for built-in classmethods too
1 parent 1f854ee commit b45efcf

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Lib/test/test_funcattrs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,9 @@ def test_builtin__module__(self):
468468
self.assertEqual(decimal.Decimal.exp.__objclass__.__module__, 'decimal')
469469

470470
# builtin classmethod:
471-
self.assertEqual(int.from_bytes.__module__, None)
471+
self.assertEqual(int.from_bytes.__module__, 'builtins')
472472
self.assertEqual(int.from_bytes.__self__.__module__, 'builtins')
473-
self.assertEqual(decimal.Decimal.from_float.__module__, None)
473+
self.assertEqual(decimal.Decimal.from_float.__module__, 'decimal')
474474
self.assertEqual(decimal.Decimal.from_float.__self__.__module__, 'decimal')
475475

476476
# builtin staticmethod:

Objects/descrobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ classmethod_get(PyObject *self, PyObject *obj, PyObject *type)
130130
if (descr->d_method->ml_flags & METH_METHOD) {
131131
cls = descr->d_common.d_type;
132132
}
133-
return PyCMethod_New(descr->d_method, type, NULL, cls);
133+
PyObject *mod;
134+
PyObject_GetOptionalAttr((PyObject*)type, &_Py_ID(__module__), &mod);
135+
return PyCMethod_New(descr->d_method, type, mod, cls);
134136
}
135137

136138
static PyObject *

0 commit comments

Comments
 (0)