Skip to content

Commit

Permalink
feat!: py3.8 drop and py3.12 support add (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Jun 4, 2024
1 parent 0ea9cef commit 6b7ad5d
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 65 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/commitlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

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

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/prtitle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

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

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

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

Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

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

Expand All @@ -42,10 +42,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

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

Expand All @@ -63,13 +63,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest] # eventually add `windows-latest`
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
python-version: [3.9, "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -89,10 +89,10 @@ jobs:
# fail-fast: true
#
# steps:
# - uses: actions/checkout@v2
# - uses: actions/checkout@v4
#
# - name: Setup Python
# uses: actions/setup-python@v2
# uses: actions/setup-python@v5
# with:
# python-version: "3.10"
#
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 23.11.0
rev: 24.3.0
hooks:
- id: black
name: black

- repo: https://github.com/pycqa/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
rev: v1.9.0
hooks:
- id: mypy
additional_dependencies: [types-PyYAML, types-requests, types-setuptools, pydantic]
Expand Down
4 changes: 2 additions & 2 deletions evm_trace/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from functools import cached_property, singledispatchmethod
from typing import List, Optional
from typing import Optional

from eth_pydantic_types import HexBytes
from pydantic import BaseModel as _BaseModel
Expand Down Expand Up @@ -50,7 +50,7 @@ class CallTreeNode(BaseModel):
returndata: HexBytes = HexBytes("")
"""Transaction returndata (outputs)."""

calls: List["CallTreeNode"] = []
calls: list["CallTreeNode"] = []
"""The list of external sub-calls this call makes."""

selfdestruct: bool = False
Expand Down
3 changes: 2 additions & 1 deletion evm_trace/display.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import TYPE_CHECKING, Iterator, Optional, cast
from collections.abc import Iterator
from typing import TYPE_CHECKING, Optional, cast

from eth_typing import ChecksumAddress
from eth_utils import to_checksum_address
Expand Down
4 changes: 2 additions & 2 deletions evm_trace/gas.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import copy
from typing import Dict, List, TypeVar
from typing import TypeVar

from evm_trace.base import CallTreeNode

ContractID = TypeVar("ContractID")
MethodID = TypeVar("MethodID")
GasReport = Dict[ContractID, Dict[MethodID, List[int]]]
GasReport = dict[ContractID, dict[MethodID, list[int]]]


def get_gas_report(calltree: CallTreeNode) -> GasReport:
Expand Down
25 changes: 13 additions & 12 deletions evm_trace/geth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import math
from typing import Dict, Iterator, List, Optional
from collections.abc import Iterator
from typing import Optional

from eth_pydantic_types import HashBytes20, HexBytes
from eth_utils import to_int
Expand All @@ -9,8 +10,8 @@
from evm_trace.enums import CALL_OPCODES, CallType


class TraceMemory(RootModel[List[HexBytes]]):
root: List[HexBytes] = []
class TraceMemory(RootModel[list[HexBytes]]):
root: list[HexBytes] = []

def get(self, offset: HexBytes, size: HexBytes):
return extract_memory(offset, size, self.root)
Expand Down Expand Up @@ -39,13 +40,13 @@ class TraceFrame(BaseModel):
The number of external jumps away the initially called contract (starts at 0).
"""

stack: List[HexBytes] = []
stack: list[HexBytes] = []
"""Execution stack."""

memory: TraceMemory = TraceMemory()
"""Execution memory."""

storage: Dict[HexBytes, HexBytes] = {}
storage: dict[HexBytes, HexBytes] = {}
"""Contract storage."""

contract_address: Optional[HashBytes20] = None
Expand All @@ -70,7 +71,7 @@ def address(self) -> Optional[HashBytes20]:
return self.contract_address


def create_trace_frames(data: Iterator[Dict]) -> Iterator[TraceFrame]:
def create_trace_frames(data: Iterator[dict]) -> Iterator[TraceFrame]:
"""
Get trace frames from ``debug_traceTransaction`` response items.
Sets the ``contract_address`` for CREATE and CREATE2 frames by
Expand Down Expand Up @@ -99,7 +100,7 @@ def create_trace_frames(data: Iterator[Dict]) -> Iterator[TraceFrame]:
yield TraceFrame(**frame)


def _get_create_frames(frame: TraceFrame, frames: Iterator[Dict]) -> List[TraceFrame]:
def _get_create_frames(frame: TraceFrame, frames: Iterator[dict]) -> list[TraceFrame]:
create_frames = [frame]
start_depth = frame.depth
for next_frame in frames:
Expand All @@ -126,7 +127,7 @@ def _get_create_frames(frame: TraceFrame, frames: Iterator[Dict]) -> List[TraceF
return create_frames


def get_calltree_from_geth_call_trace(data: Dict) -> CallTreeNode:
def get_calltree_from_geth_call_trace(data: dict) -> CallTreeNode:
"""
Creates a CallTreeNode from a given transaction call trace.
Expand Down Expand Up @@ -173,7 +174,7 @@ def get_calltree_from_geth_trace(
)


def create_call_node_data(frame: TraceFrame) -> Dict:
def create_call_node_data(frame: TraceFrame) -> dict:
"""
Parse a CALL-opcode frame into an address and calldata.
Expand All @@ -184,7 +185,7 @@ def create_call_node_data(frame: TraceFrame) -> Dict:
Tuple[str, HexBytes]: A tuple of the address str and the calldata.
"""

data: Dict = {"address": frame.address, "depth": frame.depth}
data: dict = {"address": frame.address, "depth": frame.depth}
if frame.op == CallType.CALL.value:
data["call_type"] = CallType.CALL
data["value"] = int(frame.stack[-3].hex(), 16)
Expand All @@ -208,7 +209,7 @@ def create_call_node_data(frame: TraceFrame) -> Dict:
return data


def extract_memory(offset: HexBytes, size: HexBytes, memory: List[HexBytes]) -> HexBytes:
def extract_memory(offset: HexBytes, size: HexBytes, memory: list[HexBytes]) -> HexBytes:
"""
Extracts memory from the EVM stack.
Expand Down Expand Up @@ -333,7 +334,7 @@ def _create_node(
return node


def _validate_data_from_call_tracer(data: Dict) -> Dict:
def _validate_data_from_call_tracer(data: dict) -> dict:
# Handle renames
if "receiver" in data:
data["address"] = data.pop("receiver")
Expand Down
12 changes: 6 additions & 6 deletions evm_trace/parity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Union, cast
from typing import Any, Optional, Union, cast

from pydantic import Field, RootModel, field_validator

Expand Down Expand Up @@ -93,7 +93,7 @@ class ParityTrace(BaseModel):
call_type: CallType = Field(alias="type")
result: Optional[ParityTraceResult] = None
subtraces: int
trace_address: List[int] = Field(alias="traceAddress")
trace_address: list[int] = Field(alias="traceAddress")
transaction_hash: str = Field(alias="transactionHash")

@field_validator("call_type", mode="before")
Expand All @@ -108,7 +108,7 @@ def convert_call_type(cls, value, info) -> CallType:
return CallType(value)


ParityTraceList = RootModel[List[ParityTrace]]
ParityTraceList = RootModel[list[ParityTrace]]


def get_calltree_from_parity_trace(
Expand All @@ -133,7 +133,7 @@ def get_calltree_from_parity_trace(
"""
root = root or traces.root[0]
failed = root.error is not None
node_kwargs: Dict[Any, Any] = {
node_kwargs: dict[Any, Any] = {
"call_type": root.call_type,
"failed": failed,
}
Expand Down Expand Up @@ -181,8 +181,8 @@ def get_calltree_from_parity_trace(
address=selfdestruct_action.address,
)

trace_list: List[ParityTrace] = traces.root
subtraces: List[ParityTrace] = [
trace_list: list[ParityTrace] = traces.root
subtraces: list[ParityTrace] = [
sub
for sub in trace_list
if len(sub.trace_address) == len(root.trace_address) + 1
Expand Down
35 changes: 18 additions & 17 deletions evm_trace/vmtrace.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Any, Dict, Iterator, List, Optional, Type, Union
from collections.abc import Iterator
from typing import Any

from eth.vm.memory import Memory
from eth.vm.stack import Stack
Expand Down Expand Up @@ -33,7 +34,7 @@ class uint256(int):
class VMTrace(Struct):
code: HexBytes
"""The code to be executed."""
ops: List[VMOperation]
ops: list[VMOperation]
"""The operations executed."""


Expand All @@ -42,9 +43,9 @@ class VMOperation(Struct):
"""The program counter."""
cost: int
"""The gas cost for this instruction."""
ex: Optional[VMExecutedOperation]
ex: VMExecutedOperation | None
"""Information concerning the execution of the operation."""
sub: Optional[VMTrace]
sub: VMTrace | None
"""Subordinate trace of the CALL/CREATE if applicable."""
op: str
"""Opcode that is being called."""
Expand All @@ -55,11 +56,11 @@ class VMOperation(Struct):
class VMExecutedOperation(Struct):
used: int
"""The amount of remaining gas."""
push: List[HexBytes]
push: list[HexBytes]
"""The stack item placed, if any."""
mem: Optional[MemoryDiff]
mem: MemoryDiff | None
"""If altered, the memory delta."""
store: Optional[StorageDiff]
store: StorageDiff | None
"""The altered storage value, if any."""


Expand All @@ -86,9 +87,9 @@ class VMTraceFrame(Struct):
pc: int
op: str
depth: int
stack: List[int]
memory: Union[bytes, memoryview]
storage: Dict[int, int]
stack: list[int]
memory: bytes | memoryview
storage: dict[int, int]


def to_trace_frames(
Expand Down Expand Up @@ -119,7 +120,7 @@ def to_trace_frames(
"""
memory = Memory()
stack = Stack()
storage: Dict[int, int] = {}
storage: dict[int, int] = {}
call_address = ""
read_memory = memory.read_bytes if copy_memory else memory.read

Expand Down Expand Up @@ -166,26 +167,26 @@ def to_trace_frames(


class RPCResponse(Struct):
result: Union[RPCTraceResult, List[RPCTraceResult]]
result: RPCTraceResult | list[RPCTraceResult]


class RPCTraceResult(Struct):
trace: Optional[List]
trace: list | None
vmTrace: VMTrace
stateDiff: Optional[Dict]
stateDiff: dict | None


def dec_hook(type: Type, obj: Any) -> Any:
def dec_hook(type: type, obj: Any) -> Any:
if type is uint256:
return uint256(obj, 16)
elif type is HexBytes:
return HexBytes(obj)


def from_rpc_response(buffer: bytes) -> Union[VMTrace, List[VMTrace]]:
def from_rpc_response(buffer: bytes) -> VMTrace | list[VMTrace]:
"""
Decode structured data from a raw `trace_replayTransaction` or `trace_replayBlockTransactions`.
"""
response = Decoder(RPCResponse, dec_hook=dec_hook).decode(buffer)
result: Union[List[RPCTraceResult], RPCTraceResult] = response.result
result: list[RPCTraceResult] | RPCTraceResult = response.result
return [i.vmTrace for i in result] if isinstance(result, list) else result.vmTrace
Loading

0 comments on commit 6b7ad5d

Please sign in to comment.