- Notifications
You must be signed in to change notification settings - Fork388
Description
The wrong type annotation was used in theuniswap.uniswap.Uniswap
class. The parametersprovider
,web3
,factory_contract_addr
androuter_contract_addr
of the constructor default toNone
but are not declared asOptional
. This is very unfriendly to static type checkers (such as Pyright with strict type checking enabled). And it will generate a lot of type error prompts, but actually no problem.
classUniswap:""" Wrapper around Uniswap contracts. """ ...def__init__(self,address:Union[AddressLike,str,None],private_key:Optional[str],provider:str=None,web3:Web3=None,version:int=1,default_slippage:float=0.01,use_estimate_gas:bool=True,# use_eip1559: bool = True,factory_contract_addr:str=None,router_contract_addr:str=None,enable_caching:bool=False, )->None: ...
At the same time, the type annotation format ofaddress
andprivate_key
is confusing. In Python3.9 and below, the recommended declaration method isOptional[T]
to indicate that the parameter can beNone
. And in 3.10+, its recommended to useT | None
(alsoUnion[T, None]
). But here we can see the two different formats of type annotations are being used at the same time, which is confusing.
I suggest changing it to the following:
classUniswap:""" Wrapper around Uniswap contracts. """ ...def__init__(self,address:Optional[Union[AddressLike,str]],private_key:Optional[str],provider:Optional[str]=None,web3:Optional[Web3]=None,version:int=1,default_slippage:float=0.01,use_estimate_gas:bool=True,# use_eip1559: bool = True,factory_contract_addr:Optional[str]=None,router_contract_addr:Optional[str]=None,enable_caching:bool=False, )->None: ...
Also, I noticed that some function parameters/return values also have such annotations. Returns possibleNone
but noOptional
is declared. This will confuse the user for wasting more time debugging the type.