You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
Activity
serhiy-storchaka commentedon Apr 30, 2022
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 commentedon Apr 30, 2022
On other hand, there is no reason of making them pickleable. It is an implementation detail, and they are defined in a private module.
pythongh-92049: Forbid pickling constants re._constants.SUCCESS etc
gh-92049: Forbid pickling constants re._constants.SUCCESS etc (GH-92070)
[3.10] pythongh-92049: Forbid pickling constants re._constants.SUCCES…
[3.10] gh-92049: Forbid pickling constants re._constants.SUCCESS etc (G…
[3.9] [3.10] pythongh-92049: Forbid pickling constants re._constants.…
[3.9] gh-92049: Forbid pickling constants re._constants.SUCCESS etc (G…
[3.9] pythongh-92049: Forbid pickling constants re._constants.SUCCESS…