8686
8787
8888def filter_by_type (_type : str , contract_abi : ABI ) -> List [Union [ABIFunction , ABIEvent ]]:
89- # fix for this just landed, not yet released : https://github.com/python/mypy/pull/7917
90- # after it's released, update Union[ABIFunction, ABIEvent] -> ABIElement
91- return [abi for abi in contract_abi if abi ['type' ] == _type ] # type: ignore
89+ return [abi for abi in contract_abi if abi ['type' ] == _type ]
9290
9391
9492def filter_by_name (name : str , contract_abi : ABI ) -> List [Union [ABIFunction , ABIEvent ]]:
@@ -97,25 +95,24 @@ def filter_by_name(name: str, contract_abi: ABI) -> List[Union[ABIFunction, ABIE
9795 for abi
9896 in contract_abi
9997 if (
100- # type ignored b/c see line 91
101- abi ['type' ] not in ('fallback' , 'constructor' ) and # type: ignore
102- abi ['name' ] == name # type: ignore
98+ abi ['type' ] not in ('fallback' , 'constructor' ) and
99+ abi ['name' ] == name
103100 )
104101 ]
105102
106103
107- def get_abi_input_types (abi : Union [ ABIFunction , ABIEvent ] ) -> List [str ]:
104+ def get_abi_input_types (abi : ABIFunction ) -> List [str ]:
108105 if 'inputs' not in abi and abi ['type' ] == 'fallback' :
109106 return []
110107 else :
111- return [collapse_if_tuple (arg ) for arg in abi ['inputs' ]]
108+ return [collapse_if_tuple (cast ( Dict [ str , Any ], arg ) ) for arg in abi ['inputs' ]]
112109
113110
114- def get_abi_output_types (abi : Union [ ABIFunction , ABIEvent ] ) -> List [str ]:
111+ def get_abi_output_types (abi : ABIFunction ) -> List [str ]:
115112 if abi ['type' ] == 'fallback' :
116113 return []
117114 else :
118- return [collapse_if_tuple (arg ) for arg in abi ['outputs' ]]
115+ return [collapse_if_tuple (cast ( Dict [ str , Any ], arg ) ) for arg in abi ['outputs' ]]
119116
120117
121118def get_abi_input_names (abi : Union [ABIFunction , ABIEvent ]) -> List [str ]:
@@ -128,7 +125,7 @@ def get_abi_input_names(abi: Union[ABIFunction, ABIEvent]) -> List[str]:
128125def get_fallback_func_abi (contract_abi : ABI ) -> ABIFunction :
129126 fallback_abis = filter_by_type ('fallback' , contract_abi )
130127 if fallback_abis :
131- return fallback_abis [0 ]
128+ return cast ( ABIFunction , fallback_abis [0 ])
132129 else :
133130 raise FallbackNotFound ("No fallback function was found in the contract ABI." )
134131
@@ -152,8 +149,7 @@ def filter_by_argument_count(
152149 abi
153150 for abi
154151 in contract_abi
155- # type ignored b/c see line 91
156- if len (abi ['inputs' ]) == num_arguments # type: ignore
152+ if len (abi ['inputs' ]) == num_arguments
157153 ]
158154
159155
@@ -373,10 +369,12 @@ def filter_by_encodability(
373369 abi_codec : codec .ABIEncoder , args : Sequence [Any ], kwargs : Dict [str , Any ], contract_abi : ABI
374370) -> List [ABIFunction ]:
375371 return [
376- function_abi
372+ cast ( ABIFunction , function_abi )
377373 for function_abi
378374 in contract_abi
379- if check_if_arguments_can_be_encoded (function_abi , abi_codec , args , kwargs )
375+ if check_if_arguments_can_be_encoded (
376+ cast (ABIFunction , function_abi ), abi_codec , args , kwargs
377+ )
380378 ]
381379
382380
@@ -516,7 +514,7 @@ def _align_abi_input(arg_abi: ABIFunctionParams, arg: Any) -> Tuple[Any, ...]:
516514 new_abi = copy .copy (arg_abi )
517515 new_abi ['type' ] = tuple_prefix
518516
519- sub_abis = itertools .repeat (new_abi )
517+ sub_abis = itertools .repeat (new_abi ) # type: ignore
520518
521519 if isinstance (arg , abc .Mapping ):
522520 # Arg is mapping. Align values according to abi order.
@@ -555,7 +553,9 @@ def get_aligned_abi_inputs(
555553 args = tuple (args [abi ['name' ]] for abi in input_abis )
556554
557555 return (
558- tuple (collapse_if_tuple (abi ) for abi in input_abis ),
556+ # typed dict cannot be used w/ a normal Dict
557+ # https://github.com/python/mypy/issues/4976
558+ tuple (collapse_if_tuple (abi ) for abi in input_abis ), # type: ignore
559559 # too many arguments for Sequence
560560 type (args )( # type: ignore
561561 _align_abi_input (abi , arg )
@@ -566,11 +566,10 @@ def get_aligned_abi_inputs(
566566
567567def get_constructor_abi (contract_abi : ABI ) -> ABIFunction :
568568 candidates = [
569- # type ignored b/c see line 91
570- abi for abi in contract_abi if abi ['type' ] == 'constructor' # type: ignore
569+ abi for abi in contract_abi if abi ['type' ] == 'constructor'
571570 ]
572571 if len (candidates ) == 1 :
573- return candidates [0 ]
572+ return cast ( ABIFunction , candidates [0 ])
574573 elif len (candidates ) == 0 :
575574 return None
576575 elif len (candidates ) > 1 :
@@ -725,7 +724,7 @@ def is_probably_enum(abi_type: TypeStr) -> bool:
725724@to_tuple
726725def normalize_event_input_types (
727726 abi_args : Collection [Union [ABIFunction , ABIEvent ]]
728- ) -> Iterable [Union [TypeStr , Dict [TypeStr , Any ]]]:
727+ ) -> Iterable [Union [ABIFunction , ABIEvent , Dict [TypeStr , Any ]]]:
729728 for arg in abi_args :
730729 if is_recognized_type (arg ['type' ]):
731730 yield arg
@@ -739,8 +738,7 @@ def abi_to_signature(abi: Union[ABIFunction, ABIEvent]) -> str:
739738 function_signature = "{fn_name}({fn_input_types})" .format (
740739 fn_name = abi ['name' ],
741740 fn_input_types = ',' .join ([
742- # type ignored b/c see line 91
743- arg ['type' ] for arg in normalize_event_input_types (abi .get ('inputs' , [])) # type: ignore # noqa: E501
741+ arg ['type' ] for arg in normalize_event_input_types (abi .get ('inputs' , []))
744742 ]),
745743 )
746744 return function_signature
0 commit comments