Skip to content
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

Can't pickle sre_constants #92049

Closed
charmoniumQ opened this issue Apr 29, 2022 · 2 comments · Fixed by #92070
Closed

Can't pickle sre_constants #92049

charmoniumQ opened this issue Apr 29, 2022 · 2 comments · Fixed by #92070
Labels
topic-regex type-bug An unexpected behavior, bug, or error

Comments

@charmoniumQ
Copy link

charmoniumQ commented Apr 29, 2022

Bug report

In [30]: import pickle, sre_constants

In [31]: a = pickle.dumps(sre_constants.SUCCESS)

In [32]: pickle.loads(a)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-32-7038544c8e94> in <cell line: 1>()
----> 1 pickle.loads(a)

TypeError: __new__() missing 1 required positional argument: 'name'

Even if we decide sre_constants.* are not picklable, the TypeError should happen when trying to dump, not when trying to load. This could cause a user to write pickle files they can't ever read.

Your environment

  • CPython versions tested on: 3.9, 3.10
  • Operating system and architecture: Ubuntu 20.04 x86_64
@charmoniumQ charmoniumQ added the type-bug An unexpected behavior, bug, or error label Apr 29, 2022
@serhiy-storchaka
Copy link
Member

It is equally easy to fix pickling these constants, and to make them explicitly non-pickleable.

They were pickleable before 3.5, but it was broken so long ago, that it does not make sense to fix pickleability in 3.10 and 3.9. So I am going to make them explicitly non-pickleable in 3.10 and 3.9 and fix pickling in 3.11.

@serhiy-storchaka
Copy link
Member

On other hand, there is no reason of making them pickleable. It is an implementation detail, and they are defined in a private module.

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Apr 30, 2022
Previously, pickling did not fail, but the result could not be unpickled.
serhiy-storchaka added a commit that referenced this issue Apr 30, 2022
Previously, pickling did not fail, but the result could not be unpickled.
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Apr 30, 2022
…S etc (pythonGH-92070)

Previously, pickling did not fail, but the result could not be unpickled..
(cherry picked from commit 6d0d547)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue Apr 30, 2022
…H-92070) (GH-92073)

Previously, pickling did not fail, but the result could not be unpickled.
(cherry picked from commit 6d0d547)
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue May 1, 2022
…SUCCESS etc (pythonGH-92070) (pythonGH-92073)

Previously, pickling did not fail, but the result could not be unpickled.
(cherry picked from commit 6d0d547)
(cherry picked from commit e8ff3c9)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue May 1, 2022
…H-92070) (GH-92073) (GH-92102)

Previously, pickling did not fail, but the result could not be unpickled.
(cherry picked from commit 6d0d547)
(cherry picked from commit e8ff3c9)
hello-adam pushed a commit to hello-adam/cpython that referenced this issue Jun 2, 2022
… etc (pythonGH-92070) (pythonGH-92073) (pythonGH-92102)

Previously, pickling did not fail, but the result could not be unpickled.
(cherry picked from commit 6d0d547)
(cherry picked from commit e8ff3c9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-regex type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants