Skip to content

1176 - Initial python/pypy 3.11 refactors #1179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions src/ethereum/arrow_glacier/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
chain.
"""
from dataclasses import dataclass
from typing import Tuple, Union
from typing import Tuple

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes, Bytes8, Bytes32
Expand Down Expand Up @@ -59,7 +59,7 @@ class Block:
"""

header: Header
transactions: Tuple[Union[Bytes, LegacyTransaction], ...]
transactions: Tuple[Bytes | LegacyTransaction, ...]
ommers: Tuple[Header, ...]


Expand Down Expand Up @@ -88,7 +88,7 @@ class Receipt:
logs: Tuple[Log, ...]


def encode_receipt(tx: Transaction, receipt: Receipt) -> Union[Bytes, Receipt]:
def encode_receipt(tx: Transaction, receipt: Receipt) -> Bytes | Receipt:
"""
Encodes a receipt.
"""
Expand All @@ -100,7 +100,7 @@ def encode_receipt(tx: Transaction, receipt: Receipt) -> Union[Bytes, Receipt]:
return receipt


def decode_receipt(receipt: Union[Bytes, Receipt]) -> Receipt:
def decode_receipt(receipt: Bytes | Receipt) -> Receipt:
"""
Decodes a receipt.
"""
Expand Down
6 changes: 3 additions & 3 deletions src/ethereum/arrow_glacier/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"""

from dataclasses import dataclass
from typing import List, Optional, Set, Tuple, Union
from typing import List, Optional, Set, Tuple

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes
Expand Down Expand Up @@ -482,7 +482,7 @@ def make_receipt(
error: Optional[EthereumException],
cumulative_gas_used: Uint,
logs: Tuple[Log, ...],
) -> Union[Bytes, Receipt]:
) -> Bytes | Receipt:
"""
Make the receipt for a transaction that was executed.

Expand Down Expand Up @@ -515,7 +515,7 @@ def make_receipt(

def apply_body(
block_env: vm.BlockEnvironment,
transactions: Tuple[Union[LegacyTransaction, Bytes], ...],
transactions: Tuple[LegacyTransaction | Bytes, ...],
ommers: Tuple[Header, ...],
) -> vm.BlockOutput:
"""
Expand Down
18 changes: 8 additions & 10 deletions src/ethereum/arrow_glacier/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
transactions are the events that move between states.
"""
from dataclasses import dataclass
from typing import Tuple, Union
from typing import Tuple

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes, Bytes0, Bytes32
Expand Down Expand Up @@ -36,7 +36,7 @@ class LegacyTransaction:
nonce: U256
gas_price: Uint
gas: Uint
to: Union[Bytes0, Address]
to: Bytes0 | Address
value: U256
data: Bytes
v: U256
Expand Down Expand Up @@ -67,7 +67,7 @@ class AccessListTransaction:
nonce: U256
gas_price: Uint
gas: Uint
to: Union[Bytes0, Address]
to: Bytes0 | Address
value: U256
data: Bytes
access_list: Tuple[Access, ...]
Expand All @@ -88,7 +88,7 @@ class FeeMarketTransaction:
max_priority_fee_per_gas: Uint
max_fee_per_gas: Uint
gas: Uint
to: Union[Bytes0, Address]
to: Bytes0 | Address
value: U256
data: Bytes
access_list: Tuple[Access, ...]
Expand All @@ -97,12 +97,10 @@ class FeeMarketTransaction:
s: U256


Transaction = Union[
LegacyTransaction, AccessListTransaction, FeeMarketTransaction
]
Transaction = LegacyTransaction | AccessListTransaction | FeeMarketTransaction


def encode_transaction(tx: Transaction) -> Union[LegacyTransaction, Bytes]:
def encode_transaction(tx: Transaction) -> LegacyTransaction | Bytes:
"""
Encode a transaction. Needed because non-legacy transactions aren't RLP.
"""
Expand All @@ -116,7 +114,7 @@ def encode_transaction(tx: Transaction) -> Union[LegacyTransaction, Bytes]:
raise Exception(f"Unable to encode transaction of type {type(tx)}")


def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
def decode_transaction(tx: LegacyTransaction | Bytes) -> Transaction:
"""
Decode a transaction. Needed because non-legacy transactions aren't RLP.
"""
Expand Down Expand Up @@ -400,7 +398,7 @@ def signing_hash_1559(tx: FeeMarketTransaction) -> Hash32:
)


def get_transaction_hash(tx: Union[Bytes, LegacyTransaction]) -> Hash32:
def get_transaction_hash(tx: Bytes | LegacyTransaction) -> Hash32:
"""
Parameters
----------
Expand Down
11 changes: 5 additions & 6 deletions src/ethereum/arrow_glacier/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
Sequence,
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

from ethereum_rlp import Extended, rlp
from ethereum_types.bytes import Bytes
from ethereum_types.frozen import slotted_freezable
from ethereum_types.numeric import U256, Uint
from typing_extensions import assert_type

from ethereum.crypto.hash import keccak256
from ethereum.london import trie as previous_trie
Expand Down Expand Up @@ -63,15 +62,15 @@
)
)

Node = Union[Account, Bytes, LegacyTransaction, Receipt, Uint, U256, None]
Node = Account | Bytes | LegacyTransaction | Receipt | Uint | U256 | None
K = TypeVar("K", bound=Bytes)
V = TypeVar(
"V",
Optional[Account],
Optional[Bytes],
Bytes,
Optional[Union[LegacyTransaction, Bytes]],
Optional[Union[Receipt, Bytes]],
Optional[LegacyTransaction | Bytes],
Optional[Receipt | Bytes],
Uint,
U256,
)
Expand Down Expand Up @@ -124,7 +123,7 @@ class BranchNode:
value: Extended


InternalNode = Union[LeafNode, ExtensionNode, BranchNode]
InternalNode = LeafNode | ExtensionNode | BranchNode


def encode_internal_node(node: Optional[InternalNode]) -> Extended:
Expand Down
4 changes: 1 addition & 3 deletions src/ethereum/arrow_glacier/utils/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
Address specific functions used in this arrow_glacier version of
specification.
"""
from typing import Union

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes32
from ethereum_types.numeric import U256, Uint
Expand All @@ -24,7 +22,7 @@
from ..fork_types import Address


def to_address(data: Union[Uint, U256]) -> Address:
def to_address(data: Uint | U256) -> Address:
"""
Convert a Uint or U256 value to a valid address (20 bytes).

Expand Down
8 changes: 4 additions & 4 deletions src/ethereum/arrow_glacier/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""

from dataclasses import dataclass, field
from typing import List, Optional, Set, Tuple, Union
from typing import List, Optional, Set, Tuple

from ethereum_types.bytes import Bytes, Bytes0, Bytes32
from ethereum_types.numeric import U64, U256, Uint
Expand Down Expand Up @@ -71,9 +71,9 @@ class BlockOutput:

block_gas_used: Uint = Uint(0)
transactions_trie: Trie[
Bytes, Optional[Union[Bytes, LegacyTransaction]]
Bytes, Optional[Bytes | LegacyTransaction]
] = field(default_factory=lambda: Trie(secured=False, default=None))
receipts_trie: Trie[Bytes, Optional[Union[Bytes, Receipt]]] = field(
receipts_trie: Trie[Bytes, Optional[Bytes | Receipt]] = field(
default_factory=lambda: Trie(secured=False, default=None)
)
receipt_keys: Tuple[Bytes, ...] = field(default_factory=tuple)
Expand Down Expand Up @@ -105,7 +105,7 @@ class Message:
block_env: BlockEnvironment
tx_env: TransactionEnvironment
caller: Address
target: Union[Bytes0, Address]
target: Bytes0 | Address
current_target: Address
gas: Uint
value: U256
Expand Down
8 changes: 4 additions & 4 deletions src/ethereum/berlin/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
chain.
"""
from dataclasses import dataclass
from typing import Tuple, Union
from typing import Tuple

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes, Bytes8, Bytes32
Expand Down Expand Up @@ -53,7 +53,7 @@ class Block:
"""

header: Header
transactions: Tuple[Union[Bytes, LegacyTransaction], ...]
transactions: Tuple[Bytes | LegacyTransaction, ...]
ommers: Tuple[Header, ...]


Expand Down Expand Up @@ -82,7 +82,7 @@ class Receipt:
logs: Tuple[Log, ...]


def encode_receipt(tx: Transaction, receipt: Receipt) -> Union[Bytes, Receipt]:
def encode_receipt(tx: Transaction, receipt: Receipt) -> Bytes | Receipt:
"""
Encodes a receipt.
"""
Expand All @@ -92,7 +92,7 @@ def encode_receipt(tx: Transaction, receipt: Receipt) -> Union[Bytes, Receipt]:
return receipt


def decode_receipt(receipt: Union[Bytes, Receipt]) -> Receipt:
def decode_receipt(receipt: Bytes | Receipt) -> Receipt:
"""
Decodes a receipt.
"""
Expand Down
6 changes: 3 additions & 3 deletions src/ethereum/berlin/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Entry point for the Ethereum specification.
"""
from dataclasses import dataclass
from typing import List, Optional, Set, Tuple, Union
from typing import List, Optional, Set, Tuple

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes
Expand Down Expand Up @@ -389,7 +389,7 @@ def make_receipt(
error: Optional[EthereumException],
cumulative_gas_used: Uint,
logs: Tuple[Log, ...],
) -> Union[Bytes, Receipt]:
) -> Bytes | Receipt:
"""
Make the receipt for a transaction that was executed.

Expand Down Expand Up @@ -422,7 +422,7 @@ def make_receipt(

def apply_body(
block_env: vm.BlockEnvironment,
transactions: Tuple[Union[LegacyTransaction, Bytes], ...],
transactions: Tuple[LegacyTransaction | Bytes, ...],
ommers: Tuple[Header, ...],
) -> vm.BlockOutput:
"""
Expand Down
14 changes: 7 additions & 7 deletions src/ethereum/berlin/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
transactions are the events that move between states.
"""
from dataclasses import dataclass
from typing import Tuple, Union
from typing import Tuple

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes, Bytes0, Bytes32
Expand Down Expand Up @@ -36,7 +36,7 @@ class LegacyTransaction:
nonce: U256
gas_price: Uint
gas: Uint
to: Union[Bytes0, Address]
to: Bytes0 | Address
value: U256
data: Bytes
v: U256
Expand Down Expand Up @@ -67,7 +67,7 @@ class AccessListTransaction:
nonce: U256
gas_price: Uint
gas: Uint
to: Union[Bytes0, Address]
to: Bytes0 | Address
value: U256
data: Bytes
access_list: Tuple[Access, ...]
Expand All @@ -76,10 +76,10 @@ class AccessListTransaction:
s: U256


Transaction = Union[LegacyTransaction, AccessListTransaction]
Transaction = LegacyTransaction | AccessListTransaction


def encode_transaction(tx: Transaction) -> Union[LegacyTransaction, Bytes]:
def encode_transaction(tx: Transaction) -> LegacyTransaction | Bytes:
"""
Encode a transaction. Needed because non-legacy transactions aren't RLP.
"""
Expand All @@ -91,7 +91,7 @@ def encode_transaction(tx: Transaction) -> Union[LegacyTransaction, Bytes]:
raise Exception(f"Unable to encode transaction of type {type(tx)}")


def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
def decode_transaction(tx: LegacyTransaction | Bytes) -> Transaction:
"""
Decode a transaction. Needed because non-legacy transactions aren't RLP.
"""
Expand Down Expand Up @@ -334,7 +334,7 @@ def signing_hash_2930(tx: AccessListTransaction) -> Hash32:
)


def get_transaction_hash(tx: Union[Bytes, LegacyTransaction]) -> Hash32:
def get_transaction_hash(tx: Bytes | LegacyTransaction) -> Hash32:
"""
Parameters
----------
Expand Down
11 changes: 5 additions & 6 deletions src/ethereum/berlin/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
Sequence,
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

from ethereum_rlp import Extended, rlp
from ethereum_types.bytes import Bytes
from ethereum_types.frozen import slotted_freezable
from ethereum_types.numeric import U256, Uint
from typing_extensions import assert_type

from ethereum.crypto.hash import keccak256
from ethereum.muir_glacier import trie as previous_trie
Expand Down Expand Up @@ -63,15 +62,15 @@
)
)

Node = Union[Account, Bytes, LegacyTransaction, Receipt, Uint, U256, None]
Node = Account | Bytes | LegacyTransaction | Receipt | Uint | U256 | None
K = TypeVar("K", bound=Bytes)
V = TypeVar(
"V",
Optional[Account],
Optional[Bytes],
Bytes,
Optional[Union[LegacyTransaction, Bytes]],
Optional[Union[Receipt, Bytes]],
Optional[LegacyTransaction | Bytes],
Optional[Receipt | Bytes],
Uint,
U256,
)
Expand Down Expand Up @@ -124,7 +123,7 @@ class BranchNode:
value: Extended


InternalNode = Union[LeafNode, ExtensionNode, BranchNode]
InternalNode = LeafNode | ExtensionNode | BranchNode


def encode_internal_node(node: Optional[InternalNode]) -> Extended:
Expand Down
Loading