[New-bugs-announce] [issue44342] enum with inherited type won't pickle

Tom Brown report at bugs.python.org
Mon Jun 7 20:56:53 EDT 2021


New submission from Tom Brown <thecapcom at gmail.com>:

The following script runs without error in 3.8.5 and raises an error in 3.8.6, 3.9.5 and 3.10.0b1. 

Source:
```
import enum, pickle

class MyInt(int):
    pass
    # work-around: __reduce_ex__ = int.__reduce_ex__

class MyEnum(MyInt, enum.Enum):
    A = 1

pickle.dumps(MyEnum.A)
```

Error (same in 3.8.6, 3.9.5 and 3.10.0b1):
```
Traceback (most recent call last):
  File "/home/thecap/projects/covid-data-model/./enum-pickle.py", line 12, in <module>
    pickle.dumps(MyEnum.A)
  File "/home/thecap/.pyenv/versions/3.10.0b1/lib/python3.10/enum.py", line 83, in _break_on_call_reduce
    raise TypeError('%r cannot be pickled' % self)
TypeError: MyEnum.A cannot be pickled
```

Like https://bugs.python.org/issue41889 this seems to be related to the fix for https://bugs.python.org/issue39587 which changes member_type from int to MyInt. A work-around is in the comment above.

----------
components: Library (Lib)
messages: 395300
nosy: Tom.Brown
priority: normal
severity: normal
status: open
title: enum with inherited type won't pickle
versions: Python 3.10, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44342>
_______________________________________


More information about the New-bugs-announce mailing list