-
Notifications
You must be signed in to change notification settings - Fork 181
Open
Description
Hi!
cloudpickling for IntFlag Enum seems to be broken after python 3.11
cloudpickle version : 3.1.1
Test Code
import enum
import cloudpickle
import pickle
import sys
print(sys.version)
class EnumClass(enum.Enum):
RANK_0 = 11
RANK_1 = 37
RANK_2 = 389
class IntFlagClass(enum.IntFlag):
RANK_0 = 11
RANK_1 = 37
RANK_2 = 389
def test(pickler, value):
print(f"testing {pickler} for {value} ... ", end="")
pickled = pickler.dumps(value)
unpickled = pickler.loads(pickled)
assert(unpickled == value)
print(f" success.")
for mod in [pickle, cloudpickle]:
for val in [EnumClass.RANK_1, IntFlagClass.RANK_1]:
test(mod, val)
Results for python 3.8 to 3.10, which is fine
3.8.20 (default, Oct 3 2024, 10:22:23)
[Clang 14.0.6 ]
testing <module 'pickle' from '~/test/py3.8/lib/python3.8/pickle.py'> for EnumClass.RANK_1 ... success.
testing <module 'pickle' from '~/test/py3.8/lib/python3.8/pickle.py'> for 37 ... success.
testing <module 'cloudpickle' from '~/test/py3.8/lib/python3.8/site-packages/cloudpickle/__init__.py'> for EnumClass.RANK_1 ... success.
testing <module 'cloudpickle' from '~/test/py3.8/lib/python3.8/site-packages/cloudpickle/__init__.py'> for 37 ... success.
3.9.21 (main, Dec 11 2024, 10:21:40)
[Clang 14.0.6 ]
testing <module 'pickle' from '~/test/py3.9/lib/python3.9/pickle.py'> for EnumClass.RANK_1 ... success.
testing <module 'pickle' from '~/test/py3.9/lib/python3.9/pickle.py'> for 37 ... success.
testing <module 'cloudpickle' from '~/test/py3.9/lib/python3.9/site-packages/cloudpickle/__init__.py'> for EnumClass.RANK_1 ... success.
testing <module 'cloudpickle' from '~/test/py3.9/lib/python3.9/site-packages/cloudpickle/__init__.py'> for 37 ... success.
3.10.16 (main, Dec 11 2024, 10:22:29) [Clang 14.0.6 ]
testing <module 'pickle' from '~/test/py3.10/lib/python3.10/pickle.py'> for EnumClass.RANK_1 ... success.
testing <module 'pickle' from '~/test/py3.10/lib/python3.10/pickle.py'> for 37 ... success.
testing <module 'cloudpickle' from '~/test/py3.10/lib/python3.10/site-packages/cloudpickle/__init__.py'> for EnumClass.RANK_1 ... success.
testing <module 'cloudpickle' from '~/test/py3.10/lib/python3.10/site-packages/cloudpickle/__init__.py'> for 37 ... success.
We get same error for python 3.11 to 3.13
3.11.11 (main, Dec 11 2024, 10:25:04) [Clang 14.0.6 ]
testing <module 'pickle' from '~/test/py3.11/lib/python3.11/pickle.py'> for EnumClass.RANK_1 ... success.
testing <module 'pickle' from '~/test/py3.11/lib/python3.11/pickle.py'> for 37 ... success.
testing <module 'cloudpickle' from '~/test/py3.11/lib/python3.11/site-packages/cloudpickle/__init__.py'> for EnumClass.RANK_1 ... success.
testing <module 'cloudpickle' from '~/test/py3.11/lib/python3.11/site-packages/cloudpickle/__init__.py'> for 37 ... Traceback (most recent call last):
File "/Users/ekrem/Desktop/work/test/pickle_test.py", line 30, in <module>
test(mod, val)
File "/Users/ekrem/Desktop/work/test/pickle_test.py", line 23, in test
unpickled = pickler.loads(pickled)
^^^^^^^^^^^^^^^^^^^^^^
File "~/test/py3.11/lib/python3.11/site-packages/cloudpickle/cloudpickle.py", line 1177, in _class_setstate
setattr(obj, attrname, attr)
File "~/test/py3.11/lib/python3.11/enum.py", line 838, in __setattr__
raise AttributeError('cannot reassign member %r' % (name, ))
AttributeError: cannot reassign member 'RANK_0'
3.12.9 | packaged by Anaconda, Inc. | (main, Feb 6 2025, 12:55:12) [Clang 14.0.6 ]
testing <module 'pickle' from '~/test/py3.12/lib/python3.12/pickle.py'> for EnumClass.RANK_1 ... success.
testing <module 'pickle' from '~/test/py3.12/lib/python3.12/pickle.py'> for 37 ... success.
testing <module 'cloudpickle' from '~/test/py3.12/lib/python3.12/site-packages/cloudpickle/__init__.py'> for EnumClass.RANK_1 ... success.
testing <module 'cloudpickle' from '~/test/py3.12/lib/python3.12/site-packages/cloudpickle/__init__.py'> for 37 ... Traceback (most recent call last):
File "/Users/ekrem/Desktop/work/test/pickle_test.py", line 30, in <module>
test(mod, val)
File "/Users/ekrem/Desktop/work/test/pickle_test.py", line 23, in test
unpickled = pickler.loads(pickled)
^^^^^^^^^^^^^^^^^^^^^^
File "~/test/py3.12/lib/python3.12/site-packages/cloudpickle/cloudpickle.py", line 1177, in _class_setstate
setattr(obj, attrname, attr)
File "~/test/py3.12/lib/python3.12/enum.py", line 854, in __setattr__
raise AttributeError('cannot reassign member %r' % (name, ))
AttributeError: cannot reassign member 'RANK_0'
3.13.2 | packaged by Anaconda, Inc. | (main, Feb 6 2025, 12:55:35) [Clang 14.0.6 ]
testing <module 'pickle' from '~/test/py3.13/lib/python3.13/pickle.py'> for EnumClass.RANK_1 ... success.
testing <module 'pickle' from '~/test/py3.13/lib/python3.13/pickle.py'> for 37 ... success.
testing <module 'cloudpickle' from '~/test/py3.13/lib/python3.13/site-packages/cloudpickle/__init__.py'> for EnumClass.RANK_1 ... success.
testing <module 'cloudpickle' from '~/test/py3.13/lib/python3.13/site-packages/cloudpickle/__init__.py'> for 37 ... Traceback (most recent call last):
File "/Users/ekrem/Desktop/work/test/pickle_test.py", line 30, in <module>
test(mod, val)
~~~~^^^^^^^^^^
File "/Users/ekrem/Desktop/work/test/pickle_test.py", line 23, in test
unpickled = pickler.loads(pickled)
File "~/test/py3.13/lib/python3.13/site-packages/cloudpickle/cloudpickle.py", line 1177, in _class_setstate
setattr(obj, attrname, attr)
~~~~~~~^^^^^^^^^^^^^^^^^^^^^
File "~/test/py3.13/lib/python3.13/enum.py", line 835, in __setattr__
raise AttributeError('cannot reassign member %r' % (name, ))
AttributeError: cannot reassign member 'RANK_0'
Metadata
Metadata
Assignees
Labels
No labels