-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(types): update type hints in web3._utils.method_formatters.py #3669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
cfe4f21
d8f7ccf
c883493
04773c9
1a49df3
821a0f8
5f99954
1e81a1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -1190,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]]: | ||
|
@@ -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]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is method_name actually supposed to be a I notice There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, nice catch. Yeah, these can only be RPCEndpoints once they're here. |
||
) -> 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious about the reasoning behind this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change just indicates to mypy that the function will work with any iterable of callables.
The original hint indicates that the function must take a tuple input, so while it didn't cause any type errors internally here it can cause unneeded type errors for downstream users.