Skip to content

Commit

Permalink
Tin/import cattrs (#203)
Browse files Browse the repository at this point in the history
* Import cattrs first pass

* More import cattrs

* Update test_preconf

* Update docs

* Remove prints

* Fix check-wheel-contents
  • Loading branch information
Tinche authored Dec 27, 2021
1 parent a0e56f4 commit 22b24c2
Show file tree
Hide file tree
Showing 33 changed files with 139 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ jobs:
- name: "List result"
run: "ls -l dist"
- name: "Check wheel contents"
run: "check-wheel-contents dist/*.whl"
run: "check-wheel-contents --toplevel cattr,cattrs dist/*.whl"
- name: "Check long_description"
run: "python -m twine check dist/*"
3 changes: 2 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ History
=======
1.10.0 (UNRELEASED)
-------------------
* Add PEP 563 (string annotations) for dataclasses.
* Add PEP 563 (string annotations) support for dataclasses.
(`#195 <https://github.com/python-attrs/cattrs/issues/195>`_)
* Fix handling of dictionaries with string Enum keys for bson, orjson, and tomlkit.
* 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.
* 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.

1.9.0 (2021-12-06)
------------------
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ repository = "https://github.com/python-attrs/cattrs"
documentation = "https://cattrs.readthedocs.io/en/latest/"
keywords = ["attrs", "serialization", "dataclasses"]
packages = [
{ include = "cattr", from = "src" }
{ include = "cattr", from = "src" },
{ include = "cattrs", from = "src" },
]
readme = "README.rst"

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/cattr/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def _unstructure_union(self, obj):
def _structure_error(self, _, cl):
"""At the bottom of the condition stack, we explode if we can't handle it."""
msg = (
"Unsupported type: {0}. Register a structure hook for "
"Unsupported type: {0!r}. Register a structure hook for "
"it.".format(cl)
)
raise StructureHandlerNotFoundError(msg, type_=cl)
Expand Down
2 changes: 1 addition & 1 deletion src/cattr/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
is_bare,
is_generic,
)
from .generics import deep_copy_with
from ._generics import deep_copy_with

if TYPE_CHECKING: # pragma: no cover
from cattr.converters import Converter
Expand Down
43 changes: 43 additions & 0 deletions src/cattrs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from cattr import (
Converter,
GenConverter,
UnstructureStrategy,
converters,
disambiguators,
dispatch,
errors,
gen,
global_converter,
override,
preconf,
register_structure_hook,
register_structure_hook_func,
register_unstructure_hook,
register_unstructure_hook_func,
structure,
structure_attrs_fromdict,
structure_attrs_fromtuple,
unstructure,
)

__all__ = (
"Converter",
"converters",
"disambiguators",
"dispatch",
"errors",
"gen",
"GenConverter",
"global_converter",
"override",
"preconf",
"register_structure_hook_func",
"register_structure_hook",
"register_unstructure_hook_func",
"register_unstructure_hook",
"structure_attrs_fromdict",
"structure_attrs_fromtuple",
"structure",
"unstructure",
"UnstructureStrategy",
)
3 changes: 3 additions & 0 deletions src/cattrs/converters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from cattr.converters import Converter, GenConverter, UnstructureStrategy

__all__ = ["Converter", "GenConverter", "UnstructureStrategy"]
3 changes: 3 additions & 0 deletions src/cattrs/disambiguators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from cattr.disambiguators import create_uniq_field_dis_func

__all__ = ["create_uniq_field_dis_func"]
3 changes: 3 additions & 0 deletions src/cattrs/dispatch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from cattr.dispatch import FunctionDispatch, MultiStrategyDispatch

__all__ = ["FunctionDispatch", "MultiStrategyDispatch"]
3 changes: 3 additions & 0 deletions src/cattrs/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from cattr.errors import StructureHandlerNotFoundError

__all__ = ["StructureHandlerNotFoundError"]
21 changes: 21 additions & 0 deletions src/cattrs/gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from cattr.gen import (
AttributeOverride,
make_dict_structure_fn,
make_dict_unstructure_fn,
make_hetero_tuple_unstructure_fn,
make_iterable_unstructure_fn,
make_mapping_structure_fn,
make_mapping_unstructure_fn,
override,
)

__all__ = [
"AttributeOverride",
"make_dict_structure_fn",
"make_dict_unstructure_fn",
"make_hetero_tuple_unstructure_fn",
"make_iterable_unstructure_fn",
"make_mapping_structure_fn",
"make_mapping_unstructure_fn",
"override",
]
3 changes: 3 additions & 0 deletions src/cattrs/preconf/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from cattr.preconf import validate_datetime

__all__ = ["validate_datetime"]
4 changes: 4 additions & 0 deletions src/cattrs/preconf/bson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Preconfigured converters for bson."""
from cattr.preconf.bson import configure_converter, make_converter

__all__ = ["make_converter", "configure_converter"]
4 changes: 4 additions & 0 deletions src/cattrs/preconf/json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Preconfigured converters for the stdlib json."""
from cattr.preconf.json import configure_converter, make_converter

__all__ = ["make_converter", "configure_converter"]
4 changes: 4 additions & 0 deletions src/cattrs/preconf/msgpack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Preconfigured converters for msgpack."""
from cattr.preconf.msgpack import configure_converter, make_converter

__all__ = ["make_converter", "configure_converter"]
4 changes: 4 additions & 0 deletions src/cattrs/preconf/orjson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Preconfigured converters for orjson."""
from cattr.preconf.orjson import configure_converter, make_converter

__all__ = ["make_converter", "configure_converter"]
4 changes: 4 additions & 0 deletions src/cattrs/preconf/pyyaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Preconfigured converters for pyyaml."""
from cattr.preconf.pyyaml import configure_converter, make_converter

__all__ = ["make_converter", "configure_converter"]
4 changes: 4 additions & 0 deletions src/cattrs/preconf/tomlkit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Preconfigured converters for tomlkit."""
from cattr.preconf.tomlkit import configure_converter, make_converter

__all__ = ["make_converter", "configure_converter"]
4 changes: 4 additions & 0 deletions src/cattrs/preconf/ujson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Preconfigured converters for ujson."""
from cattr.preconf.ujson import configure_converter, make_converter

__all__ = ["make_converter", "configure_converter"]
Empty file added src/cattrs/py.typed
Empty file.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from hypothesis import HealthCheck, settings

from cattr import Converter
from cattrs import Converter


@pytest.fixture()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_converter_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import attr
import pytest

from cattr import Converter, GenConverter
from cattrs import Converter, GenConverter


@pytest.mark.parametrize("converter_cls", [GenConverter, Converter])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import attr
import pytest

from cattr import Converter, GenConverter
from cattrs import Converter, GenConverter


@dataclasses.dataclass
Expand Down
2 changes: 1 addition & 1 deletion tests/test_disambigutors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from attr import NOTHING
from hypothesis import HealthCheck, assume, given, settings

from cattr.disambiguators import create_uniq_field_dis_func
from cattrs.disambiguators import create_uniq_field_dis_func

from . import simple_classes

Expand Down
4 changes: 2 additions & 2 deletions tests/test_factory_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pytest
from attr import define, fields, has

from cattr import Converter, GenConverter
from cattr.gen import (
from cattrs import Converter, GenConverter
from cattrs.gen import (
make_dict_structure_fn,
make_dict_unstructure_fn,
override,
Expand Down
3 changes: 2 additions & 1 deletion tests/test_function_dispatch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from cattr.dispatch import FunctionDispatch, StructureHandlerNotFoundError
from cattrs.dispatch import FunctionDispatch
from cattrs.errors import StructureHandlerNotFoundError


def test_function_dispatch():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from attr import define

from cattr import GenConverter
from cattr.gen import make_dict_structure_fn, make_dict_unstructure_fn
from cattrs import GenConverter
from cattrs.gen import make_dict_structure_fn, make_dict_unstructure_fn


def test_structure_linecache():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_gen_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from hypothesis import assume, given
from hypothesis.strategies._internal.core import data, sampled_from

from cattr import Converter
from cattr._compat import adapted_fields, fields
from cattr.gen import (
from cattrs import Converter
from cattrs.gen import (
make_dict_structure_fn,
make_dict_unstructure_fn,
override,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_gen_dict_563.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from attr import define

from cattr import GenConverter
from cattr.gen import make_dict_structure_fn, make_dict_unstructure_fn
from cattrs import GenConverter
from cattrs.gen import make_dict_structure_fn, make_dict_unstructure_fn


# These need to be at the top level for `attr.resolve_types` to work.
Expand Down
6 changes: 3 additions & 3 deletions tests/test_generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import pytest
from attr import asdict, attrs, define

from cattr import Converter, GenConverter
from cattr._compat import Protocol, is_py39_plus
from cattr.errors import StructureHandlerNotFoundError
from cattr.generics import deep_copy_with
from cattr._generics import deep_copy_with
from cattrs import Converter, GenConverter
from cattrs.errors import StructureHandlerNotFoundError

from ._compat import Dict_origin, List_origin

Expand Down
2 changes: 1 addition & 1 deletion tests/test_multistrategy_dispatch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cattr.dispatch import MultiStrategyDispatch
from cattrs.dispatch import MultiStrategyDispatch


class Foo(object):
Expand Down
14 changes: 7 additions & 7 deletions tests/test_preconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
Set,
TupleSubscriptable,
)
from cattr.preconf.bson import make_converter as bson_make_converter
from cattr.preconf.json import make_converter as json_make_converter
from cattr.preconf.msgpack import make_converter as msgpack_make_converter
from cattr.preconf.orjson import make_converter as orjson_make_converter
from cattr.preconf.pyyaml import make_converter as pyyaml_make_converter
from cattr.preconf.tomlkit import make_converter as tomlkit_make_converter
from cattr.preconf.ujson import make_converter as ujson_make_converter
from cattrs.preconf.bson import make_converter as bson_make_converter
from cattrs.preconf.json import make_converter as json_make_converter
from cattrs.preconf.msgpack import make_converter as msgpack_make_converter
from cattrs.preconf.orjson import make_converter as orjson_make_converter
from cattrs.preconf.pyyaml import make_converter as pyyaml_make_converter
from cattrs.preconf.tomlkit import make_converter as tomlkit_make_converter
from cattrs.preconf.ujson import make_converter as ujson_make_converter


@define
Expand Down

0 comments on commit 22b24c2

Please sign in to comment.