Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

corona10
Copy link
Member

@corona10 corona10 commented Sep 10, 2020

@corona10
Copy link
Member Author

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,
Copy link
Member Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a public marco :)

Copy link
Member Author

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);
Copy link
Member

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'.

cc @pitrou @serhiy-storchaka

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a 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?

@corona10
Copy link
Member Author

corona10 commented Sep 10, 2020

@serhiy-storchaka

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

@corona10
Copy link
Member Author

I created the issue https://bugs.python.org/issue41052 when I found the issue after porting to heap type.

@serhiy-storchaka
Copy link
Member

This is no longer needed, is not?

@corona10
Copy link
Member Author

@serhiy-storchaka Yeah this pr is no needed ;)

@corona10 corona10 closed this Nov 23, 2020
@corona10 corona10 deleted the bpo-41052-blake2 branch November 23, 2020 07:22
@vstinner
Copy link
Member

This is no longer needed, is not?

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants