-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-115231: fill __module__ for built-in class/staticmethods #115232
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
base: main
Are you sure you want to change the base?
Changes from all commits
9b31877
be1c7ef
1f854ee
c4dec10
1e25d84
63b05a0
777bc8d
d1650bf
d0f5bb0
e20339b
4ba1288
543a5b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Setup ``__module__`` attribute for built-in class/static methods. Patch by | ||
Sergey B Kirpichev. |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -130,7 +130,11 @@ classmethod_get(PyObject *self, PyObject *obj, PyObject *type) | |||||||
if (descr->d_method->ml_flags & METH_METHOD) { | ||||||||
cls = descr->d_common.d_type; | ||||||||
} | ||||||||
return PyCMethod_New(descr->d_method, type, NULL, cls); | ||||||||
PyObject *mod = PyObject_GetAttr((PyObject*)type, &_Py_ID(__module__)); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will add an overhead for use of class methods. We should try to find other solution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You meant for adding static/class methods?
Unlikely e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR updated to use type_module(). For classmethods, I doubt there is another solution. Here is a micro-benchmark:
@serhiy-storchaka, does the rest (static methods) looks sane for you? If so, I'll create a separate pr just for that case. import pyperf
runner = pyperf.Runner()
n = 'from_bytes'
runner.bench_func('int.from_bytes', getattr, int, n) |
||||||||
PyErr_Clear(); | ||||||||
PyObject *result = PyCMethod_New(descr->d_method, type, mod, cls); | ||||||||
Py_XDECREF(mod); | ||||||||
return result; | ||||||||
} | ||||||||
|
||||||||
static PyObject * | ||||||||
|
Uh oh!
There was an error while loading. Please reload this page.