Relax _ConverterType to work with chained converters
I guess we could add a separate type for chained converters but I don't think that's worth it.
This commit is contained in:
parent
5885c4a412
commit
a74c32bcde
|
@ -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.
|
||||
|
|
|
@ -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] = ...,
|
||||
|
|
|
@ -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: ...
|
||||
|
|
Loading…
Reference in New Issue