From 5815be3e07890c94d0b15aeec3231c077096673e Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Fri, 16 May 2025 18:25:03 +0000 Subject: [PATCH 1/2] fix(types): update type hints in web3._utils.method_formatters.py --- web3/_utils/method_formatters.py | 41 +++++++++++++------------------- web3/method.py | 2 +- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/web3/_utils/method_formatters.py b/web3/_utils/method_formatters.py index 8cc3eab58e..d66852ed9d 100644 --- a/web3/_utils/method_formatters.py +++ b/web3/_utils/method_formatters.py @@ -105,6 +105,7 @@ BlockIdentifier, Formatters, RPCEndpoint, + RPCResponse, SimulateV1Payload, StateOverrideParams, TReturn, @@ -650,19 +651,15 @@ def storage_key_to_hexstr(value: Union[bytes, int, str]) -> HexStr: ) block_result_formatters_copy = BLOCK_RESULT_FORMATTERS.copy() -block_result_formatters_copy.update( - { - "calls": apply_list_to_array_formatter( - type_aware_apply_formatters_to_dict( - { - "returnData": HexBytes, - "logs": apply_list_to_array_formatter(log_entry_formatter), - "gasUsed": to_integer_if_hex, - "status": to_integer_if_hex, - } - ) - ) - } +block_result_formatters_copy["calls"] = apply_list_to_array_formatter( + type_aware_apply_formatters_to_dict( + { + "returnData": HexBytes, + "logs": apply_list_to_array_formatter(log_entry_formatter), + "gasUsed": to_integer_if_hex, + "status": to_integer_if_hex, + } + ) ) simulate_v1_result_formatter = apply_formatter_if( is_not_null, @@ -1107,9 +1104,7 @@ def combine_formatters( yield formatter_map[method_name] -def get_request_formatters( - method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]], -) -> Dict[str, Callable[..., Any]]: +def get_request_formatters(method_name: RPCEndpoint) -> Callable[[RPCResponse], Any]: request_formatter_maps = ( ABI_REQUEST_FORMATTERS, # METHOD_NORMALIZERS needs to be after ABI_REQUEST_FORMATTERS @@ -1241,7 +1236,7 @@ def filter_wrapper( @to_tuple def apply_module_to_formatters( - formatters: Tuple[Callable[..., TReturn]], + formatters: Iterable[Callable[..., TReturn]], module: "Module", method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]], ) -> Iterable[Callable[..., TReturn]]: @@ -1250,9 +1245,9 @@ def apply_module_to_formatters( def get_result_formatters( - method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]], + method_name: RPCEndpoint, module: "Module", -) -> Dict[str, Callable[..., Any]]: +) -> Callable[[RPCResponse], Any]: formatters = combine_formatters((PYTHONIC_RESULT_FORMATTERS,), method_name) formatters_requiring_module = combine_formatters( (FILTER_RESULT_FORMATTERS,), method_name @@ -1263,9 +1258,7 @@ def get_result_formatters( return compose(*partial_formatters, *formatters) -def get_error_formatters( - method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]], -) -> Callable[..., Any]: +def get_error_formatters(method_name: RPCEndpoint) -> Callable[[RPCResponse], Any]: # Note error formatters work on the full response dict error_formatter_maps = (ERROR_FORMATTERS,) formatters = combine_formatters(error_formatter_maps, method_name) @@ -1274,8 +1267,8 @@ def get_error_formatters( def get_null_result_formatters( - method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]], -) -> Callable[..., Any]: + method_name: RPCEndpoint, +) -> Callable[[RPCResponse], Any]: formatters = combine_formatters((NULL_RESULT_FORMATTERS,), method_name) return compose(*formatters) diff --git a/web3/method.py b/web3/method.py index c9ced51f17..8c7ae73b11 100644 --- a/web3/method.py +++ b/web3/method.py @@ -182,7 +182,7 @@ def __call__(self, *args: Any, **kwargs: Any) -> Any: @property def method_selector_fn( self, - ) -> Callable[..., Union[RPCEndpoint, Callable[..., RPCEndpoint]]]: + ) -> Callable[..., RPCEndpoint]: """Gets the method selector from the config.""" if callable(self.json_rpc_method): return self.json_rpc_method From 7bc16a6c52a24387ea31fec1c4b77b8b4ab6b84e Mon Sep 17 00:00:00 2001 From: kclowes Date: Fri, 16 May 2025 13:31:18 -0600 Subject: [PATCH 2/2] Add newsfragment --- newsfragments/3669.internal.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/3669.internal.rst diff --git a/newsfragments/3669.internal.rst b/newsfragments/3669.internal.rst new file mode 100644 index 0000000000..be1ac0329b --- /dev/null +++ b/newsfragments/3669.internal.rst @@ -0,0 +1 @@ +Update some types in ``web3._utils.method_formatters``