Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,13 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- uses: astral-sh/setup-uv@v1
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[release]

run: uv pip install -e '.[release]'
- name: Install Build Tool
run: uv pip install build
- name: Build
run: python setup.py sdist bdist_wheel

run: python -m build
- name: Publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
Expand Down
45 changes: 9 additions & 36 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,9 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- uses: astral-sh/setup-uv@v1
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install .[lint]

run: uv pip install -e '.[lint]'
- name: Run Ruff Format
run: ruff format --check .

Expand All @@ -40,17 +32,9 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- uses: astral-sh/setup-uv@v1
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install .[lint,test]

run: uv pip install -e '.[lint,test]'
- name: Run MyPy
run: mypy . --exclude build/ # For some reason, this gets caught sometimes

Expand All @@ -60,20 +44,15 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14-dev"]

steps:
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install .[test]
run: uv pip install -e '.[test]'

- name: Run Tests
run: pytest -m "not fuzzing" -n 0 -s --cov
Expand All @@ -87,14 +66,8 @@ jobs:
#
# steps:
# - uses: actions/checkout@v4
#
# - name: Setup Python
# uses: actions/setup-python@v5
# with:
# python-version: "3.10"
#
# - uses: astral-sh/setup-uv@v1
# - name: Install Dependencies
# run: pip install .[test]
#
# run: uv pip install -e '.[test]'
# - name: Run Tests
# run: pytest -m "fuzzing" --no-cov -s
47 changes: 21 additions & 26 deletions ethpm_types/abi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Any, Literal, Optional, Union
from typing import Any, Literal

from eth_abi import grammar
from eth_abi.packed import encode_packed
Expand All @@ -10,29 +10,26 @@
from ethpm_types.base import BaseModel
from ethpm_types.utils import parse_signature

if TYPE_CHECKING:
from typing_extensions import Self


class ABIType(BaseModel):
name: Optional[str] = None
name: str | None = None
"""
The name attached to the type, such as the input name of
a function.
"""

type: Union[str, "ABIType"]
type: "str | ABIType"
"""
The value-type, such as ``address`` or ``address[]``.
"""

components: Optional[list["ABIType"]] = None
components: "list[ABIType] | None" = None
Comment thread
fubuloubu marked this conversation as resolved.
Outdated
"""
A field of sub-types that makes up this type.
Tuples and structs tend to have this field.
"""

internal_type: Optional[str] = Field(default=None, alias="internalType")
internal_type: str | None = Field(default=None, alias="internalType")
"""
Another name for the type. Sometimes, compilers are able to populate
this field with the struct or enum name.
Expand Down Expand Up @@ -304,7 +301,7 @@ def signature(self) -> str:
return f"{self.name}({input_args}){output_args}"

@classmethod
def from_signature(cls, sig: str) -> "Self":
def from_signature(cls, sig: str) -> "MethodABI":
"""
Create an MethodABI instance from a method signature.

Expand Down Expand Up @@ -356,7 +353,7 @@ def signature(self) -> str:
return f"{self.name}({input_args})"

@classmethod
def from_signature(cls, sig: str) -> "Self":
def from_signature(cls, sig: str) -> "EventABI":
"""Create an EventABI instance from an event signature."""
name, inputs, _ = parse_signature(sig)
input_abis = [
Expand All @@ -365,7 +362,7 @@ def from_signature(cls, sig: str) -> "Self":
]
return cls(name=name, inputs=input_abis)

def encode_topics(self, inputs: dict[str, Any]) -> list[Union[Optional[str], list[str]]]:
def encode_topics(self, inputs: dict[str, Any]) -> list[str | list[str] | None]:
"""
Encode the given input data into a topics list, useful for log-filtering.
Missing topics correspond to None values in the returns list, which work
Expand All @@ -377,9 +374,7 @@ def encode_topics(self, inputs: dict[str, Any]) -> list[Union[Optional[str], lis
Returns:
list[Optional[str]]: Encoded topics.
"""
topics: list[Union[Optional[str], list[str]]] = [
str(to_hex(HexBytes(keccak(text=self.selector))))
]
topics: list[str | list[str] | None] = [str(to_hex(HexBytes(keccak(text=self.selector))))]
for ipt in self.inputs:
if not ipt.indexed:
continue
Expand All @@ -399,7 +394,7 @@ def encode_topics(self, inputs: dict[str, Any]) -> list[Union[Optional[str], lis
return topics


def encode_topic_value(abi_type, value) -> Union[Optional[str], list[str]]:
def encode_topic_value(abi_type, value) -> str | list[str] | None:
"""
Encode a single topic.

Expand Down Expand Up @@ -427,7 +422,7 @@ def encode_topic_value(abi_type, value) -> Union[Optional[str], list[str]]:
return HexStr32.__eth_pydantic_validate__(value, pad=PadDirection.LEFT)


def is_dynamic_sized_type(abi_type: Union[ABIType, str]) -> bool:
def is_dynamic_sized_type(abi_type: ABIType | str) -> bool:
parsed = grammar.parse(str(abi_type))
return parsed.is_dynamic

Expand Down Expand Up @@ -524,13 +519,13 @@ def signature(self) -> str:
return self.model_dump_json()


ABI = Union[
ConstructorABI,
FallbackABI,
ReceiveABI,
MethodABI,
EventABI,
ErrorABI,
StructABI,
UnprocessedABI,
]
ABI = (
ConstructorABI
| FallbackABI
| ReceiveABI
| MethodABI
| EventABI
| ErrorABI
| StructABI
| UnprocessedABI
)
23 changes: 11 additions & 12 deletions ethpm_types/ast.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections.abc import Iterator
from enum import Enum
from typing import Optional, Union

from pydantic import model_validator

Expand All @@ -18,7 +17,7 @@ class ASTClassification(Enum):


class ASTNode(BaseModel):
name: Optional[str] = None
name: str | None = None
"""
The node's name if it has one, such as a function name.
"""
Expand All @@ -33,7 +32,7 @@ class ASTNode(BaseModel):
A generic classification of what type of AST this is.
"""

doc_str: Optional[Union[str, "ASTNode"]] = None
doc_str: "str | ASTNode | None" = None
"""
Documentation for the node.
"""
Expand Down Expand Up @@ -63,7 +62,7 @@ class ASTNode(BaseModel):
The offset when the column ends.
"""

children: list["ASTNode"] = []
children: "list[ASTNode]" = []
Comment thread
fubuloubu marked this conversation as resolved.
Outdated
"""
All sub-AST nodes within this one.
"""
Expand Down Expand Up @@ -98,7 +97,7 @@ def _validate_src(cls, val: dict) -> SourceMapItem:
return src

@classmethod
def find_children(cls, node) -> list["ASTNode"]:
def find_children(cls, node) -> "list[ASTNode]":
Comment thread
fubuloubu marked this conversation as resolved.
Outdated
children = []

def add_child(data):
Expand All @@ -118,7 +117,7 @@ def add_child(data):
return children

@property
def line_numbers(self) -> "SourceLocation":
def line_numbers(self) -> SourceLocation:
"""
The values needed for constructing the line numbers for this node
in the form ``[lineno, col_offset, end_lineno, end_col_offset]``.
Expand All @@ -127,7 +126,7 @@ def line_numbers(self) -> "SourceLocation":
return self.lineno, self.col_offset, self.end_lineno, self.end_col_offset

@property
def functions(self) -> list["ASTNode"]:
def functions(self) -> "list[ASTNode]":
Comment thread
fubuloubu marked this conversation as resolved.
Outdated
"""
All function nodes defined at this level.

Expand All @@ -144,7 +143,7 @@ def __str__(self):
stats = "leaf" if num_children == 0 else f"children={num_children}"
return f"<{self.ast_type}Node {stats}>"

def iter_nodes(self) -> Iterator["ASTNode"]:
def iter_nodes(self) -> "Iterator[ASTNode]":
Comment thread
fubuloubu marked this conversation as resolved.
Outdated
"""
Yield through all nodes in the tree, including this one.
"""
Expand All @@ -153,7 +152,7 @@ def iter_nodes(self) -> Iterator["ASTNode"]:
for node in self.children:
yield from node.iter_nodes()

def get_node(self, src: SourceMapItem) -> Optional["ASTNode"]:
def get_node(self, src: SourceMapItem) -> "ASTNode | None":
"""
Get a node by source.

Expand All @@ -174,7 +173,7 @@ def get_node(self, src: SourceMapItem) -> Optional["ASTNode"]:

return None

def get_nodes_at_line(self, line_numbers: "SourceLocation") -> list["ASTNode"]:
def get_nodes_at_line(self, line_numbers: "SourceLocation") -> "list[ASTNode]":
Comment thread
fubuloubu marked this conversation as resolved.
Outdated
"""
Get the AST nodes for the given line number combination

Expand All @@ -193,7 +192,7 @@ def get_nodes_at_line(self, line_numbers: "SourceLocation") -> list["ASTNode"]:
"`(lineno, col_offset, end_lineno, end_coloffset)`"
)

if all(x == y for x, y in zip(self.line_numbers, line_numbers)):
if all(x == y for x, y in zip(self.line_numbers, line_numbers, strict=False)):
Comment thread
fubuloubu marked this conversation as resolved.
nodes.append(self)

for child in self.children:
Expand All @@ -202,7 +201,7 @@ def get_nodes_at_line(self, line_numbers: "SourceLocation") -> list["ASTNode"]:

return nodes

def get_defining_function(self, line_numbers: "SourceLocation") -> Optional["ASTNode"]:
def get_defining_function(self, line_numbers: "SourceLocation") -> "ASTNode | None":
"""
Get the function that defines the given line numbers.

Expand Down
Loading
Loading