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
{{ message }}
Repository navigation
An enum used as another enum's value is not unstructured by the json converter #679
import cattrs
import enum
import cattr.preconf.json
c = cattr.preconf.json.make_converter()
class TE(enum.Enum):
A = 1
class TE2(enum.Enum):
C = TE.A
print(repr(c.unstructure(TE2.C)))
Outputs:
<TE.A: 1>
Should output:
1
The actual use-case I have for this is an enum with a value that has a tuple with another enum's value and an additional integer value so it isn't quite this trivial. Nevertheless, the problem is the same. An enum's value may be one which needs to be recursively unstructured. In fact, the same issue arises if an attrs class instance is used as an enum's value:
import attrs
@attrs.define
class C:
a: int
class EC(enum.Enum):
D = C(1)
print(repr(c.unstructure(EC.D)))
The reverse issue also happens when trying to use structure on what the jsonable result should be:
Activity
fix: unstructure enum values through the converter recursively