Skip to content

Commit 22b24c2

Browse files
authored
Tin/import cattrs (#203)
* Import cattrs first pass * More import cattrs * Update test_preconf * Update docs * Remove prints * Fix check-wheel-contents
1 parent a0e56f4 commit 22b24c2

33 files changed

+139
-29
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ jobs:
6363
- name: "List result"
6464
run: "ls -l dist"
6565
- name: "Check wheel contents"
66-
run: "check-wheel-contents dist/*.whl"
66+
run: "check-wheel-contents --toplevel cattr,cattrs dist/*.whl"
6767
- name: "Check long_description"
6868
run: "python -m twine check dist/*"

HISTORY.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ History
33
=======
44
1.10.0 (UNRELEASED)
55
-------------------
6-
* Add PEP 563 (string annotations) for dataclasses.
6+
* Add PEP 563 (string annotations) support for dataclasses.
77
(`#195 <https://github.com/python-attrs/cattrs/issues/195>`_)
88
* Fix handling of dictionaries with string Enum keys for bson, orjson, and tomlkit.
99
* Rename the ``cattr.gen.make_dict_unstructure_fn.omit_if_default`` parameter to ``_cattrs_omit_if_default``, for consistency. The ``omit_if_default`` parameters to ``GenConverter`` and ``override`` are unchanged.
10+
* Following the changes in ``attrs`` 21.3.0, add a ``cattrs`` package mirroring the existing ``cattr`` package. Both package names may be used as desired, and the ``cattr`` package isn't going away.
1011

1112
1.9.0 (2021-12-06)
1213
------------------

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ repository = "https://github.com/python-attrs/cattrs"
1717
documentation = "https://cattrs.readthedocs.io/en/latest/"
1818
keywords = ["attrs", "serialization", "dataclasses"]
1919
packages = [
20-
{ include = "cattr", from = "src" }
20+
{ include = "cattr", from = "src" },
21+
{ include = "cattrs", from = "src" },
2122
]
2223
readme = "README.rst"
2324

File renamed without changes.

src/cattr/converters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def _unstructure_union(self, obj):
360360
def _structure_error(self, _, cl):
361361
"""At the bottom of the condition stack, we explode if we can't handle it."""
362362
msg = (
363-
"Unsupported type: {0}. Register a structure hook for "
363+
"Unsupported type: {0!r}. Register a structure hook for "
364364
"it.".format(cl)
365365
)
366366
raise StructureHandlerNotFoundError(msg, type_=cl)

src/cattr/gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
is_bare,
2626
is_generic,
2727
)
28-
from .generics import deep_copy_with
28+
from ._generics import deep_copy_with
2929

3030
if TYPE_CHECKING: # pragma: no cover
3131
from cattr.converters import Converter

src/cattrs/__init__.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from cattr import (
2+
Converter,
3+
GenConverter,
4+
UnstructureStrategy,
5+
converters,
6+
disambiguators,
7+
dispatch,
8+
errors,
9+
gen,
10+
global_converter,
11+
override,
12+
preconf,
13+
register_structure_hook,
14+
register_structure_hook_func,
15+
register_unstructure_hook,
16+
register_unstructure_hook_func,
17+
structure,
18+
structure_attrs_fromdict,
19+
structure_attrs_fromtuple,
20+
unstructure,
21+
)
22+
23+
__all__ = (
24+
"Converter",
25+
"converters",
26+
"disambiguators",
27+
"dispatch",
28+
"errors",
29+
"gen",
30+
"GenConverter",
31+
"global_converter",
32+
"override",
33+
"preconf",
34+
"register_structure_hook_func",
35+
"register_structure_hook",
36+
"register_unstructure_hook_func",
37+
"register_unstructure_hook",
38+
"structure_attrs_fromdict",
39+
"structure_attrs_fromtuple",
40+
"structure",
41+
"unstructure",
42+
"UnstructureStrategy",
43+
)

src/cattrs/converters.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from cattr.converters import Converter, GenConverter, UnstructureStrategy
2+
3+
__all__ = ["Converter", "GenConverter", "UnstructureStrategy"]

src/cattrs/disambiguators.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from cattr.disambiguators import create_uniq_field_dis_func
2+
3+
__all__ = ["create_uniq_field_dis_func"]

src/cattrs/dispatch.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from cattr.dispatch import FunctionDispatch, MultiStrategyDispatch
2+
3+
__all__ = ["FunctionDispatch", "MultiStrategyDispatch"]

src/cattrs/errors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from cattr.errors import StructureHandlerNotFoundError
2+
3+
__all__ = ["StructureHandlerNotFoundError"]

src/cattrs/gen.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from cattr.gen import (
2+
AttributeOverride,
3+
make_dict_structure_fn,
4+
make_dict_unstructure_fn,
5+
make_hetero_tuple_unstructure_fn,
6+
make_iterable_unstructure_fn,
7+
make_mapping_structure_fn,
8+
make_mapping_unstructure_fn,
9+
override,
10+
)
11+
12+
__all__ = [
13+
"AttributeOverride",
14+
"make_dict_structure_fn",
15+
"make_dict_unstructure_fn",
16+
"make_hetero_tuple_unstructure_fn",
17+
"make_iterable_unstructure_fn",
18+
"make_mapping_structure_fn",
19+
"make_mapping_unstructure_fn",
20+
"override",
21+
]

src/cattrs/preconf/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from cattr.preconf import validate_datetime
2+
3+
__all__ = ["validate_datetime"]

src/cattrs/preconf/bson.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Preconfigured converters for bson."""
2+
from cattr.preconf.bson import configure_converter, make_converter
3+
4+
__all__ = ["make_converter", "configure_converter"]

src/cattrs/preconf/json.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Preconfigured converters for the stdlib json."""
2+
from cattr.preconf.json import configure_converter, make_converter
3+
4+
__all__ = ["make_converter", "configure_converter"]

src/cattrs/preconf/msgpack.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Preconfigured converters for msgpack."""
2+
from cattr.preconf.msgpack import configure_converter, make_converter
3+
4+
__all__ = ["make_converter", "configure_converter"]

src/cattrs/preconf/orjson.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Preconfigured converters for orjson."""
2+
from cattr.preconf.orjson import configure_converter, make_converter
3+
4+
__all__ = ["make_converter", "configure_converter"]

src/cattrs/preconf/pyyaml.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Preconfigured converters for pyyaml."""
2+
from cattr.preconf.pyyaml import configure_converter, make_converter
3+
4+
__all__ = ["make_converter", "configure_converter"]

src/cattrs/preconf/tomlkit.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Preconfigured converters for tomlkit."""
2+
from cattr.preconf.tomlkit import configure_converter, make_converter
3+
4+
__all__ = ["make_converter", "configure_converter"]

src/cattrs/preconf/ujson.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Preconfigured converters for ujson."""
2+
from cattr.preconf.ujson import configure_converter, make_converter
3+
4+
__all__ = ["make_converter", "configure_converter"]

src/cattrs/py.typed

Whitespace-only changes.

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from hypothesis import HealthCheck, settings
33

4-
from cattr import Converter
4+
from cattrs import Converter
55

66

77
@pytest.fixture()

tests/test_converter_inheritance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import attr
44
import pytest
55

6-
from cattr import Converter, GenConverter
6+
from cattrs import Converter, GenConverter
77

88

99
@pytest.mark.parametrize("converter_cls", [GenConverter, Converter])

tests/test_dataclasses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import attr
55
import pytest
66

7-
from cattr import Converter, GenConverter
7+
from cattrs import Converter, GenConverter
88

99

1010
@dataclasses.dataclass

tests/test_disambigutors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from attr import NOTHING
77
from hypothesis import HealthCheck, assume, given, settings
88

9-
from cattr.disambiguators import create_uniq_field_dis_func
9+
from cattrs.disambiguators import create_uniq_field_dis_func
1010

1111
from . import simple_classes
1212

tests/test_factory_hooks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import pytest
33
from attr import define, fields, has
44

5-
from cattr import Converter, GenConverter
6-
from cattr.gen import (
5+
from cattrs import Converter, GenConverter
6+
from cattrs.gen import (
77
make_dict_structure_fn,
88
make_dict_unstructure_fn,
99
override,

tests/test_function_dispatch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

3-
from cattr.dispatch import FunctionDispatch, StructureHandlerNotFoundError
3+
from cattrs.dispatch import FunctionDispatch
4+
from cattrs.errors import StructureHandlerNotFoundError
45

56

67
def test_function_dispatch():

tests/test_gen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from attr import define
66

7-
from cattr import GenConverter
8-
from cattr.gen import make_dict_structure_fn, make_dict_unstructure_fn
7+
from cattrs import GenConverter
8+
from cattrs.gen import make_dict_structure_fn, make_dict_unstructure_fn
99

1010

1111
def test_structure_linecache():

tests/test_gen_dict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from hypothesis import assume, given
66
from hypothesis.strategies._internal.core import data, sampled_from
77

8-
from cattr import Converter
98
from cattr._compat import adapted_fields, fields
10-
from cattr.gen import (
9+
from cattrs import Converter
10+
from cattrs.gen import (
1111
make_dict_structure_fn,
1212
make_dict_unstructure_fn,
1313
override,

tests/test_gen_dict_563.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
from attr import define
77

8-
from cattr import GenConverter
9-
from cattr.gen import make_dict_structure_fn, make_dict_unstructure_fn
8+
from cattrs import GenConverter
9+
from cattrs.gen import make_dict_structure_fn, make_dict_unstructure_fn
1010

1111

1212
# These need to be at the top level for `attr.resolve_types` to work.

tests/test_generics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import pytest
44
from attr import asdict, attrs, define
55

6-
from cattr import Converter, GenConverter
76
from cattr._compat import Protocol, is_py39_plus
8-
from cattr.errors import StructureHandlerNotFoundError
9-
from cattr.generics import deep_copy_with
7+
from cattr._generics import deep_copy_with
8+
from cattrs import Converter, GenConverter
9+
from cattrs.errors import StructureHandlerNotFoundError
1010

1111
from ._compat import Dict_origin, List_origin
1212

tests/test_multistrategy_dispatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from cattr.dispatch import MultiStrategyDispatch
1+
from cattrs.dispatch import MultiStrategyDispatch
22

33

44
class Foo(object):

tests/test_preconf.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
Set,
3434
TupleSubscriptable,
3535
)
36-
from cattr.preconf.bson import make_converter as bson_make_converter
37-
from cattr.preconf.json import make_converter as json_make_converter
38-
from cattr.preconf.msgpack import make_converter as msgpack_make_converter
39-
from cattr.preconf.orjson import make_converter as orjson_make_converter
40-
from cattr.preconf.pyyaml import make_converter as pyyaml_make_converter
41-
from cattr.preconf.tomlkit import make_converter as tomlkit_make_converter
42-
from cattr.preconf.ujson import make_converter as ujson_make_converter
36+
from cattrs.preconf.bson import make_converter as bson_make_converter
37+
from cattrs.preconf.json import make_converter as json_make_converter
38+
from cattrs.preconf.msgpack import make_converter as msgpack_make_converter
39+
from cattrs.preconf.orjson import make_converter as orjson_make_converter
40+
from cattrs.preconf.pyyaml import make_converter as pyyaml_make_converter
41+
from cattrs.preconf.tomlkit import make_converter as tomlkit_make_converter
42+
from cattrs.preconf.ujson import make_converter as ujson_make_converter
4343

4444

4545
@define

0 commit comments

Comments
 (0)