Skip to content

Commit

Permalink
chore: remove unused type ignores and other small items [APE-1419] (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Sep 27, 2023
1 parent d70ed9b commit 1c776db
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/ape/api/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ def serialize_transaction(self, transaction: "TransactionAPI") -> bytes:

unsigned_txn = serializable_unsigned_transaction_from_dict(txn_data)
signature = (
self.signature.v, # type: ignore
to_int(self.signature.r), # type: ignore
to_int(self.signature.s), # type: ignore
self.signature.v,
to_int(self.signature.r),
to_int(self.signature.s),
)

signed_txn = encode_transaction(unsigned_txn, signature)
Expand Down
8 changes: 4 additions & 4 deletions src/ape/api/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1250,8 +1250,8 @@ def get_transactions_by_block(self, block_id: BlockID) -> Iterator[TransactionAP
def get_transactions_by_account_nonce(
self,
account: AddressType,
start_nonce: int,
stop_nonce: int,
start_nonce: int = 0,
stop_nonce: int = -1,
) -> Iterator[ReceiptAPI]:
if start_nonce > stop_nonce:
raise ValueError("Starting nonce cannot be greater than stop nonce for search")
Expand Down Expand Up @@ -1326,7 +1326,7 @@ def block_ranges(self, start=0, stop=None, page=None):
stop_block = min(stop, start_block + page - 1)
yield start_block, stop_block

def get_contract_creation_receipts( # type: ignore[empty-body]
def get_contract_creation_receipts(
self,
address: AddressType,
start_block: int = 0,
Expand Down Expand Up @@ -1657,7 +1657,7 @@ class SubprocessProvider(ProviderAPI):
A provider that manages a process, such as for ``ganache``.
"""

PROCESS_WAIT_TIMEOUT = 15
PROCESS_WAIT_TIMEOUT: int = 15
process: Optional[Popen] = None
is_stopping: bool = False

Expand Down
5 changes: 3 additions & 2 deletions src/ape/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from inspect import getframeinfo, stack
from pathlib import Path
from types import CodeType, TracebackType
from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Union
from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Union, cast

import click
from eth_typing import Hash32
from eth_utils import humanize_hash
from ethpm_types.abi import ConstructorABI, ErrorABI, MethodABI
from rich import print as rich_print
Expand Down Expand Up @@ -418,7 +419,7 @@ class UnknownSnapshotError(ChainError):
def __init__(self, snapshot_id: "SnapshotID"):
if isinstance(snapshot_id, bytes):
# Is block hash
snapshot_id = humanize_hash(snapshot_id) # type: ignore
snapshot_id = humanize_hash(cast(Hash32, snapshot_id))

super().__init__(f"Unknown snapshot ID '{str(snapshot_id)}'.")

Expand Down
2 changes: 1 addition & 1 deletion src/ape/plugins/pluggy_patch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Callable, TypeVar, cast

import pluggy # type: ignore
import pluggy

F = TypeVar("F", bound=Callable[..., Any])
hookimpl = cast(Callable[[F], F], pluggy.HookimplMarker("ape"))
Expand Down
1 change: 0 additions & 1 deletion src/ape/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ def __contains__(self, val: Any) -> bool:
"ContractLogContainer",
"ContractType",
"ControlFlow",
"CoverageItem",
"CoverageProject",
"CoverageReport",
"CoverageStatement",
Expand Down
4 changes: 2 additions & 2 deletions src/ape_cache/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def _get_block_txns_data(
new_dict = {k: v for k, v in val.dict(by_alias=False).items() if k in table_columns}
for col in table_columns:
if col == "txn_hash":
new_dict["txn_hash"] = val.txn_hash # type: ignore
new_dict["txn_hash"] = val.txn_hash
elif col == "sender":
new_dict["sender"] = new_dict["sender"].encode()
elif col == "receiver" and "receiver" in new_dict:
Expand All @@ -429,7 +429,7 @@ def _get_block_txns_data(
elif col == "block_hash":
new_dict["block_hash"] = query.block_id
elif col == "signature":
new_dict["signature"] = val.signature.encode_rsv() # type: ignore
new_dict["signature"] = val.signature.encode_rsv()
elif col not in new_dict:
new_dict[col] = None
new_result.append(new_dict)
Expand Down
4 changes: 2 additions & 2 deletions src/ape_console/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from typing import Any, Dict, cast

import click
import IPython # type: ignore
from IPython.terminal.ipapp import Config as IPythonConfig # type: ignore
import IPython
from IPython.terminal.ipapp import Config as IPythonConfig

from ape import config
from ape import project as default_project
Expand Down
4 changes: 2 additions & 2 deletions src/ape_console/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import click
from click.testing import CliRunner
from eth_utils import is_hex
from IPython import get_ipython # type: ignore
from IPython.core.magic import Magics, line_magic, magics_class # type: ignore
from IPython import get_ipython
from IPython.core.magic import Magics, line_magic, magics_class

import ape
from ape._cli import cli
Expand Down
4 changes: 3 additions & 1 deletion src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ class Ethereum(EcosystemAPI):

@property
def config(self) -> EthereumConfig:
return self.config_manager.get_config("ethereum") # type: ignore
result = self.config_manager.get_config("ethereum")
assert isinstance(result, EthereumConfig) # For mypy
return result

@property
def default_transaction_type(self) -> TransactionType:
Expand Down
5 changes: 1 addition & 4 deletions src/ape_ethereum/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ class AccessListTransaction(BaseTransaction):

@validator("type", allow_reuse=True)
def check_type(cls, value):
if isinstance(value, TransactionType):
return value.value

return value
return value.value if isinstance(value, TransactionType) else value


class Receipt(ReceiptAPI):
Expand Down
8 changes: 6 additions & 2 deletions src/ape_geth/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@ def disconnect(self):
self._process = None

# Also unset the subprocess-provider reference.
self.process = None
# NOTE: Type ignore is wrong; TODO: figure out why.
self.process = None # type: ignore[assignment]

super().disconnect()

Expand Down Expand Up @@ -670,7 +671,10 @@ def http_provider():

def ipc_provider():
# NOTE: This mypy complaint seems incorrect.
return IPCProvider(ipc_path=ipc_path) # type: ignore[arg-type]
if not (path := ipc_path):
raise ValueError("IPC Path required.")

return IPCProvider(ipc_path=path)

# NOTE: This tuple is ordered by try-attempt.
# Try ENV, then IPC, and then HTTP last.
Expand Down
4 changes: 2 additions & 2 deletions src/ape_test/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import click
import pytest
from watchdog import events # type: ignore
from watchdog.observers import Observer # type: ignore
from watchdog import events
from watchdog.observers import Observer

from ape.cli import ape_cli_context
from ape.utils import ManagerAccessMixin, cached_property
Expand Down
3 changes: 2 additions & 1 deletion src/ape_test/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ def estimate_gas_cost(self, txn: TransactionAPI, **kwargs) -> int:
# Remove from dict before estimating
txn_dict.pop("gas")

txn_data = cast(TxParams, txn_dict)
try:
return estimate_gas(txn_dict, block_identifier=block_id) # type: ignore
return estimate_gas(txn_data, block_identifier=block_id)
except (ValidationError, TransactionFailed) as err:
ape_err = self.get_virtual_machine_error(err, txn=txn)
gas_match = self._INVALID_NONCE_PATTERN.match(str(ape_err))
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/test_contract_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def test_structs(contract_instance, owner, chain):

# Expected: b == block.prevhash.
assert actual.b == actual["b"] == actual[1] == actual_prev_block == chain.blocks[-2].hash
assert type(actual.b) is HexBytes
assert isinstance(actual.b, bytes)


def test_nested_structs(contract_instance, owner, chain):
Expand All @@ -254,15 +254,15 @@ def test_nested_structs(contract_instance, owner, chain):
== actual_prev_block_1
== chain.blocks[-2].hash
)
assert type(actual_1.t.b) is HexBytes
assert isinstance(actual_1.t.b, bytes)
assert (
actual_2.t.b
== actual_2.t["b"]
== actual_2.t[1]
== actual_prev_block_2
== chain.blocks[-2].hash
)
assert type(actual_2.t.b) is HexBytes
assert isinstance(actual_2.t.b, bytes)


def test_nested_structs_in_tuples(contract_instance, owner, chain):
Expand Down

0 comments on commit 1c776db

Please sign in to comment.