Skip to content

Enforce all execution-specs mypy rules #1477

@marioevz

Description

@marioevz

Before welding, we need to sync mypy configuration and fix all resulting errors in this repository.

This means adding the following lines to the [tool.mypy] section in the pyproject.toml file:

disallow_incomplete_defs = true  # 1349 new errors
disallow_untyped_defs = true  # 1850 new errors

(edit felix: I removed the ones we fixed already above.)

without the comments.

List of errors per subfolder:

  • tests/unscheduled (408 errors)
  • src/pytest_plugins (395 errors)
  • tests/prague (206 errors)
  • tests/cancun (137 errors)
  • src/cli (98 errors)
  • src/ethereum_test_types (86 errors)
  • src/ethereum_test_specs (84 errors)
  • tests/benchmark (83 errors)
  • tests/osaka (77 errors)
  • tests/amsterdam (49 errors)
  • src/ethereum_test_fixtures (49 errors)
  • src/ethereum_test_base_types (48 errors)
  • src/ethereum_clis (46 errors)
  • src/ethereum_test_tools (31 errors)
  • tests/shanghai (28 errors)
  • tests/frontier (28 errors)
  • src/ethereum_test_forks (28 errors)
  • src/ethereum_test_vm (15 errors)
  • src/ethereum_test_rpc (12 errors)
  • src/ethereum_test_checklists (9 errors)
  • tests/istanbul (7 errors)
  • tests/constantinople (5 errors)
  • tests/berlin (5 errors)
  • src/ethereum_test_exceptions (5 errors)
  • src/ethereum_test_execution (4 errors)
  • .github/scripts (4 errors)
  • tests/homestead (3 errors)
  • tests/byzantium (2 errors)
  • tests/paris (1 errors)
  • src/config (1 errors)

Errors by type:

Function is missing a return type annotation [no-untyped-def] (1451 errors)

Example:

def compile_yul(source_file: str, evm_version: str | None = None, optimize: str | None = None):
    """
    Compiles a Yul source file using solc and returns the binary
    representation.
    """

Fix:

def compile_yul(
    source_file: str, evm_version: str | None = None, optimize: str | None = None
) -> str:
    """
    Compiles a Yul source file using solc and returns the binary
    representation.
    """

Function is missing a type annotation [no-untyped-def] (266 errors)

Example:

@dataclass(frozen=True)
class PointG1(BytesConcatenation):
    """Dataclass that defines a single point in G1."""

    x: int = 0
    y: int = 0

    def __bytes__(self) -> bytes:
        """Convert point to bytes."""
        return self.x.to_bytes(64, byteorder="big") + self.y.to_bytes(64, byteorder="big")

    def __neg__(self):  # <------ Issue
        """Negates the point."""
        return PointG1(self.x, Spec.P - self.y)

Fix

@dataclass(frozen=True)
class PointG1(BytesConcatenation):
    """Dataclass that defines a single point in G1."""

    x: int = 0
    y: int = 0

    def __bytes__(self) -> bytes:
        """Convert point to bytes."""
        return self.x.to_bytes(64, byteorder="big") + self.y.to_bytes(64, byteorder="big")

    def __neg__(self) -> "PointG1":
        """Negates the point."""
        return PointG1(self.x, Spec.P - self.y)

Function is missing a type annotation for one or more arguments [no-untyped-def] (168 errors)

Example:

    def __eq__(self, value) -> bool:  # <----- issue
        """
        Check if the release descriptor matches the string value.

        Returns True if the value is the same as the tag name or the tag name
        and version.
        """

Fix:

    def __eq__(self, value: object) -> bool:
        """
        Check if the release descriptor matches the string value.

        Returns True if the value is the same as the tag name or the tag name
        and version.
        """

Unused "type: ignore" comment [unused-ignore] (62 errors)

Example:

def parse_release_information(release_information: List) -> List[ReleaseInformation]:
    """Parse the release information from the Github API."""
    return Releases.model_validate(release_information).root  # type: ignore

Fix:

def parse_release_information(release_information: List) -> List[ReleaseInformation]:
    """Parse the release information from the Github API."""
    return Releases.model_validate(release_information).root

Unused "type: ignore" comment, use narrower [prop-decorator] instead of [misc] code [unused-ignore] (3 errors)

Example:

    @computed_field  # type: ignore[misc]
    @cached_property
    def parent_hash(self) -> Hash | None:
        """
        Obtains the latest hash according to the highest block number in
        `block_hashes`.
        """
        if len(self.block_hashes) == 0:
            return None

        last_index = max(self.block_hashes.keys())
        return Hash(self.block_hashes[last_index])

Fix:

    @computed_field  # type: ignore[prop-decorator]
    @cached_property
    def parent_hash(self) -> Hash | None:
        """
        Obtains the latest hash according to the highest block number in
        `block_hashes`.
        """
        if len(self.block_hashes) == 0:
            return None

        last_index = max(self.block_hashes.keys())
        return Hash(self.block_hashes[last_index])

"bytes" has no attribute "pop" [attr-defined] (2 errors)

Example:

def process_evm_bytes(evm_bytes: bytes) -> List[OpcodeWithOperands]:  # noqa: D103
    evm_bytes = bytearray(evm_bytes)

    opcodes: List[OpcodeWithOperands] = []

    while evm_bytes:
        opcode_byte = evm_bytes.pop(0)

Fix:

def process_evm_bytes(evm_bytes: bytes) -> List[OpcodeWithOperands]:  # noqa: D103
    evm_bytes_array = bytearray(evm_bytes)

    opcodes: List[OpcodeWithOperands] = []

    while evm_bytes_array:
        opcode_byte = evm_bytes_array.pop(0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions