Skip to content

Commit 5815be3

Browse files
committed
fix(types): update type hints in web3._utils.method_formatters.py
1 parent 8a7bef1 commit 5815be3

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

web3/_utils/method_formatters.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
BlockIdentifier,
106106
Formatters,
107107
RPCEndpoint,
108+
RPCResponse,
108109
SimulateV1Payload,
109110
StateOverrideParams,
110111
TReturn,
@@ -650,19 +651,15 @@ def storage_key_to_hexstr(value: Union[bytes, int, str]) -> HexStr:
650651
)
651652

652653
block_result_formatters_copy = BLOCK_RESULT_FORMATTERS.copy()
653-
block_result_formatters_copy.update(
654-
{
655-
"calls": apply_list_to_array_formatter(
656-
type_aware_apply_formatters_to_dict(
657-
{
658-
"returnData": HexBytes,
659-
"logs": apply_list_to_array_formatter(log_entry_formatter),
660-
"gasUsed": to_integer_if_hex,
661-
"status": to_integer_if_hex,
662-
}
663-
)
664-
)
665-
}
654+
block_result_formatters_copy["calls"] = apply_list_to_array_formatter(
655+
type_aware_apply_formatters_to_dict(
656+
{
657+
"returnData": HexBytes,
658+
"logs": apply_list_to_array_formatter(log_entry_formatter),
659+
"gasUsed": to_integer_if_hex,
660+
"status": to_integer_if_hex,
661+
}
662+
)
666663
)
667664
simulate_v1_result_formatter = apply_formatter_if(
668665
is_not_null,
@@ -1107,9 +1104,7 @@ def combine_formatters(
11071104
yield formatter_map[method_name]
11081105

11091106

1110-
def get_request_formatters(
1111-
method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]],
1112-
) -> Dict[str, Callable[..., Any]]:
1107+
def get_request_formatters(method_name: RPCEndpoint) -> Callable[[RPCResponse], Any]:
11131108
request_formatter_maps = (
11141109
ABI_REQUEST_FORMATTERS,
11151110
# METHOD_NORMALIZERS needs to be after ABI_REQUEST_FORMATTERS
@@ -1241,7 +1236,7 @@ def filter_wrapper(
12411236

12421237
@to_tuple
12431238
def apply_module_to_formatters(
1244-
formatters: Tuple[Callable[..., TReturn]],
1239+
formatters: Iterable[Callable[..., TReturn]],
12451240
module: "Module",
12461241
method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]],
12471242
) -> Iterable[Callable[..., TReturn]]:
@@ -1250,9 +1245,9 @@ def apply_module_to_formatters(
12501245

12511246

12521247
def get_result_formatters(
1253-
method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]],
1248+
method_name: RPCEndpoint,
12541249
module: "Module",
1255-
) -> Dict[str, Callable[..., Any]]:
1250+
) -> Callable[[RPCResponse], Any]:
12561251
formatters = combine_formatters((PYTHONIC_RESULT_FORMATTERS,), method_name)
12571252
formatters_requiring_module = combine_formatters(
12581253
(FILTER_RESULT_FORMATTERS,), method_name
@@ -1263,9 +1258,7 @@ def get_result_formatters(
12631258
return compose(*partial_formatters, *formatters)
12641259

12651260

1266-
def get_error_formatters(
1267-
method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]],
1268-
) -> Callable[..., Any]:
1261+
def get_error_formatters(method_name: RPCEndpoint) -> Callable[[RPCResponse], Any]:
12691262
# Note error formatters work on the full response dict
12701263
error_formatter_maps = (ERROR_FORMATTERS,)
12711264
formatters = combine_formatters(error_formatter_maps, method_name)
@@ -1274,8 +1267,8 @@ def get_error_formatters(
12741267

12751268

12761269
def get_null_result_formatters(
1277-
method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]],
1278-
) -> Callable[..., Any]:
1270+
method_name: RPCEndpoint,
1271+
) -> Callable[[RPCResponse], Any]:
12791272
formatters = combine_formatters((NULL_RESULT_FORMATTERS,), method_name)
12801273

12811274
return compose(*formatters)

web3/method.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def __call__(self, *args: Any, **kwargs: Any) -> Any:
182182
@property
183183
def method_selector_fn(
184184
self,
185-
) -> Callable[..., Union[RPCEndpoint, Callable[..., RPCEndpoint]]]:
185+
) -> Callable[..., RPCEndpoint]:
186186
"""Gets the method selector from the config."""
187187
if callable(self.json_rpc_method):
188188
return self.json_rpc_method

0 commit comments

Comments
 (0)