From 543499d90a9c26d364c945a131bfbffb9f53a917 Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 20 May 2025 18:40:58 +0000 Subject: [PATCH] feat(mypy): better typing for applicator funcs --- eth_utils/applicators.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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)