diff --git a/changelog.d/618.change.rst b/changelog.d/618.change.rst index f497375d..cbea0888 100644 --- a/changelog.d/618.change.rst +++ b/changelog.d/618.change.rst @@ -1,2 +1,4 @@ Added ``attr.converters.chain()``. The feature allows combining multiple conversion callbacks into one. + +As part of this feature, we had to relax the type information for converter callables. diff --git a/src/attr/__init__.pyi b/src/attr/__init__.pyi index 394c07e4..6cbf48b0 100644 --- a/src/attr/__init__.pyi +++ b/src/attr/__init__.pyi @@ -38,7 +38,7 @@ _T = TypeVar("_T") _C = TypeVar("_C", bound=type) _ValidatorType = Callable[[Any, Attribute[_T], _T], Any] -_ConverterType = Callable[[Any], _T] +_ConverterType = Callable[[Any], Any] _FilterType = Callable[[Attribute[_T], _T], bool] _ReprType = Callable[[Any], str] _ReprArgType = Union[bool, _ReprType] @@ -76,7 +76,7 @@ class Attribute(Generic[_T]): order: bool hash: Optional[bool] init: bool - converter: Optional[_ConverterType[_T]] + converter: Optional[_ConverterType] metadata: Dict[Any, Any] type: Optional[Type[_T]] kw_only: bool @@ -136,7 +136,7 @@ def attrib( init: bool = ..., metadata: Optional[Mapping[Any, Any]] = ..., type: Optional[Type[_T]] = ..., - converter: Optional[_ConverterType[_T]] = ..., + converter: Optional[_ConverterType] = ..., factory: Optional[Callable[[], _T]] = ..., kw_only: bool = ..., eq: Optional[bool] = ..., @@ -155,7 +155,7 @@ def attrib( init: bool = ..., metadata: Optional[Mapping[Any, Any]] = ..., type: Optional[Type[_T]] = ..., - converter: Optional[_ConverterType[_T]] = ..., + converter: Optional[_ConverterType] = ..., factory: Optional[Callable[[], _T]] = ..., kw_only: bool = ..., eq: Optional[bool] = ..., @@ -174,7 +174,7 @@ def attrib( init: bool = ..., metadata: Optional[Mapping[Any, Any]] = ..., type: object = ..., - converter: Optional[_ConverterType[_T]] = ..., + converter: Optional[_ConverterType] = ..., factory: Optional[Callable[[], _T]] = ..., kw_only: bool = ..., eq: Optional[bool] = ..., diff --git a/src/attr/converters.pyi b/src/attr/converters.pyi index b9138765..2bf4cf74 100644 --- a/src/attr/converters.pyi +++ b/src/attr/converters.pyi @@ -3,11 +3,9 @@ from . import _ConverterType _T = TypeVar("_T") -def chain(*validators: _ConverterType[_T]) -> _ConverterType[_T]: ... -def optional( - converter: _ConverterType[_T], -) -> _ConverterType[Optional[_T]]: ... +def chain(*validators: _ConverterType) -> _ConverterType: ... +def optional(converter: _ConverterType) -> _ConverterType: ... @overload -def default_if_none(default: _T) -> _ConverterType[_T]: ... +def default_if_none(default: _T) -> _ConverterType: ... @overload -def default_if_none(*, factory: Callable[[], _T]) -> _ConverterType[_T]: ... +def default_if_none(*, factory: Callable[[], _T]) -> _ConverterType: ...