Skip to content

Commit

Permalink
Update mypy to 0.812
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed May 6, 2021
1 parent f143b0e commit cfd97bd
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 36 deletions.
6 changes: 3 additions & 3 deletions ethpm/_utils/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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} ."
)


Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion ethpm/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions ethpm/validation/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}."
)


Expand Down
1 change: 1 addition & 0 deletions newsfragments/1980.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update mypy from 0.730 to 0.812
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'linter': [
"flake8==3.8.3",
"isort>=4.2.15,<4.3.5",
"mypy==0.730",
"mypy==0.812",
],
'docs': [
"mock",
Expand Down
2 changes: 1 addition & 1 deletion web3/_utils/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions web3/_utils/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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, ...]:
Expand Down
9 changes: 5 additions & 4 deletions web3/_utils/method_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -595,21 +595,22 @@ 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:
block_identifier = params[0]
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."
)


Expand Down
7 changes: 3 additions & 4 deletions web3/_utils/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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')

Expand Down
12 changes: 4 additions & 8 deletions web3/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion web3/gas_strategies/time_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
4 changes: 2 additions & 2 deletions web3/middleware/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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

Expand Down
5 changes: 4 additions & 1 deletion web3/middleware/stalecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions web3/pm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit cfd97bd

Please sign in to comment.