-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
gh-95196: Fixed instances of types.ClassMethodDescriptorType not being pickled correctly #96162
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
gh-95196: Fixed instances of types.ClassMethodDescriptorType not being pickled correctly #96162
Conversation
correctly Previously, instances of types.ClassMethodDescriptorType were reduced into a wrong set of instructions. Instead of instructions to retreive the descriptor itself (using direct access to the owner's __dict__), the instructions retrieved the underlying classmethod (using getattr). This change has replaced the implementation of __reduce__ for these instances so it will directly access the owner's __dict__. Since there is no publicly available builtin function (That I could find) to get an attribute directly from the object's __dict__, and in order for the implmentation to work with older versions of python, I unfortunately could not avoid the usage of the "eval" builtin in the implementation.
Sorry for missing this. I'll try to review before the end of the week. |
Thank you :D |
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.
@serhiy-storchaka can you please help verify if this is the correct way to solve this problem?
…unction for instances of types.ClassMethodDescriptorType in order to use it
Using In any case, I think that it is better to just disable pickling of types.ClassMethodDescriptorType, for compatibility with Python implemented classmethod descriptors and with C and Python implemented staticmethod descriptors, and because there are no use common cases for this (otherwise we would get such report years ago). |
NOTE: I want to apologize for anything that is not up to par in this PR. This is my first time writing to cpython (and writing in python's C-API in general), I would love to learn from any mistakes done here and improve for the next time. I tried my best to look at other examples and guides and derive the correct conventions and workflow from there.
Previously, instances of types.ClassMethodDescriptorType were reduced
into a wrong set of instructions. Instead of the instructions retrieving
the descriptor itself (using direct access to the object's
__dict__
),the instructions retrieved the underlying classmethod (using the normal
getattr
)which resulted in different object upon unpickling.
This change has replaced the implementation of
__reduce__
for suchinstances so it will directly access the owner's
__dict__
.Since there is no publicly available builtin function (That I could
find) to get an attribute directly from the object's
__dict__
, and inorder for the implmentation to work with older versions of python, I
unfortunately could not avoid the usage of the "eval" builtin in the
implementation.