Skip to content

Remove internal apply_formatters_to_array #2737

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/2737.internal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove internal method ``apply_formatter_to_array`` and use the method with the same name from the ``eth-utils`` library.
11 changes: 0 additions & 11 deletions web3/_utils/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
Callable,
Dict,
Iterable,
Sequence,
Tuple,
TypeVar,
)
Expand All @@ -19,7 +18,6 @@
is_list_like,
is_string,
to_dict,
to_list,
)
from eth_utils.curried import (
apply_formatter_at_index,
Expand Down Expand Up @@ -56,15 +54,6 @@ def apply_formatters_to_args(
)


@curry
@to_list
def apply_formatter_to_array(
formatter: Callable[[TValue], TReturn], value: Sequence[TValue]
) -> Iterable[TReturn]:
for item in value:
yield formatter(item)


def map_collection(func: Callable[..., TReturn], collection: Any) -> Any:
"""
Apply func to each element of a collection, or value of a dictionary.
Expand Down
18 changes: 10 additions & 8 deletions web3/providers/eth_tester/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@
)

from web3._utils.formatters import (
apply_formatter_to_array,
apply_formatters_to_args,
apply_key_map,
hex_to_integer,
integer_to_hex,
is_array_of_dicts,
static_return,
)
from web3._utils.method_formatters import (
apply_list_to_array_formatter,
)
from web3.middleware import (
construct_formatting_middleware,
)
Expand Down Expand Up @@ -88,8 +90,8 @@ def is_hexstr(value: Any) -> bool:
"nonce": to_integer_if_hex,
"maxFeePerGas": to_integer_if_hex,
"maxPriorityFeePerGas": to_integer_if_hex,
"accessList": apply_formatter_to_array(
apply_key_map({"storageKeys": "storage_keys"})
"accessList": apply_list_to_array_formatter(
(apply_key_map({"storageKeys": "storage_keys"}))
),
}
transaction_request_formatter = apply_formatters_to_dict(TRANSACTION_REQUEST_FORMATTERS)
Expand Down Expand Up @@ -142,7 +144,7 @@ def is_hexstr(value: Any) -> bool:

TRANSACTION_RESULT_FORMATTERS = {
"to": apply_formatter_if(partial(operator.eq, ""), static_return(None)),
"access_list": apply_formatter_to_array(
"access_list": apply_list_to_array_formatter(
apply_key_map({"storage_keys": "storageKeys"}),
),
}
Expand Down Expand Up @@ -189,7 +191,7 @@ def is_hexstr(value: Any) -> bool:


RECEIPT_RESULT_FORMATTERS = {
"logs": apply_formatter_to_array(log_result_remapper),
"logs": apply_list_to_array_formatter(log_result_remapper),
}
receipt_result_formatter = apply_formatters_to_dict(RECEIPT_RESULT_FORMATTERS)

Expand Down Expand Up @@ -285,15 +287,15 @@ def is_hexstr(value: Any) -> bool:
RPCEndpoint("eth_newPendingTransactionFilter"): integer_to_hex,
RPCEndpoint("eth_getLogs"): apply_formatter_if(
is_array_of_dicts,
apply_formatter_to_array(log_result_remapper),
apply_list_to_array_formatter(log_result_remapper),
),
RPCEndpoint("eth_getFilterChanges"): apply_formatter_if(
is_array_of_dicts,
apply_formatter_to_array(log_result_remapper),
apply_list_to_array_formatter(log_result_remapper),
),
RPCEndpoint("eth_getFilterLogs"): apply_formatter_if(
is_array_of_dicts,
apply_formatter_to_array(log_result_remapper),
apply_list_to_array_formatter(log_result_remapper),
),
# EVM
RPCEndpoint("evm_snapshot"): integer_to_hex,
Expand Down