Skip to content

Commit f605aad

Browse files
committed
preconf: test bare dicts
1 parent dd7e821 commit f605aad

File tree

8 files changed

+14
-12
lines changed

8 files changed

+14
-12
lines changed

src/cattrs/preconf/bson.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def configure_converter(converter: BaseConverter):
6161
* a deserialization hook is registered for bson.ObjectId by default
6262
* string and int enums are passed through when unstructuring
6363
64-
.. versionchanged: 24.2.0
64+
.. versionchanged:: 24.2.0
6565
Enums are left to the library to unstructure, speeding them up.
6666
"""
6767

src/cattrs/preconf/json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def configure_converter(converter: BaseConverter):
3636
* union passthrough is configured for unions of strings, bools, ints,
3737
floats and None
3838
39-
.. versionchanged: 24.2.0
39+
.. versionchanged:: 24.2.0
4040
Enums are left to the library to unstructure, speeding them up.
4141
"""
4242
converter.register_unstructure_hook(

src/cattrs/preconf/msgpack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def configure_converter(converter: BaseConverter):
3131
* sets are serialized as lists
3232
* string and int enums are passed through when unstructuring
3333
34-
.. versionchanged: 24.2.0
34+
.. versionchanged:: 24.2.0
3535
Enums are left to the library to unstructure, speeding them up.
3636
"""
3737
converter.register_unstructure_hook(datetime, lambda v: v.timestamp())

src/cattrs/preconf/msgspec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def configure_converter(converter: Converter) -> None:
7575
* union passthrough configured for str, bool, int, float and None
7676
* bare, string and int enums are passed through when unstructuring
7777
78-
.. versionchanged: 24.2.0
78+
.. versionchanged:: 24.2.0
7979
Enums are left to the library to unstructure, speeding them up.
8080
"""
8181
configure_passthroughs(converter)

src/cattrs/preconf/orjson.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from .._compat import is_subclass
1313
from ..cols import is_mapping, is_namedtuple, namedtuple_unstructure_factory
14-
from ..converters import BaseConverter, Converter
14+
from ..converters import Converter
1515
from ..fns import identity
1616
from ..literals import is_literal_containing_enums
1717
from ..strategies import configure_union_passthrough
@@ -28,7 +28,7 @@ def loads(self, data: Union[bytes, bytearray, memoryview, str], cl: type[T]) ->
2828
return self.structure(loads(data), cl)
2929

3030

31-
def configure_converter(converter: BaseConverter):
31+
def configure_converter(converter: Converter):
3232
"""
3333
Configure the converter for use with the orjson library.
3434
@@ -40,9 +40,9 @@ def configure_converter(converter: BaseConverter):
4040
* mapping keys are coerced into strings when unstructuring
4141
* bare, string and int enums are passed through when unstructuring
4242
43-
.. versionchanged: 24.1.0
43+
.. versionchanged:: 24.1.0
4444
Add support for typed namedtuples.
45-
.. versionchanged: 24.2.0
45+
.. versionchanged:: 24.2.0
4646
Enums are left to the library to unstructure, speeding them up.
4747
"""
4848
converter.register_unstructure_hook(
@@ -53,7 +53,7 @@ def configure_converter(converter: BaseConverter):
5353
converter.register_structure_hook(datetime, lambda v, _: datetime.fromisoformat(v))
5454
converter.register_structure_hook(date, lambda v, _: date.fromisoformat(v))
5555

56-
def gen_unstructure_mapping(cl: Any, unstructure_to=None):
56+
def unstructure_mapping_factory(cl: Any, unstructure_to=None):
5757
key_handler = str
5858
args = getattr(cl, "__args__", None)
5959
if args:
@@ -77,7 +77,7 @@ def key_handler(v):
7777

7878
converter._unstructure_func.register_func_list(
7979
[
80-
(is_mapping, gen_unstructure_mapping, True),
80+
(is_mapping, unstructure_mapping_factory, True),
8181
(
8282
is_namedtuple,
8383
partial(namedtuple_unstructure_factory, unstructure_to=tuple),

src/cattrs/preconf/pyyaml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def configure_converter(converter: BaseConverter):
3838
* datetimes and dates are validated
3939
* typed namedtuples are serialized as lists
4040
41-
.. versionchanged: 24.1.0
41+
.. versionchanged:: 24.1.0
4242
Add support for typed namedtuples.
4343
"""
4444
converter.register_unstructure_hook(

src/cattrs/preconf/ujson.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def configure_converter(converter: BaseConverter):
3333
* sets are serialized as lists
3434
* string and int enums are passed through when unstructuring
3535
36-
.. versionchanged: 24.2.0
36+
.. versionchanged:: 24.2.0
3737
Enums are left to the library to unstructure, speeding them up.
3838
"""
3939
converter.register_unstructure_hook(

tests/test_preconf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class ABareEnum(Enum):
8888
an_int: int
8989
a_float: float
9090
a_dict: Dict[str, int]
91+
a_bare_dict: dict
9192
a_list: List[int]
9293
a_homogenous_tuple: TupleSubscriptable[int, ...]
9394
a_hetero_tuple: TupleSubscriptable[str, int, float]
@@ -160,6 +161,7 @@ def everythings(
160161
draw(ints),
161162
draw(fs),
162163
draw(dictionaries(key_text, ints)),
164+
draw(dictionaries(key_text, strings)),
163165
draw(lists(ints)),
164166
tuple(draw(lists(ints))),
165167
(draw(strings), draw(ints), draw(fs)),

0 commit comments

Comments
 (0)