@@ -358,19 +358,21 @@ def _align_abi_input(arg_abi, arg):
358
358
359
359
if isinstance (arg , abc .Mapping ):
360
360
# Arg is mapping. Align values according to abi order.
361
- arg = tuple (arg [abi ['name' ]] for abi in sub_abis )
361
+ aligned_arg = tuple (arg [abi ['name' ]] for abi in sub_abis )
362
+ else :
363
+ aligned_arg = arg
362
364
363
- if not is_list_like (arg ):
365
+ if not is_list_like (aligned_arg ):
364
366
raise TypeError (
365
367
'Expected non-string sequence for "{}" component type: got {}' .format (
366
368
arg_abi ['type' ],
367
- arg ,
369
+ aligned_arg ,
368
370
),
369
371
)
370
372
371
- return type (arg )(
373
+ return type (aligned_arg )(
372
374
_align_abi_input (sub_abi , sub_arg )
373
- for sub_abi , sub_arg in zip (sub_abis , arg )
375
+ for sub_abi , sub_arg in zip (sub_abis , aligned_arg )
374
376
)
375
377
376
378
@@ -668,34 +670,39 @@ def __new__(cls, iterable):
668
670
return super ().__new__ (cls , * iterable )
669
671
670
672
671
- def abi_sub_tree (abi_type : Optional [Union [TypeStr , ABIType ]], data_value : Any ) -> ABITypedData :
672
- if abi_type is None :
673
+ def abi_sub_tree (type_str_or_abi_type : Optional [Union [TypeStr , ABIType ]],
674
+ data_value : Any ) -> ABITypedData :
675
+ if type_str_or_abi_type is None :
673
676
return ABITypedData ([None , data_value ])
674
677
675
- if isinstance (abi_type , TypeStr ):
676
- abi_type = parse (abi_type )
678
+ if isinstance (type_str_or_abi_type , TypeStr ):
679
+ abi_type = parse (type_str_or_abi_type )
680
+ else :
681
+ abi_type = type_str_or_abi_type
677
682
678
683
# In the two special cases below, we rebuild the given data structures with
679
684
# annotated items
680
685
if abi_type .is_array :
681
686
# If type is array, determine item type and annotate all
682
687
# items in iterable with that type
683
688
item_type_str = abi_type .item_type .to_type_str ()
684
- data_value = [
689
+ value_to_annotate = [
685
690
abi_sub_tree (item_type_str , item_value )
686
691
for item_value in data_value
687
692
]
688
693
elif isinstance (abi_type , TupleType ):
689
694
# Otherwise, if type is tuple, determine component types and annotate
690
695
# tuple components in iterable respectively with those types
691
- data_value = type (data_value )(
696
+ value_to_annotate = type (data_value )(
692
697
abi_sub_tree (comp_type .to_type_str (), comp_value )
693
698
for comp_type , comp_value in zip (abi_type .components , data_value )
694
699
)
700
+ else :
701
+ value_to_annotate = data_value
695
702
696
703
return ABITypedData ([
697
704
abi_type .to_type_str (),
698
- data_value ,
705
+ value_to_annotate ,
699
706
])
700
707
701
708
0 commit comments