Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
gh-144330: Initialize classmethod and staticmethod in new#144469
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 ourterms of service andprivacy 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?
Conversation
Move classmethod and staticmethod initialization from __init__() to__new__().PyClassMethod_New() and PyStaticMethod_New() now copy attributes ofthe wrapped functions: __module__, __name__, __qualname__ and__doc__.Change static type initialization: initialize PyStaticMethod_Type andPyCFunction_Type earlier.Remove test_refleaks_in_classmethod___init__() andtest_refleaks_in_staticmethod___init__() tests from test_descr sinceclassmethod and staticmethod have no __init__() method anymore.
vstinner commentedFeb 4, 2026
vstinner commentedFeb 4, 2026
With this change, |
| cm_descr_get(PyObject *self, PyObject *obj, PyObject *type) | ||
| { | ||
| classmethod *cm = (classmethod *)self; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Should we add an assert here likeassert(cm->cm_callable != NULL)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I would prefer to not add an assertion sincecm->cm_callable is used in multiple places without checking that it's notNULL. With this change,cm->cm_callable cannot beNULL anymore. In practice, it can beNULL ifcm_new() fails: onlycm_dealloc() has to deal withNULL.
| sm_descr_get(PyObject *self, PyObject *obj, PyObject *type) | ||
| { | ||
| staticmethod *sm = (staticmethod *)self; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Same here
Uh oh!
There was an error while loading.Please reload this page.
Move classmethod and staticmethod initialization frominit() tonew().
PyClassMethod_New() and PyStaticMethod_New() now copy attributes of the wrapped functions:
__module__,__name__,__qualname__and__doc__.Change static type initialization: initialize PyStaticMethod_Type and PyCFunction_Type earlier.
Remove test_refleaks_in_classmethod___init__() and test_refleaks_in_staticmethod___init__() tests from test_descr since classmethod and staticmethod have no
__init__()method anymore.classmethodandstaticmethodcan crash withNULL/ uninitialized callables #144330