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..54d35803e9 100644 --- a/web3/_utils/abi.py +++ b/web3/_utils/abi.py @@ -618,13 +618,12 @@ def normalizer(datatype, data): *map(data_tree_map, normalizers), # 3. Stripping the types back out of the tree strip_abi_types, + list, ) @curry -def abi_data_tree( - types: Iterable[TypeStr], data: Iterable[Any] -) -> List["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. @@ -634,7 +633,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 +928,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):