From cfe4f21a7340ae99d334a1d8caf437180fe2ecc2 Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 22 Apr 2025 16:56:11 +0000 Subject: [PATCH 1/7] fix(types): update type hints in web3._utils.method_formatters.py --- web3/_utils/method_formatters.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/web3/_utils/method_formatters.py b/web3/_utils/method_formatters.py index 71f27e1970..456e2bf3c0 100644 --- a/web3/_utils/method_formatters.py +++ b/web3/_utils/method_formatters.py @@ -101,6 +101,7 @@ BlockIdentifier, Formatters, RPCEndpoint, + RPCResponse, SimulateV1Payload, StateOverrideParams, TReturn, @@ -600,19 +601,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, @@ -1201,7 +1198,7 @@ def apply_module_to_formatters( def get_result_formatters( method_name: Union[RPCEndpoint, Callable[..., 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 @@ -1214,7 +1211,7 @@ def get_result_formatters( def get_error_formatters( method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]] -) -> Callable[..., Any]: +) -> 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) @@ -1224,7 +1221,7 @@ def get_error_formatters( def get_null_result_formatters( method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]] -) -> Callable[..., Any]: +) -> Callable[[RPCResponse], Any]: formatters = combine_formatters((NULL_RESULT_FORMATTERS,), method_name) return compose(*formatters) From d8f7ccfba5bd81920b770bb59b17dd9b4b8fe680 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 22 Apr 2025 16:56:11 +0000 Subject: [PATCH 2/7] fix: Tuple -> Iterable --- web3/_utils/method_formatters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web3/_utils/method_formatters.py b/web3/_utils/method_formatters.py index 456e2bf3c0..8e9a01a9ec 100644 --- a/web3/_utils/method_formatters.py +++ b/web3/_utils/method_formatters.py @@ -1187,7 +1187,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]]: From c88349342eacffafa830ec3e0b5a18c1ef7ca138 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 25 Apr 2025 16:39:57 -0400 Subject: [PATCH 3/7] fix(mypy): no union method_name --- web3/_utils/method_formatters.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/web3/_utils/method_formatters.py b/web3/_utils/method_formatters.py index 8e9a01a9ec..88fda43719 100644 --- a/web3/_utils/method_formatters.py +++ b/web3/_utils/method_formatters.py @@ -1053,9 +1053,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 @@ -1196,7 +1194,7 @@ def apply_module_to_formatters( def get_result_formatters( - method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]], + method_name: RPCEndpoint, module: "Module", ) -> Callable[[RPCResponse], Any]: formatters = combine_formatters((PYTHONIC_RESULT_FORMATTERS,), method_name) @@ -1209,9 +1207,7 @@ def get_result_formatters( return compose(*partial_formatters, *formatters) -def get_error_formatters( - method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]] -) -> Callable[[RPCResponse], 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) @@ -1219,9 +1215,7 @@ def get_error_formatters( return compose(*formatters) -def get_null_result_formatters( - method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]] -) -> Callable[[RPCResponse], Any]: +def get_null_result_formatters(method_name: RPCEndpoint) -> Callable[[RPCResponse], Any]: formatters = combine_formatters((NULL_RESULT_FORMATTERS,), method_name) return compose(*formatters) From 04773c97d0c7a307288e33ed7d095c462ae32445 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 25 Apr 2025 16:41:34 -0400 Subject: [PATCH 4/7] fix: unmatched ']' --- web3/_utils/method_formatters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web3/_utils/method_formatters.py b/web3/_utils/method_formatters.py index 88fda43719..de6157ede2 100644 --- a/web3/_utils/method_formatters.py +++ b/web3/_utils/method_formatters.py @@ -1053,7 +1053,7 @@ def combine_formatters( yield formatter_map[method_name] -def get_request_formatters(method_name: RPCEndpoint) -> Callable[[RPCResponse], 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 From 1a49df3a4320ecc741f89b91e1879b5fda8b111e Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 25 Apr 2025 16:46:56 -0400 Subject: [PATCH 5/7] Update method.py --- web3/method.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web3/method.py b/web3/method.py index f67828f964..a3977fff84 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 821a0f856bfcc1737bc8229f9e20717dc91071fc Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 25 Apr 2025 16:47:47 -0400 Subject: [PATCH 6/7] chore: lint --- web3/_utils/method_formatters.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web3/_utils/method_formatters.py b/web3/_utils/method_formatters.py index de6157ede2..11182f6565 100644 --- a/web3/_utils/method_formatters.py +++ b/web3/_utils/method_formatters.py @@ -1215,7 +1215,9 @@ def get_error_formatters(method_name: RPCEndpoint) -> Callable[[RPCResponse], An return compose(*formatters) -def get_null_result_formatters(method_name: RPCEndpoint) -> Callable[[RPCResponse], Any]: +def get_null_result_formatters( + method_name: RPCEndpoint +) -> Callable[[RPCResponse], Any]: formatters = combine_formatters((NULL_RESULT_FORMATTERS,), method_name) return compose(*formatters) From 5f999540b3efcd173d13724cf699b39909988fd6 Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Fri, 25 Apr 2025 21:25:42 +0000 Subject: [PATCH 7/7] chore: lint --- web3/_utils/method_formatters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web3/_utils/method_formatters.py b/web3/_utils/method_formatters.py index 11182f6565..401dcc54d3 100644 --- a/web3/_utils/method_formatters.py +++ b/web3/_utils/method_formatters.py @@ -1216,7 +1216,7 @@ def get_error_formatters(method_name: RPCEndpoint) -> Callable[[RPCResponse], An def get_null_result_formatters( - method_name: RPCEndpoint + method_name: RPCEndpoint, ) -> Callable[[RPCResponse], Any]: formatters = combine_formatters((NULL_RESULT_FORMATTERS,), method_name)