An enum used as another enum's value is not unstructured by the json converter
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start by reproducing the examples through cattr.preconf.json.make_converter(), focusing on unstructure and structure for enums whose values are other enums or attrs instances. Done means nested enum values and attrs instances are recursively converted in both directions, including the tuple-valued case described in the issue.
Written by the indexing model from the issue text.
Description
Trivial example:
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:
c.structure({"a": 1}, EC)
c.structure(1, TE2)
Both fail.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 159
- Avg merge
- 12h 21m
- Merged PRs (30d)
- 6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-attrs/cattrs
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
python-attrs/cattrs#761 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
python-attrs/cattrs#513 · 4 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
python-attrs/cattrs#779 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 85/100
python-attrs/cattrs#774 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
python-attrs/cattrs#746 · 2 comments ·
All issues in python-attrs/cattrs
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100