diff --git a/ethpm/_utils/deployments.py b/ethpm/_utils/deployments.py index 13ef648a93..e6cfe7f927 100644 --- a/ethpm/_utils/deployments.py +++ b/ethpm/_utils/deployments.py @@ -70,7 +70,7 @@ def validate_linked_references( "Error validating linked reference. " f"Offset: {offset} " f"Value: {values[idx]} " - f"Bytecode: {bytecode} ." + f"Bytecode: {bytecode!r} ." ) @@ -122,8 +122,8 @@ def validate_deployments_tx_receipt( if tx_receipt["blockHash"] != to_bytes(hexstr=data["block"]): raise EthPMValidationError( f"Error validating tx_receipt for {name} deployment. " - f"Block found in manifest's deployment data: {data['block']} does not " - f"Does not match block found on tx_receipt: {tx_receipt['blockHash']}." + f"Block found in manifest's deployment data: {data['block']!r} does not " + f"Does not match block found on tx_receipt: {tx_receipt['blockHash']!r}." ) elif allow_missing_data is False: raise EthPMValidationError( diff --git a/ethpm/package.py b/ethpm/package.py index 79d1a20d5d..139c412614 100644 --- a/ethpm/package.py +++ b/ethpm/package.py @@ -301,7 +301,7 @@ def get_contract_instance(self, name: ContractName, address: Address) -> Contrac except KeyError: raise InsufficientAssetsError( "Package does not have the ABI required to generate a contract instance " - f"for contract: {name} at address: {address}." + f"for contract: {name} at address: {address!r}." ) contract_kwargs = generate_contract_factory_kwargs( self.manifest["contractTypes"][name] diff --git a/ethpm/validation/misc.py b/ethpm/validation/misc.py index 14f05012dc..2b3807c203 100644 --- a/ethpm/validation/misc.py +++ b/ethpm/validation/misc.py @@ -22,8 +22,8 @@ def validate_empty_bytes(offset: int, length: int, bytecode: bytes) -> None: slot = bytecode[offset:slot_length] if slot != bytearray(length): raise EthPMValidationError( - f"Bytecode segment: [{offset}:{slot_length}] is not comprised of empty bytes, " - f"rather: {slot}." + f"Bytecode segment: [{offset}:{slot_length}] " + f"is not comprised of empty bytes, rather: {slot!r}." ) diff --git a/newsfragments/1980.misc.rst b/newsfragments/1980.misc.rst new file mode 100644 index 0000000000..7e2931c1c9 --- /dev/null +++ b/newsfragments/1980.misc.rst @@ -0,0 +1 @@ +Update mypy from 0.730 to 0.812 diff --git a/setup.py b/setup.py index d2f0caf2f9..10c2ba37ee 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ 'linter': [ "flake8==3.8.3", "isort>=4.2.15,<4.3.5", - "mypy==0.730", + "mypy==0.812", ], 'docs': [ "mock", diff --git a/web3/_utils/abi.py b/web3/_utils/abi.py index 2288b98584..7fbdc9968b 100644 --- a/web3/_utils/abi.py +++ b/web3/_utils/abi.py @@ -580,7 +580,7 @@ def get_constructor_abi(contract_abi: ABI) -> ABIFunction: abi for abi in contract_abi if abi['type'] == 'constructor' ] if len(candidates) == 1: - return cast(ABIFunction, candidates[0]) + return candidates[0] elif len(candidates) == 0: return None elif len(candidates) > 1: diff --git a/web3/_utils/events.py b/web3/_utils/events.py index 34468c5730..896535af7e 100644 --- a/web3/_utils/events.py +++ b/web3/_utils/events.py @@ -332,8 +332,8 @@ def fromBlock(self, value: BlockIdentifier) -> None: self._fromBlock = value else: raise ValueError( - "fromBlock is already set to {0}. " - "Resetting filter parameters is not permitted".format(self._fromBlock)) + f"fromBlock is already set to {self._fromBlock!r}. " + "Resetting filter parameters is not permitted") @property def toBlock(self) -> BlockIdentifier: @@ -345,8 +345,8 @@ def toBlock(self, value: BlockIdentifier) -> None: self._toBlock = value else: raise ValueError( - "toBlock is already set to {0}. " - "Resetting filter parameters is not permitted".format(self._toBlock)) + f"toBlock is already set to {self._toBlock!r}. " + "Resetting filter parameters is not permitted") @property def address(self) -> ChecksumAddress: @@ -358,8 +358,8 @@ def address(self, value: ChecksumAddress) -> None: self._address = value else: raise ValueError( - "address is already set to {0}. " - "Resetting filter parameters is not permitted".format(self.address)) + f"address is already set to {self.address!r}. " + "Resetting filter parameters is not permitted") @property def ordered_args(self) -> Tuple[Any, ...]: diff --git a/web3/_utils/method_formatters.py b/web3/_utils/method_formatters.py index 1562d7806b..de94ed2904 100644 --- a/web3/_utils/method_formatters.py +++ b/web3/_utils/method_formatters.py @@ -586,7 +586,7 @@ def get_request_formatters( def raise_block_not_found(params: Tuple[BlockIdentifier, bool]) -> NoReturn: block_identifier = params[0] - raise BlockNotFound(f"Block with id: {block_identifier} not found.") + raise BlockNotFound(f"Block with id: {block_identifier!r} not found.") def raise_block_not_found_for_uncle_at_index( @@ -595,13 +595,14 @@ def raise_block_not_found_for_uncle_at_index( block_identifier = params[0] uncle_index = to_integer_if_hex(params[1]) raise BlockNotFound( - f"Uncle at index: {uncle_index} of block with id: {block_identifier} not found." + f"Uncle at index: {uncle_index} of block with id: " + f"{block_identifier!r} not found." ) def raise_transaction_not_found(params: Tuple[_Hash32]) -> NoReturn: transaction_hash = params[0] - raise TransactionNotFound(f"Transaction with hash: {transaction_hash} not found.") + raise TransactionNotFound(f"Transaction with hash: {transaction_hash!r} not found.") def raise_transaction_not_found_with_index(params: Tuple[BlockIdentifier, int]) -> NoReturn: @@ -609,7 +610,7 @@ def raise_transaction_not_found_with_index(params: Tuple[BlockIdentifier, int]) transaction_index = to_integer_if_hex(params[1]) raise TransactionNotFound( f"Transaction index: {transaction_index} " - f"on block id: {block_identifier} not found." + f"on block id: {block_identifier!r} not found." ) diff --git a/web3/_utils/transactions.py b/web3/_utils/transactions.py index e484960ffa..165dc7a339 100644 --- a/web3/_utils/transactions.py +++ b/web3/_utils/transactions.py @@ -141,8 +141,7 @@ def get_buffered_gas_estimate( def get_required_transaction(web3: "Web3", transaction_hash: _Hash32) -> TxData: current_transaction = web3.eth.get_transaction(transaction_hash) if not current_transaction: - raise ValueError('Supplied transaction with hash {} does not exist' - .format(transaction_hash)) + raise ValueError(f'Supplied transaction with hash {transaction_hash!r} does not exist') return current_transaction @@ -186,8 +185,8 @@ def prepare_replacement_transaction( gas_multiplier: float = 1.125 ) -> TxParams: if current_transaction['blockHash'] is not None: - raise ValueError('Supplied transaction with hash {} has already been mined' - .format(current_transaction['hash'])) + raise ValueError(f'Supplied transaction with hash {current_transaction["hash"]!r} ' + 'has already been mined') if 'nonce' in new_transaction and new_transaction['nonce'] != current_transaction['nonce']: raise ValueError('Supplied nonce in new_transaction must match the pending transaction') diff --git a/web3/contract.py b/web3/contract.py index 340d384b46..579cb4309b 100644 --- a/web3/contract.py +++ b/web3/contract.py @@ -1160,9 +1160,9 @@ def _parse_logs( raise e else: warnings.warn( - f"The log with transaction hash: {log['transactionHash']} and " + f"The log with transaction hash: {log['transactionHash']!r} and " f"logIndex: {log['logIndex']} encountered the following error " - f'during processing: {type(e).__name__}({e}). It has been discarded.' + f"during processing: {type(e).__name__}({e}). It has been discarded." ) continue yield rich_log @@ -1518,12 +1518,8 @@ def call_contract_function( ) else: msg = ( - "Could not decode contract function call {} return data {} for " - "output_types {}".format( - function_identifier, - return_data, - output_types - ) + "Could not decode contract function call {function_identifier} " + "return data {return_data!r} for output_types {output_types}" ) raise BadFunctionCallOutput(msg) from e diff --git a/web3/gas_strategies/time_based.py b/web3/gas_strategies/time_based.py index 4005435d0b..34af8e6cde 100644 --- a/web3/gas_strategies/time_based.py +++ b/web3/gas_strategies/time_based.py @@ -113,7 +113,7 @@ def _aggregate_miner_data( yield MinerData( miner, len(set(block_hashes)), - min(gas_prices), + min(gas_prices), # type: ignore price_percentile) diff --git a/web3/middleware/filter.py b/web3/middleware/filter.py index b1ec26b1a7..5b2f82a417 100644 --- a/web3/middleware/filter.py +++ b/web3/middleware/filter.py @@ -240,7 +240,7 @@ def __init__( self._from_block = BlockNumber(hex_to_integer(from_block)) # type: ignore else: # cast b/c LatestBlockParam is handled above - self._from_block = cast(BlockNumber, from_block) + self._from_block = from_block self._to_block = to_block self.filter_changes = self._get_filter_changes() @@ -257,7 +257,7 @@ def to_block(self) -> BlockNumber: elif is_hex(self._to_block): to_block = BlockNumber(hex_to_integer(self._to_block)) # type: ignore else: - to_block = cast(BlockNumber, self._to_block) + to_block = self._to_block return to_block diff --git a/web3/middleware/stalecheck.py b/web3/middleware/stalecheck.py index 86711ee67c..7b244653f9 100644 --- a/web3/middleware/stalecheck.py +++ b/web3/middleware/stalecheck.py @@ -26,7 +26,10 @@ def _isfresh(block: BlockData, allowable_delay: int) -> bool: - return block and time.time() - block['timestamp'] <= allowable_delay + if block and (time.time() - block['timestamp'] <= allowable_delay): + return True + else: + return False def make_stalecheck_middleware( diff --git a/web3/pm.py b/web3/pm.py index 5257db22bd..10cd5ccff7 100644 --- a/web3/pm.py +++ b/web3/pm.py @@ -389,13 +389,13 @@ def set_registry(self, address: Union[Address, ChecksumAddress, ENS]) -> None: addr_lookup = self.web3.ens.address(str(address)) if not addr_lookup: raise NameNotFound( - "No address found after ENS lookup for name: {0}.".format(address) + f"No address found after ENS lookup for name: {address!r}." ) self.registry = SimpleRegistry(addr_lookup, self.web3) else: raise PMError( "Expected a canonical/checksummed address or ENS name for the address, " - "instead received {0}.".format(type(address)) + f"instead received {type(address)}." ) def deploy_and_set_registry(self) -> ChecksumAddress: