Skip to content

Commit

Permalink
Use Optional for typing on eth.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxio0 committed Jun 10, 2020
1 parent 587d673 commit 7c6209f
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions web3/eth.py
Expand Up @@ -153,7 +153,8 @@ def chainId(self) -> int:
return self.web3.manager.request_blocking(RPC.eth_chainId, [])

def getBalance(
self, account: Union[Address, ChecksumAddress, ENS], block_identifier: BlockIdentifier=None
self, account: Union[Address, ChecksumAddress, ENS],
block_identifier: Optional[BlockIdentifier] = None
) -> Wei:
if block_identifier is None:
block_identifier = self.defaultBlock
Expand All @@ -166,7 +167,7 @@ def getStorageAt(
self,
account: Union[Address, ChecksumAddress, ENS],
position: int,
block_identifier: BlockIdentifier=None
block_identifier: Optional[BlockIdentifier] = None
) -> bytes:
if block_identifier is None:
block_identifier = self.defaultBlock
Expand All @@ -179,7 +180,7 @@ def getProof(
self,
account: Union[Address, ChecksumAddress, ENS],
positions: Sequence[int],
block_identifier: BlockIdentifier=None
block_identifier: Optional[BlockIdentifier] = None
) -> MerkleProof:
if block_identifier is None:
block_identifier = self.defaultBlock
Expand All @@ -189,7 +190,8 @@ def getProof(
)

def getCode(
self, account: Union[Address, ChecksumAddress, ENS], block_identifier: BlockIdentifier=None
self, account: Union[Address, ChecksumAddress, ENS],
block_identifier: Optional[BlockIdentifier] = None
) -> HexBytes:
if block_identifier is None:
block_identifier = self.defaultBlock
Expand All @@ -199,7 +201,7 @@ def getCode(
)

def getBlock(
self, block_identifier: BlockIdentifier, full_transactions: bool=False
self, block_identifier: BlockIdentifier, full_transactions: bool = False
) -> BlockData:
"""
`eth_getBlockByHash`
Expand Down Expand Up @@ -344,7 +346,8 @@ def getTransactionReceipt(self, transaction_hash: _Hash32) -> TxReceipt:
return result

def getTransactionCount(
self, account: Union[Address, ChecksumAddress, ENS], block_identifier: BlockIdentifier=None
self, account: Union[Address, ChecksumAddress, ENS],
block_identifier: Optional[BlockIdentifier] = None
) -> Nonce:
if block_identifier is None:
block_identifier = self.defaultBlock
Expand Down Expand Up @@ -395,9 +398,9 @@ def sendRawTransaction(self, raw_transaction: HexStr) -> HexBytes:
def sign(
self,
account: Union[Address, ChecksumAddress, ENS],
data: Union[int, bytes]=None,
hexstr: HexStr=None,
text: str=None
data: Optional[Union[int, bytes]] = None,
hexstr: Optional[HexStr] = None,
text: Optional[str] = None
) -> HexStr:
message_hex = to_hex(data, hexstr=hexstr, text=text)
return self.web3.manager.request_blocking(
Expand All @@ -417,7 +420,8 @@ def signTypedData(
)

@apply_to_return_value(HexBytes)
def call(self, transaction: TxParams, block_identifier: BlockIdentifier=None) -> Sequence[Any]:
def call(self, transaction: TxParams,
block_identifier: Optional[BlockIdentifier] = None) -> Sequence[Any]:
# TODO: move to middleware
if 'from' not in transaction and is_checksum_address(self.defaultAccount):
transaction = assoc(transaction, 'from', self.defaultAccount)
Expand All @@ -430,7 +434,8 @@ def call(self, transaction: TxParams, block_identifier: BlockIdentifier=None) ->
[transaction, block_identifier],
)

def estimateGas(self, transaction: TxParams, block_identifier: BlockIdentifier=None) -> Wei:
def estimateGas(self, transaction: TxParams,
block_identifier: Optional[BlockIdentifier] = None) -> Wei:
# TODO: move to middleware
if 'from' not in transaction and is_checksum_address(self.defaultAccount):
transaction = assoc(transaction, 'from', self.defaultAccount)
Expand All @@ -446,7 +451,8 @@ def estimateGas(self, transaction: TxParams, block_identifier: BlockIdentifier=N
)

def filter(
self, filter_params: Union[str, FilterParams]=None, filter_id: HexStr=None
self, filter_params: Optional[Union[str, FilterParams]] = None,
filter_id: Optional[HexStr] = None
) -> Filter:
if filter_id and filter_params:
raise TypeError(
Expand Down Expand Up @@ -519,7 +525,7 @@ def contract(self, address: None=None, **kwargs: Any) -> Type[Contract]: ... #
def contract(self, address: Union[Address, ChecksumAddress, ENS], **kwargs: Any) -> Contract: ... # noqa: E704,E501

def contract( # noqa: F811
self, address: Union[Address, ChecksumAddress, ENS]=None, **kwargs: Any
self, address: Optional[Union[Address, ChecksumAddress, ENS]] = None, **kwargs: Any
) -> Union[Type[Contract], Contract]:
ContractFactoryClass = kwargs.pop('ContractFactoryClass', self.defaultContractFactory)

Expand All @@ -541,7 +547,7 @@ def getCompilers(self) -> NoReturn:
def getWork(self) -> List[HexBytes]:
return self.web3.manager.request_blocking(RPC.eth_getWork, [])

def generateGasPrice(self, transaction_params: TxParams=None) -> Optional[Wei]:
def generateGasPrice(self, transaction_params: Optional[TxParams] = None) -> Optional[Wei]:
if self.gasPriceStrategy:
return self.gasPriceStrategy(self.web3, transaction_params)
return None
Expand Down

0 comments on commit 7c6209f

Please sign in to comment.