diff --git a/eth_utils/applicators.py b/eth_utils/applicators.py index 9bfd5939..69b20cac 100644 --- a/eth_utils/applicators.py +++ b/eth_utils/applicators.py @@ -5,6 +5,7 @@ Generator, List, Tuple, + TypeVar, Union, ) import warnings @@ -23,6 +24,9 @@ curry, ) +TArg = TypeVar("TArg") +TReturn = TypeVar("TReturn") + Formatters = Callable[[List[Any]], List[Any]] @@ -83,8 +87,8 @@ def apply_formatters_to_sequence( def apply_formatter_if( - condition: Callable[..., bool], formatter: Callable[..., Any], value: Any -) -> Any: + condition: Callable[[TArg], bool], formatter: Callable[[TArg], TReturn], value: TArg +) -> Union[TArg, TReturn]: if condition(value): return formatter(value) else: @@ -131,8 +135,8 @@ def apply_formatters_to_dict( @return_arg_type(1) def apply_formatter_to_array( - formatter: Callable[..., Any], value: List[Any] -) -> Generator[List[Any], None, None]: + formatter: Callable[[TArg], TReturn], value: List[TArg] +) -> Generator[TReturn, None, None]: for item in value: yield formatter(item)