Skip to content

Commit 8f9065c

Browse files
committed
Remove internal apply_formatter_to_array
- Remove web3.py ``apply_formatter_to_array`` and use the method with the same name from eth-utils
1 parent 56c8899 commit 8f9065c

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

newsfragments/2737.internal.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove internal method ``apply_formatter_to_array`` and use the method with the same name from the ``eth-utils`` library.

web3/_utils/formatters.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
Callable,
77
Dict,
88
Iterable,
9-
Sequence,
109
Tuple,
1110
TypeVar,
1211
)
@@ -19,7 +18,6 @@
1918
is_list_like,
2019
is_string,
2120
to_dict,
22-
to_list,
2321
)
2422
from eth_utils.curried import (
2523
apply_formatter_at_index,
@@ -56,15 +54,6 @@ def apply_formatters_to_args(
5654
)
5755

5856

59-
@curry
60-
@to_list
61-
def apply_formatter_to_array(
62-
formatter: Callable[[TValue], TReturn], value: Sequence[TValue]
63-
) -> Iterable[TReturn]:
64-
for item in value:
65-
yield formatter(item)
66-
67-
6857
def map_collection(func: Callable[..., TReturn], collection: Any) -> Any:
6958
"""
7059
Apply func to each element of a collection, or value of a dictionary.

web3/providers/eth_tester/middleware.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@
3030
)
3131

3232
from web3._utils.formatters import (
33-
apply_formatter_to_array,
3433
apply_formatters_to_args,
3534
apply_key_map,
3635
hex_to_integer,
3736
integer_to_hex,
3837
is_array_of_dicts,
3938
static_return,
4039
)
40+
from web3._utils.method_formatters import (
41+
apply_list_to_array_formatter,
42+
)
4143
from web3.middleware import (
4244
construct_formatting_middleware,
4345
)
@@ -88,8 +90,8 @@ def is_hexstr(value: Any) -> bool:
8890
"nonce": to_integer_if_hex,
8991
"maxFeePerGas": to_integer_if_hex,
9092
"maxPriorityFeePerGas": to_integer_if_hex,
91-
"accessList": apply_formatter_to_array(
92-
apply_key_map({"storageKeys": "storage_keys"})
93+
"accessList": apply_list_to_array_formatter(
94+
(apply_key_map({"storageKeys": "storage_keys"}))
9395
),
9496
}
9597
transaction_request_formatter = apply_formatters_to_dict(TRANSACTION_REQUEST_FORMATTERS)
@@ -142,7 +144,7 @@ def is_hexstr(value: Any) -> bool:
142144

143145
TRANSACTION_RESULT_FORMATTERS = {
144146
"to": apply_formatter_if(partial(operator.eq, ""), static_return(None)),
145-
"access_list": apply_formatter_to_array(
147+
"access_list": apply_list_to_array_formatter(
146148
apply_key_map({"storage_keys": "storageKeys"}),
147149
),
148150
}
@@ -189,7 +191,7 @@ def is_hexstr(value: Any) -> bool:
189191

190192

191193
RECEIPT_RESULT_FORMATTERS = {
192-
"logs": apply_formatter_to_array(log_result_remapper),
194+
"logs": apply_list_to_array_formatter(log_result_remapper),
193195
}
194196
receipt_result_formatter = apply_formatters_to_dict(RECEIPT_RESULT_FORMATTERS)
195197

@@ -285,15 +287,15 @@ def is_hexstr(value: Any) -> bool:
285287
RPCEndpoint("eth_newPendingTransactionFilter"): integer_to_hex,
286288
RPCEndpoint("eth_getLogs"): apply_formatter_if(
287289
is_array_of_dicts,
288-
apply_formatter_to_array(log_result_remapper),
290+
apply_list_to_array_formatter(log_result_remapper),
289291
),
290292
RPCEndpoint("eth_getFilterChanges"): apply_formatter_if(
291293
is_array_of_dicts,
292-
apply_formatter_to_array(log_result_remapper),
294+
apply_list_to_array_formatter(log_result_remapper),
293295
),
294296
RPCEndpoint("eth_getFilterLogs"): apply_formatter_if(
295297
is_array_of_dicts,
296-
apply_formatter_to_array(log_result_remapper),
298+
apply_list_to_array_formatter(log_result_remapper),
297299
),
298300
# EVM
299301
RPCEndpoint("evm_snapshot"): integer_to_hex,

0 commit comments

Comments
 (0)