From 6024125113ec1324280606b528896d2991bd57da Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Fri, 16 May 2025 19:58:37 +0000 Subject: [PATCH 1/3] fix red stuff --- tests/core/utilities/test_abi.py | 2 +- web3/_utils/abi.py | 6 ++++-- web3/_utils/formatters.py | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/core/utilities/test_abi.py b/tests/core/utilities/test_abi.py index baebbec247..339a5563f2 100644 --- a/tests/core/utilities/test_abi.py +++ b/tests/core/utilities/test_abi.py @@ -262,7 +262,7 @@ def test_get_tuple_type_str_parts( def test_abi_data_tree( types: List[str], data: Tuple[List[bool], bytes], expected: List[Any] ) -> None: - assert abi_data_tree(types, data) == expected + assert list(abi_data_tree(types, data)) == expected @pytest.mark.parametrize( diff --git a/web3/_utils/abi.py b/web3/_utils/abi.py index df4902635b..0455378a6b 100644 --- a/web3/_utils/abi.py +++ b/web3/_utils/abi.py @@ -624,7 +624,7 @@ def normalizer(datatype, data): @curry def abi_data_tree( types: Iterable[TypeStr], data: Iterable[Any] -) -> List["ABITypedData"]: +) -> "map[ABITypedData]": """ Decorate the data tree with pairs of (type, data). The pair tuple is actually an ABITypedData, but can be accessed as a tuple. @@ -634,7 +634,7 @@ def abi_data_tree( >>> abi_data_tree(types=["bool[2]", "uint"], data=[[True, False], 0]) [("bool[2]", [("bool", True), ("bool", False)]), ("uint256", 0)] """ - return list(map(abi_sub_tree, types, data)) + return map(abi_sub_tree, types, data) @curry @@ -929,6 +929,8 @@ async def async_map_if_collection( If the value is not a collection, return it unmodified. """ datatype = type(value) + if datatype is map: + return [await func(item) for item in value] if isinstance(value, Mapping): return datatype({key: await func(val) for key, val in value.values()}) if is_string(value): diff --git a/web3/_utils/formatters.py b/web3/_utils/formatters.py index c01fcb8d7f..d886aad8d8 100644 --- a/web3/_utils/formatters.py +++ b/web3/_utils/formatters.py @@ -65,6 +65,8 @@ def map_collection(func: Callable[..., TReturn], collection: Any) -> Any: If the value is not a collection, return it unmodified """ datatype = type(collection) + if datatype is map: + return map(func, collection) if isinstance(collection, Mapping): return datatype((key, func(val)) for key, val in collection.items()) if is_string(collection): From f988116196b0bf0b9ec878bfa4b57fde01de5632 Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Fri, 16 May 2025 19:58:37 +0000 Subject: [PATCH 2/3] fix more red, way less fast :( --- web3/_utils/abi.py | 1 + 1 file changed, 1 insertion(+) diff --git a/web3/_utils/abi.py b/web3/_utils/abi.py index 0455378a6b..a8cf596630 100644 --- a/web3/_utils/abi.py +++ b/web3/_utils/abi.py @@ -618,6 +618,7 @@ def normalizer(datatype, data): *map(data_tree_map, normalizers), # 3. Stripping the types back out of the tree strip_abi_types, + list, ) From a55b44c16742a7567b1406d0ae50c4bdc5e10c7b Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Fri, 16 May 2025 19:58:37 +0000 Subject: [PATCH 3/3] chore: lint --- web3/_utils/abi.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/web3/_utils/abi.py b/web3/_utils/abi.py index a8cf596630..54d35803e9 100644 --- a/web3/_utils/abi.py +++ b/web3/_utils/abi.py @@ -623,9 +623,7 @@ def normalizer(datatype, data): @curry -def abi_data_tree( - types: Iterable[TypeStr], data: Iterable[Any] -) -> "map[ABITypedData]": +def abi_data_tree(types: Iterable[TypeStr], data: Iterable[Any]) -> "map[ABITypedData]": """ Decorate the data tree with pairs of (type, data). The pair tuple is actually an ABITypedData, but can be accessed as a tuple.