From 56f94f436c4cb9c69fe6edb77d1f8b5aa20ed164 Mon Sep 17 00:00:00 2001 From: fselmo Date: Wed, 23 Nov 2022 12:10:27 -0700 Subject: [PATCH] Remove internal ``apply_formatter_to_array`` - Remove web3.py ``apply_formatter_to_array`` and use the method with the same name from eth-utils --- newsfragments/2737.internal.rst | 1 + web3/_utils/formatters.py | 11 ----------- web3/providers/eth_tester/middleware.py | 18 ++++++++++-------- 3 files changed, 11 insertions(+), 19 deletions(-) create mode 100644 newsfragments/2737.internal.rst diff --git a/newsfragments/2737.internal.rst b/newsfragments/2737.internal.rst new file mode 100644 index 0000000000..38ee3331c1 --- /dev/null +++ b/newsfragments/2737.internal.rst @@ -0,0 +1 @@ +Remove internal method ``apply_formatter_to_array`` and use the method with the same name from the ``eth-utils`` library. diff --git a/web3/_utils/formatters.py b/web3/_utils/formatters.py index f735424cc8..cbd94e8007 100644 --- a/web3/_utils/formatters.py +++ b/web3/_utils/formatters.py @@ -6,7 +6,6 @@ Callable, Dict, Iterable, - Sequence, Tuple, TypeVar, ) @@ -19,7 +18,6 @@ is_list_like, is_string, to_dict, - to_list, ) from eth_utils.curried import ( apply_formatter_at_index, @@ -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. diff --git a/web3/providers/eth_tester/middleware.py b/web3/providers/eth_tester/middleware.py index 9db386c00a..28b5baec9f 100644 --- a/web3/providers/eth_tester/middleware.py +++ b/web3/providers/eth_tester/middleware.py @@ -30,7 +30,6 @@ ) from web3._utils.formatters import ( - apply_formatter_to_array, apply_formatters_to_args, apply_key_map, hex_to_integer, @@ -38,6 +37,9 @@ is_array_of_dicts, static_return, ) +from web3._utils.method_formatters import ( + apply_list_to_array_formatter, +) from web3.middleware import ( construct_formatting_middleware, ) @@ -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) @@ -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"}), ), } @@ -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) @@ -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,