Skip to content

Commit

Permalink
Fix preconf mapping optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinche committed Nov 12, 2024
1 parent 771d2ca commit 6762377
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/cattrs/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ def is_literal(_) -> bool:


Set = AbcSet
AbstractSet = AbcSet
MutableSet = AbcMutableSet
Sequence = AbcSequence
MutableSequence = AbcMutableSequence
Expand Down
5 changes: 2 additions & 3 deletions src/cattrs/preconf/cbor2.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Preconfigured converters for cbor2."""

from collections.abc import Set
from datetime import date, datetime, timezone
from typing import Any, TypeVar, Union

from cbor2 import dumps, loads

from cattrs._compat import AbstractSet

from ..converters import BaseConverter, Converter
from ..fns import identity
from ..literals import is_literal_containing_enums
Expand Down Expand Up @@ -48,7 +47,7 @@ def configure_converter(converter: BaseConverter):
@wrap(Cbor2Converter)
def make_converter(*args: Any, **kwargs: Any) -> Cbor2Converter:
kwargs["unstruct_collection_overrides"] = {
AbstractSet: list,
Set: list,
**kwargs.get("unstruct_collection_overrides", {}),
}
res = Cbor2Converter(*args, **kwargs)
Expand Down
5 changes: 3 additions & 2 deletions src/cattrs/preconf/json.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Preconfigured converters for the stdlib json."""

from base64 import b85decode, b85encode
from collections.abc import Set
from datetime import date, datetime
from json import dumps, loads
from typing import Any, TypeVar, Union

from .._compat import AbstractSet, Counter
from .._compat import Counter
from ..converters import BaseConverter, Converter
from ..fns import identity
from ..literals import is_literal_containing_enums
Expand Down Expand Up @@ -56,7 +57,7 @@ def configure_converter(converter: BaseConverter):
@wrap(JsonConverter)
def make_converter(*args: Any, **kwargs: Any) -> JsonConverter:
kwargs["unstruct_collection_overrides"] = {
AbstractSet: list,
Set: list,
Counter: dict,
**kwargs.get("unstruct_collection_overrides", {}),
}
Expand Down
5 changes: 2 additions & 3 deletions src/cattrs/preconf/msgpack.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Preconfigured converters for msgpack."""

from collections.abc import Set
from datetime import date, datetime, time, timezone
from typing import Any, TypeVar, Union

from msgpack import dumps, loads

from cattrs._compat import AbstractSet

from ..converters import BaseConverter, Converter
from ..fns import identity
from ..literals import is_literal_containing_enums
Expand Down Expand Up @@ -55,7 +54,7 @@ def configure_converter(converter: BaseConverter):
@wrap(MsgpackConverter)
def make_converter(*args: Any, **kwargs: Any) -> MsgpackConverter:
kwargs["unstruct_collection_overrides"] = {
AbstractSet: list,
Set: list,
**kwargs.get("unstruct_collection_overrides", {}),
}
res = MsgpackConverter(*args, **kwargs)
Expand Down
7 changes: 4 additions & 3 deletions src/cattrs/preconf/orjson.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""Preconfigured converters for orjson."""

from base64 import b85decode, b85encode
from collections.abc import Set
from datetime import date, datetime
from enum import Enum
from functools import partial
from typing import Any, TypeVar, Union

from orjson import dumps, loads

from .._compat import AbstractSet, is_mapping, is_subclass
from ..cols import is_namedtuple, namedtuple_unstructure_factory
from .._compat import is_subclass
from ..cols import is_mapping, is_namedtuple, namedtuple_unstructure_factory
from ..converters import BaseConverter, Converter
from ..fns import identity
from ..literals import is_literal_containing_enums
Expand Down Expand Up @@ -96,7 +97,7 @@ def key_handler(v):
@wrap(OrjsonConverter)
def make_converter(*args: Any, **kwargs: Any) -> OrjsonConverter:
kwargs["unstruct_collection_overrides"] = {
AbstractSet: list,
Set: list,
**kwargs.get("unstruct_collection_overrides", {}),
}
res = OrjsonConverter(*args, **kwargs)
Expand Down
5 changes: 3 additions & 2 deletions src/cattrs/preconf/tomlkit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Preconfigured converters for tomlkit."""

from base64 import b85decode, b85encode
from collections.abc import Set
from datetime import date, datetime
from enum import Enum
from operator import attrgetter
Expand All @@ -9,7 +10,7 @@
from tomlkit import dumps, loads
from tomlkit.items import Float, Integer, String

from .._compat import AbstractSet, is_mapping, is_subclass
from .._compat import is_mapping, is_subclass
from ..converters import BaseConverter, Converter
from ..strategies import configure_union_passthrough
from . import validate_datetime, wrap
Expand Down Expand Up @@ -76,7 +77,7 @@ def key_handler(k: bytes):
@wrap(TomlkitConverter)
def make_converter(*args: Any, **kwargs: Any) -> TomlkitConverter:
kwargs["unstruct_collection_overrides"] = {
AbstractSet: list,
Set: list,
tuple: list,
**kwargs.get("unstruct_collection_overrides", {}),
}
Expand Down
4 changes: 2 additions & 2 deletions src/cattrs/preconf/ujson.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Preconfigured converters for ujson."""

from base64 import b85decode, b85encode
from collections.abc import Set
from datetime import date, datetime
from typing import Any, AnyStr, TypeVar, Union

from ujson import dumps, loads

from .._compat import AbstractSet
from ..converters import BaseConverter, Converter
from ..fns import identity
from ..literals import is_literal_containing_enums
Expand Down Expand Up @@ -55,7 +55,7 @@ def configure_converter(converter: BaseConverter):
@wrap(UjsonConverter)
def make_converter(*args: Any, **kwargs: Any) -> UjsonConverter:
kwargs["unstruct_collection_overrides"] = {
AbstractSet: list,
Set: list,
**kwargs.get("unstruct_collection_overrides", {}),
}
res = UjsonConverter(*args, **kwargs)
Expand Down

0 comments on commit 6762377

Please sign in to comment.