-
-
Notifications
You must be signed in to change notification settings - Fork 34k
gh-144330: Initialize staticmethod/classmethod callables in tp_new #144364
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?
Conversation
|
You need to update your branch to fix the CI, it is currently incompatible. |
| cm->cm_callable = Py_NewRef(Py_None); | ||
| cm->cm_dict = NULL; | ||
| return (PyObject *)cm; | ||
| } |
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.
Move cm_new() before PyClassMethod_Type, so you don't need to declare it in advance (remove forward declaration line 1558).
| sm->sm_callable = Py_NewRef(Py_None); | ||
| sm->sm_dict = NULL; | ||
| return (PyObject *)sm; | ||
| } |
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.
Move sm_new() before PyStaticMethod_Type.
| classmethod *cm = (classmethod *)PyType_GenericAlloc(type, 0); | ||
| if (cm == NULL) | ||
| return NULL; | ||
| cm->cm_callable = Py_NewRef(Py_None); |
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.
None is immortal so you can just write:
| cm->cm_callable = Py_NewRef(Py_None); | |
| cm->cm_callable = Py_None; |
Same remark in sm_new().
| if (cm == NULL) | ||
| return 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.
PEP 7 coding style:
| if (cm == NULL) | |
| return NULL; | |
| if (cm == NULL) { | |
| return NULL; | |
| } |
Same remark in sm_new().
| sm.__init__(None) | ||
| self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10) | ||
|
|
||
| def test_staticmethod_new_none_repr(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.
| def test_staticmethod_new_none_repr(self): | |
| def test_staticmethod_new(self): |
|
|
||
| def test_staticmethod_new_none_repr(self): | ||
| sm = staticmethod.__new__(staticmethod, None) | ||
| self.assertIsInstance(repr(sm), str) |
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.
| self.assertIsInstance(repr(sm), str) | |
| self.assertEqual(repr(sm), '<staticmethod(None)>') |
|
|
||
| def test_classmethod_new_none_repr(self): | ||
| cm = classmethod.__new__(classmethod, None) | ||
| self.assertIsInstance(repr(cm), str) |
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.
| self.assertIsInstance(repr(cm), str) | |
| self.assertEqual(repr(cm), '<classmethod(None)>') |
#144330