Skip to content

Pickling enum types with cloudpickle #244

@pcmoritz

Description

@pcmoritz

Dear all,

cloudpickle currently doesn't support pickling types of type enum.EnumMeta. Here is an example to reproduce (on the latest release cloudpickle 0.7):

import cloudpickle
from enum import IntEnum

class Color(IntEnum):
    RED = 1

u = cloudpickle.dumps(Color)
cloudpickle.loads(u)

gives the error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-ff791d51315b> in <module>
      6 
      7 u = cloudpickle.dumps(Color)
----> 8 cloudpickle.loads(u)

~/anaconda3/lib/python3.7/enum.py in __new__(metacls, cls, bases, classdict)
    149         # save enum items into separate mapping so they don't get baked into
    150         # the new class
--> 151         enum_members = {k: classdict[k] for k in classdict._member_names}
    152         for name in classdict._member_names:
    153             del classdict[name]

AttributeError: 'dict' object has no attribute '_member_names'

Any help with this is appreciated!

-- Philipp.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions