Skip to content

Commit

Permalink
chore: enable and impl flake8 type check
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Oct 29, 2024
1 parent 4199cac commit e301fdf
Show file tree
Hide file tree
Showing 64 changed files with 606 additions and 457 deletions.
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ exclude =
build
.eggs
tests/integration/cli/projects
ignore = E704,W503,PYD002
ignore = E704,W503,PYD002,TC003,TC006
per-file-ignores =
# Need signal handler before imports
src/ape/__init__.py: E402
# Test data causes long lines
tests/functional/data/python/__init__.py: E501
tests/functional/utils/expected_traces.py: E501

type-checking-pydantic-enabled = True
type-checking-sqlalchemy-enabled = True
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"flake8-breakpoint>=1.1.0,<2", # Detect breakpoints left in code
"flake8-print>=4.0.1,<5", # Detect print statements left in code
"flake8-pydantic", # For detecting issues with Pydantic models
"flake8-type-checking", # Detect imports to move in/out of type-checking blocks
"isort>=5.13.2,<6", # Import sorting linter
"mdformat>=0.7.18", # Auto-formatter for markdown
"mdformat-gfm>=0.3.5", # Needed for formatting GitHub-flavored markdown
Expand Down
8 changes: 5 additions & 3 deletions src/ape/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
from importlib import import_module
from importlib.metadata import entry_points
from pathlib import Path
from typing import Any, Optional
from typing import TYPE_CHECKING, Any, Optional

import click
import rich
import yaml
from click import Context

from ape.cli.options import ape_cli_context
from ape.exceptions import Abort, ApeException, ConfigError, handle_ape_exception
from ape.logging import logger
from ape.utils.basemodel import ManagerAccessMixin as access

if TYPE_CHECKING:
from click import Context

_DIFFLIB_CUT_OFF = 0.6


Expand Down Expand Up @@ -50,7 +52,7 @@ class ApeCLI(click.MultiCommand):
_commands: Optional[dict] = None
_CLI_GROUP_NAME = "ape_cli_subcommands"

def parse_args(self, ctx: Context, args: list[str]) -> list[str]:
def parse_args(self, ctx: "Context", args: list[str]) -> list[str]:
# Validate the config before any argument parsing,
# as arguments may utilize config.
if "--help" not in args and args != []:
Expand Down
5 changes: 3 additions & 2 deletions src/ape/api/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from eip712.messages import SignableMessage as EIP712SignableMessage
from eth_account import Account
from eth_account.messages import encode_defunct
from eth_pydantic_types import HexBytes
from eth_utils import to_hex
from ethpm_types import ContractType

Expand All @@ -31,6 +30,8 @@
from ape.utils.misc import raises_not_implemented

if TYPE_CHECKING:
from eth_pydantic_types import HexBytes

from ape.contracts import ContractContainer, ContractInstance


Expand Down Expand Up @@ -65,7 +66,7 @@ def alias(self) -> Optional[str]:
"""
return None

def sign_raw_msghash(self, msghash: HexBytes) -> Optional[MessageSignature]:
def sign_raw_msghash(self, msghash: "HexBytes") -> Optional[MessageSignature]:
"""
Sign a raw message hash.
Expand Down
4 changes: 2 additions & 2 deletions src/ape/api/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from ape.exceptions import ConversionError
from ape.types.address import AddressType
from ape.types.units import CurrencyValue
from ape.types.vm import ContractCode
from ape.utils.basemodel import BaseInterface
from ape.utils.misc import log_instead_of_fail

if TYPE_CHECKING:
from ape.api.transactions import ReceiptAPI, TransactionAPI
from ape.managers.chain import AccountHistory
from ape.types.vm import ContractCode


class BaseAddress(BaseInterface):
Expand Down Expand Up @@ -146,7 +146,7 @@ def __setattr__(self, attr: str, value: Any) -> None:
super().__setattr__(attr, value)

@property
def code(self) -> ContractCode:
def code(self) -> "ContractCode":
"""
The raw bytes of the smart-contract code at the address.
"""
Expand Down
36 changes: 18 additions & 18 deletions src/ape/api/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
from pathlib import Path
from typing import TYPE_CHECKING, Optional

from eth_pydantic_types import HexBytes
from ethpm_types import ContractType
from ethpm_types.source import Content, ContractSource
from packaging.version import Version

from ape.api.config import PluginConfig
from ape.api.trace import TraceAPI
from ape.exceptions import APINotImplementedError, ContractLogicError
from ape.types.coverage import ContractSourceCoverage
from ape.types.trace import SourceTraceback
from ape.utils.basemodel import BaseInterfaceModel
from ape.utils.misc import log_instead_of_fail, raises_not_implemented

if TYPE_CHECKING:
from eth_pydantic_types import HexBytes
from ethpm_types import ContractType
from ethpm_types.source import Content, ContractSource
from packaging.version import Version

from ape.api.config import PluginConfig
from ape.api.trace import TraceAPI
from ape.managers.project import ProjectManager
from ape.types.coverage import ContractSourceCoverage
from ape.types.trace import SourceTraceback


class CompilerAPI(BaseInterfaceModel):
Expand All @@ -44,7 +44,7 @@ def name(self) -> str:
The name of the compiler.
"""

def get_config(self, project: Optional["ProjectManager"] = None) -> PluginConfig:
def get_config(self, project: Optional["ProjectManager"] = None) -> "PluginConfig":
"""
The combination of settings from ``ape-config.yaml`` and ``.compiler_settings``.
Expand Down Expand Up @@ -79,7 +79,7 @@ def get_compiler_settings( # type: ignore[empty-body]
contract_filepaths: Iterable[Path],
project: Optional["ProjectManager"] = None,
**overrides,
) -> dict[Version, dict]:
) -> dict["Version", dict]:
"""
Get a mapping of the settings that would be used to compile each of the sources
by the compiler version number.
Expand All @@ -101,7 +101,7 @@ def compile(
contract_filepaths: Iterable[Path],
project: Optional["ProjectManager"],
settings: Optional[dict] = None,
) -> Iterator[ContractType]:
) -> Iterator["ContractType"]:
"""
Compile the given source files. All compiler plugins must implement this function.
Expand All @@ -123,7 +123,7 @@ def compile_code( # type: ignore[empty-body]
project: Optional["ProjectManager"],
settings: Optional[dict] = None,
**kwargs,
) -> ContractType:
) -> "ContractType":
"""
Compile a program.
Expand Down Expand Up @@ -162,7 +162,7 @@ def get_version_map( # type: ignore[empty-body]
self,
contract_filepaths: Iterable[Path],
project: Optional["ProjectManager"] = None,
) -> dict[Version, set[Path]]:
) -> dict["Version", set[Path]]:
"""
Get a map of versions to source paths.
Expand Down Expand Up @@ -218,8 +218,8 @@ def enrich_error(self, err: ContractLogicError) -> ContractLogicError:

@raises_not_implemented
def trace_source( # type: ignore[empty-body]
self, contract_source: ContractSource, trace: TraceAPI, calldata: HexBytes
) -> SourceTraceback:
self, contract_source: "ContractSource", trace: "TraceAPI", calldata: "HexBytes"
) -> "SourceTraceback":
"""
Get a source-traceback for the given contract type.
The source traceback object contains all the control paths taken in the transaction.
Expand All @@ -239,7 +239,7 @@ def trace_source( # type: ignore[empty-body]
@raises_not_implemented
def flatten_contract( # type: ignore[empty-body]
self, path: Path, project: Optional["ProjectManager"] = None, **kwargs
) -> Content:
) -> "Content":
"""
Get the content of a flattened contract via its source path.
Plugin implementations handle import resolution, SPDX de-duplication,
Expand All @@ -259,7 +259,7 @@ def flatten_contract( # type: ignore[empty-body]

@raises_not_implemented
def init_coverage_profile(
self, source_coverage: ContractSourceCoverage, contract_source: ContractSource
self, source_coverage: "ContractSourceCoverage", contract_source: "ContractSource"
): # type: ignore[empty-body]
"""
Initialize an empty report for the given source ID. Modifies the given source
Expand Down
16 changes: 9 additions & 7 deletions src/ape/api/explorers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from abc import abstractmethod
from typing import Optional

from ethpm_types import ContractType
from typing import TYPE_CHECKING, Optional

from ape.api.networks import NetworkAPI
from ape.types.address import AddressType
from ape.utils.basemodel import BaseInterfaceModel

if TYPE_CHECKING:
from ethpm_types import ContractType

from ape.types.address import AddressType


class ExplorerAPI(BaseInterfaceModel):
"""
Expand All @@ -18,7 +20,7 @@ class ExplorerAPI(BaseInterfaceModel):
network: NetworkAPI

@abstractmethod
def get_address_url(self, address: AddressType) -> str:
def get_address_url(self, address: "AddressType") -> str:
"""
Get an address URL, such as for a transaction.
Expand All @@ -42,7 +44,7 @@ def get_transaction_url(self, transaction_hash: str) -> str:
"""

@abstractmethod
def get_contract_type(self, address: AddressType) -> Optional[ContractType]:
def get_contract_type(self, address: "AddressType") -> Optional["ContractType"]:
"""
Get the contract type for a given address if it has been published to this explorer.
Expand All @@ -54,7 +56,7 @@ def get_contract_type(self, address: AddressType) -> Optional[ContractType]:
"""

@abstractmethod
def publish_contract(self, address: AddressType):
def publish_contract(self, address: "AddressType"):
"""
Publish a contract to the explorer.
Expand Down
Loading

0 comments on commit e301fdf

Please sign in to comment.