-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-41052: Optout serialization/deserialization for blake2s/b #22189
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
Conversation
Before heap types, serialization/deserialization was failed. |
_blake2_blake2s___reduce___impl(BLAKE2sObject *self) | ||
/*[clinic end generated code: output=fb085f3da88f0c39 input=49898c2f1ef1ff74]*/ | ||
{ | ||
PyErr_Format(PyExc_TypeError, |
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.
@vstinner This function is very redundant with this issue.
Do you have any ideas with better solution?
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.
Maybe a public marco :)
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 don't think that exposing it to the public is the proper way.
It's should be a kind of internal utility routine.
{ | ||
PyErr_Format(PyExc_TypeError, | ||
"cannot pickle %s object", | ||
Py_TYPE(self)->tp_name); |
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.
Rather than having to copy/paste such code in each type, would it be possible to have a protocol like:
class NotHashable:
__hash__ = None
obj = NotHashable()
hash(obj)
This code raises TypeError: unhashable type: 'NotHashable'
.
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.
By default most extension types are not serializable. blake2b
is not serializable. Why is it needed to add explicit __reduce__
method?
master (after #21856)Python 3.10.0a0 (heads/master:f76d894dc5, Sep 10 2020, 23:26:39)
[Clang 11.0.0 (clang-1100.0.33.12)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> import _blake2
>>> pickle.dumps(_blake2.blake2s(), 0)
b'ccopy_reg\n_reconstructor\np0\n(c_blake2\nblake2s\np1\nc__builtin__\nobject\np2\nNtp3\nRp4\n.'
>>> pickle.dumps(_blake2.blake2s(), 1)
b'ccopy_reg\n_reconstructor\nq\x00(c_blake2\nblake2s\nq\x01c__builtin__\nobject\nq\x02Ntq\x03Rq\x04.' before>>> import _blake2
>>> import pickle
>>> pickle.dumps(_blake2.blake2s(), 0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/copyreg.py", line 65, in _reduce_ex
raise TypeError("can't pickle %s objects" % base.__name__)
TypeError: can't pickle blake2s objects
>>> pickle.dumps(_blake2.blake2s(), 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/copyreg.py", line 65, in _reduce_ex
raise TypeError("can't pickle %s objects" % base.__name__)
TypeError: can't pickle blake2s objects |
I created the issue https://bugs.python.org/issue41052 when I found the issue after porting to heap type. |
This is no longer needed, is not? |
@serhiy-storchaka Yeah this pr is no needed ;) |
Cool. I like the fact that it's no longer needed thanks to the generic https://bugs.python.org/issue41052 fix :-D Thanks again for the generic fix! It's way better than such copy/paste fix on each type. |
https://bugs.python.org/issue41052