gh-144330: Initialize classmethod and staticmethod in new#144469
Open
vstinner wants to merge 2 commits intopython:mainfrom
Open
gh-144330: Initialize classmethod and staticmethod in new#144469vstinner wants to merge 2 commits intopython:mainfrom
vstinner wants to merge 2 commits intopython:mainfrom
Conversation
Move classmethod and staticmethod initialization from __init__() to __new__(). 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.
Member
Author
|
cc @colesbury |
Member
Author
|
With this change, |
Member
Author
|
I modified my PR to keep class abstractclassmethod(classmethod):
__isabstractmethod__ = True
def __init__(self, callable):
callable.__isabstractmethod__ = True
super().__init__(callable) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Move classmethod and staticmethod initialization from
__init__()to__new__().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