Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Our backwards-compatibility policy can be found [here](https://github.com/python
- The documentation has been significantly reworked.
([#473](https://github.com/python-attrs/cattrs/pull/473))
- The docs now use the Inter font.
- Make type annotations for `include_subclasses` and `tagged_union` strategies more lenient.
([#431](https://github.com/python-attrs/cattrs/pull/431))

## 23.2.3 (2023-11-30)

Expand Down
17 changes: 10 additions & 7 deletions src/cattrs/strategies/_subclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from __future__ import annotations

from gc import collect
from typing import Any, Callable, Union
from typing import Any, Callable, TypeVar, Union

from ..converters import BaseConverter, Converter
from ..converters import BaseConverter
from ..gen import AttributeOverride, make_dict_structure_fn, make_dict_unstructure_fn
from ..gen._consts import already_generating

Expand All @@ -28,11 +28,14 @@ def _get_union_type(cl: type, given_subclasses_tree: tuple[type]) -> type | None
return Union[class_tree] if len(class_tree) >= 2 else None


C = TypeVar("C", bound=BaseConverter)


def include_subclasses(
cl: type,
converter: Converter,
converter: C,
subclasses: tuple[type, ...] | None = None,
union_strategy: Callable[[Any, BaseConverter], Any] | None = None,
union_strategy: Callable[[Any, C], Any] | None = None,
overrides: dict[str, AttributeOverride] | None = None,
) -> None:
"""
Expand Down Expand Up @@ -79,7 +82,7 @@ def include_subclasses(

def _include_subclasses_without_union_strategy(
cl,
converter: Converter,
converter: BaseConverter,
parent_subclass_tree: tuple[type],
overrides: dict[str, AttributeOverride] | None,
):
Expand Down Expand Up @@ -153,9 +156,9 @@ def unstruct_hook(


def _include_subclasses_with_union_strategy(
converter: Converter,
converter: C,
union_classes: tuple[type, ...],
union_strategy: Callable[[Any, BaseConverter], Any],
union_strategy: Callable[[Any, C], Any],
overrides: dict[str, AttributeOverride] | None,
):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/cattrs/strategies/_unions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from attrs import NOTHING

from cattrs import BaseConverter, Converter
from cattrs import BaseConverter
from cattrs._compat import get_newtype_base, is_literal, is_subclass, is_union_type

__all__ = [
Expand All @@ -20,7 +20,7 @@ def default_tag_generator(typ: Type) -> str:

def configure_tagged_union(
union: Any,
converter: Converter,
converter: BaseConverter,
tag_generator: Callable[[Type], str] = default_tag_generator,
tag_name: str = "_type",
default: Optional[Type] = NOTHING,
Expand Down