-
-
Notifications
You must be signed in to change notification settings - Fork 133
Closed
Description
- cattrs version: 22.2.0
- Python version: 3.9.16
- Operating System: macOS
Description
What I was trying to do:
from collections.abc import Set
from cattrs.preconf.json import make_converter as json_make_converter
json_converter = json_make_converter(unstruct_collection_overrides={Set: sorted})This didn't work because cattrs.preconf.json.make_converter overrides the kwargs:
cattrs/src/cattrs/preconf/json.py
Lines 40 to 44 in 5ccd616
| kwargs["unstruct_collection_overrides"] = { | |
| **kwargs.get("unstruct_collection_overrides", {}), | |
| AbstractSet: list, | |
| Counter: dict, | |
| } |
Then I tried:
from collections.abc import Set
from cattrs.preconf.json import make_converter as json_make_converter
json_converter = json_make_converter().copy(unstruct_collection_overrides={Set: sorted})But later in the code I call json_converter.dumps and mypy complained error: "Converter" has no attribute "dumps" [attr-defined] because copy returns a Converter.
What I Did
from collections.abc import Set
from cattrs.preconf.json import JsonConverter
from cattrs.preconf.json import configure_converter as json_configure_converter
json_converter = JsonConverter(unstruct_collection_overrides={Set: sorted})
json_configure_converter(json_converter)Maybe the two forms that I've tried above should also be allowed?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels