Skip to content

Can't pickle sre_constants #92049

Closed

Description

@charmoniumQ

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

Activity

  1. serhiy-storchaka commented on Apr 30, 2022

    @serhiy-storchaka
    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.

  2. serhiy-storchaka commented on Apr 30, 2022

    @serhiy-storchaka
    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.

  3. added a commit that references this issue on Apr 30, 2022
  4. added 5 commits that reference this issue on Apr 30, 2022
  5. added a commit that references this issue on Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions