Skip to content

The value of enums should be unstructured and structured too #699

@reversefold

Description

@reversefold

I'm running into an interesting issue where the value of an enum is a structured value which isn't being properly unstructured and that's causing issues with serialization.

Here's a simple example:

import attrs
import cattrs
import enum

class E(enum.Enum):
    A = 0
    B = 1

class EE(enum.Enum):
    A0 = (E.A, 0)
    A1 = (E.A, 1)
    B0 = (E.B, 0)
    B1 = (E.B, 1)

@attrs.define
class C:
    e: E
    ee: EE

c = C(e=E.B, ee=EE.A1)
print(cattrs.unstructure(c))

The e attribute of the C class is properly unstructured to a 1 value and the ee attribute is unstructured to the tuple (E.A, 1), but the E.A in that resulting tuple is not unstructured, which causes, for instance, JSON serialization to fail.

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