Skip to content

Commit 3778acd

Browse files
Carsons-Eelscodeofcarson
authored andcommitted
Python 3.11 refactors
- refactored assert_type import from typing_extensions to typing - refactored Union to use primitive type offered by 3.10
1 parent 4cc0d67 commit 3778acd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+316
-374
lines changed

Diff for: src/ethereum/arrow_glacier/blocks.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
chain.
1010
"""
1111
from dataclasses import dataclass
12-
from typing import Tuple, Union
12+
from typing import Tuple
1313

1414
from ethereum_rlp import rlp
1515
from ethereum_types.bytes import Bytes, Bytes8, Bytes32
@@ -59,7 +59,7 @@ class Block:
5959
"""
6060

6161
header: Header
62-
transactions: Tuple[Union[Bytes, LegacyTransaction], ...]
62+
transactions: Tuple[Bytes | LegacyTransaction, ...]
6363
ommers: Tuple[Header, ...]
6464

6565

@@ -88,7 +88,7 @@ class Receipt:
8888
logs: Tuple[Log, ...]
8989

9090

91-
def encode_receipt(tx: Transaction, receipt: Receipt) -> Union[Bytes, Receipt]:
91+
def encode_receipt(tx: Transaction, receipt: Receipt) -> Bytes | Receipt:
9292
"""
9393
Encodes a receipt.
9494
"""
@@ -100,7 +100,7 @@ def encode_receipt(tx: Transaction, receipt: Receipt) -> Union[Bytes, Receipt]:
100100
return receipt
101101

102102

103-
def decode_receipt(receipt: Union[Bytes, Receipt]) -> Receipt:
103+
def decode_receipt(receipt: Bytes | Receipt) -> Receipt:
104104
"""
105105
Decodes a receipt.
106106
"""

Diff for: src/ethereum/arrow_glacier/fork.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"""
1414

1515
from dataclasses import dataclass
16-
from typing import List, Optional, Set, Tuple, Union
16+
from typing import List, Optional, Set, Tuple
1717

1818
from ethereum_rlp import rlp
1919
from ethereum_types.bytes import Bytes
@@ -482,7 +482,7 @@ def make_receipt(
482482
error: Optional[EthereumException],
483483
cumulative_gas_used: Uint,
484484
logs: Tuple[Log, ...],
485-
) -> Union[Bytes, Receipt]:
485+
) -> Bytes | Receipt:
486486
"""
487487
Make the receipt for a transaction that was executed.
488488
@@ -515,7 +515,7 @@ def make_receipt(
515515

516516
def apply_body(
517517
block_env: vm.BlockEnvironment,
518-
transactions: Tuple[Union[LegacyTransaction, Bytes], ...],
518+
transactions: Tuple[LegacyTransaction | Bytes, ...],
519519
ommers: Tuple[Header, ...],
520520
) -> vm.BlockOutput:
521521
"""

Diff for: src/ethereum/arrow_glacier/transactions.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
transactions are the events that move between states.
55
"""
66
from dataclasses import dataclass
7-
from typing import Tuple, Union
7+
from typing import Tuple
88

99
from ethereum_rlp import rlp
1010
from ethereum_types.bytes import Bytes, Bytes0, Bytes32
@@ -36,7 +36,7 @@ class LegacyTransaction:
3636
nonce: U256
3737
gas_price: Uint
3838
gas: Uint
39-
to: Union[Bytes0, Address]
39+
to: Bytes0 | Address
4040
value: U256
4141
data: Bytes
4242
v: U256
@@ -55,7 +55,7 @@ class AccessListTransaction:
5555
nonce: U256
5656
gas_price: Uint
5757
gas: Uint
58-
to: Union[Bytes0, Address]
58+
to: Bytes0 | Address
5959
value: U256
6060
data: Bytes
6161
access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...]
@@ -76,7 +76,7 @@ class FeeMarketTransaction:
7676
max_priority_fee_per_gas: Uint
7777
max_fee_per_gas: Uint
7878
gas: Uint
79-
to: Union[Bytes0, Address]
79+
to: Bytes0 | Address
8080
value: U256
8181
data: Bytes
8282
access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...]
@@ -85,12 +85,10 @@ class FeeMarketTransaction:
8585
s: U256
8686

8787

88-
Transaction = Union[
89-
LegacyTransaction, AccessListTransaction, FeeMarketTransaction
90-
]
88+
Transaction = LegacyTransaction | AccessListTransaction | FeeMarketTransaction
9189

9290

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

106104

107-
def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
105+
def decode_transaction(tx: LegacyTransaction | Bytes) -> Transaction:
108106
"""
109107
Decode a transaction. Needed because non-legacy transactions aren't RLP.
110108
"""
@@ -382,7 +380,7 @@ def signing_hash_1559(tx: FeeMarketTransaction) -> Hash32:
382380
)
383381

384382

385-
def get_transaction_hash(tx: Union[Bytes, LegacyTransaction]) -> Hash32:
383+
def get_transaction_hash(tx: Bytes | LegacyTransaction) -> Hash32:
386384
"""
387385
Parameters
388386
----------

Diff for: src/ethereum/arrow_glacier/trie.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
Optional,
2626
Sequence,
2727
TypeVar,
28-
Union,
2928
)
3029

3130
from ethereum_rlp import rlp
@@ -60,15 +59,15 @@
6059
)
6160
)
6261

63-
Node = Union[Account, Bytes, LegacyTransaction, Receipt, Uint, U256, None]
62+
Node = Account | Bytes | LegacyTransaction | Receipt | Uint | U256 | None
6463
K = TypeVar("K", bound=Bytes)
6564
V = TypeVar(
6665
"V",
6766
Optional[Account],
6867
Optional[Bytes],
6968
Bytes,
70-
Optional[Union[LegacyTransaction, Bytes]],
71-
Optional[Union[Receipt, Bytes]],
69+
Optional[LegacyTransaction | Bytes],
70+
Optional[Receipt | Bytes],
7271
Uint,
7372
U256,
7473
)
@@ -101,7 +100,7 @@ class BranchNode:
101100
value: rlp.Extended
102101

103102

104-
InternalNode = Union[LeafNode, ExtensionNode, BranchNode]
103+
InternalNode = LeafNode | ExtensionNode | BranchNode
105104

106105

107106
def encode_internal_node(node: Optional[InternalNode]) -> rlp.Extended:

Diff for: src/ethereum/arrow_glacier/utils/address.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
Address specific functions used in this arrow_glacier version of
1313
specification.
1414
"""
15-
from typing import Union
16-
1715
from ethereum_rlp import rlp
1816
from ethereum_types.bytes import Bytes32
1917
from ethereum_types.numeric import U256, Uint
@@ -24,7 +22,7 @@
2422
from ..fork_types import Address
2523

2624

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

Diff for: src/ethereum/arrow_glacier/vm/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"""
1515

1616
from dataclasses import dataclass, field
17-
from typing import List, Optional, Set, Tuple, Union
17+
from typing import List, Optional, Set, Tuple
1818

1919
from ethereum_types.bytes import Bytes, Bytes0, Bytes32
2020
from ethereum_types.numeric import U64, U256, Uint
@@ -69,9 +69,9 @@ class BlockOutput:
6969

7070
block_gas_used: Uint = Uint(0)
7171
transactions_trie: Trie[
72-
Bytes, Optional[Union[Bytes, LegacyTransaction]]
72+
Bytes, Optional[Bytes | LegacyTransaction]
7373
] = field(default_factory=lambda: Trie(secured=False, default=None))
74-
receipts_trie: Trie[Bytes, Optional[Union[Bytes, Receipt]]] = field(
74+
receipts_trie: Trie[Bytes, Optional[Bytes | Receipt]] = field(
7575
default_factory=lambda: Trie(secured=False, default=None)
7676
)
7777
block_logs: Tuple[Log, ...] = field(default_factory=tuple)
@@ -102,7 +102,7 @@ class Message:
102102
block_env: BlockEnvironment
103103
tx_env: TransactionEnvironment
104104
caller: Address
105-
target: Union[Bytes0, Address]
105+
target: Bytes0 | Address
106106
current_target: Address
107107
gas: Uint
108108
value: U256

Diff for: src/ethereum/berlin/blocks.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
chain.
1010
"""
1111
from dataclasses import dataclass
12-
from typing import Tuple, Union
12+
from typing import Tuple
1313

1414
from ethereum_rlp import rlp
1515
from ethereum_types.bytes import Bytes, Bytes8, Bytes32
@@ -53,7 +53,7 @@ class Block:
5353
"""
5454

5555
header: Header
56-
transactions: Tuple[Union[Bytes, LegacyTransaction], ...]
56+
transactions: Tuple[Bytes | LegacyTransaction, ...]
5757
ommers: Tuple[Header, ...]
5858

5959

@@ -82,7 +82,7 @@ class Receipt:
8282
logs: Tuple[Log, ...]
8383

8484

85-
def encode_receipt(tx: Transaction, receipt: Receipt) -> Union[Bytes, Receipt]:
85+
def encode_receipt(tx: Transaction, receipt: Receipt) -> Bytes | Receipt:
8686
"""
8787
Encodes a receipt.
8888
"""
@@ -92,7 +92,7 @@ def encode_receipt(tx: Transaction, receipt: Receipt) -> Union[Bytes, Receipt]:
9292
return receipt
9393

9494

95-
def decode_receipt(receipt: Union[Bytes, Receipt]) -> Receipt:
95+
def decode_receipt(receipt: Bytes | Receipt) -> Receipt:
9696
"""
9797
Decodes a receipt.
9898
"""

Diff for: src/ethereum/berlin/fork.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Entry point for the Ethereum specification.
1313
"""
1414
from dataclasses import dataclass
15-
from typing import List, Optional, Set, Tuple, Union
15+
from typing import List, Optional, Set, Tuple
1616

1717
from ethereum_rlp import rlp
1818
from ethereum_types.bytes import Bytes
@@ -389,7 +389,7 @@ def make_receipt(
389389
error: Optional[EthereumException],
390390
cumulative_gas_used: Uint,
391391
logs: Tuple[Log, ...],
392-
) -> Union[Bytes, Receipt]:
392+
) -> Bytes | Receipt:
393393
"""
394394
Make the receipt for a transaction that was executed.
395395
@@ -422,7 +422,7 @@ def make_receipt(
422422

423423
def apply_body(
424424
block_env: vm.BlockEnvironment,
425-
transactions: Tuple[Union[LegacyTransaction, Bytes], ...],
425+
transactions: Tuple[LegacyTransaction | Bytes, ...],
426426
ommers: Tuple[Header, ...],
427427
) -> vm.BlockOutput:
428428
"""

Diff for: src/ethereum/berlin/transactions.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
transactions are the events that move between states.
55
"""
66
from dataclasses import dataclass
7-
from typing import Tuple, Union
7+
from typing import Tuple
88

99
from ethereum_rlp import rlp
1010
from ethereum_types.bytes import Bytes, Bytes0, Bytes32
@@ -36,7 +36,7 @@ class LegacyTransaction:
3636
nonce: U256
3737
gas_price: Uint
3838
gas: Uint
39-
to: Union[Bytes0, Address]
39+
to: Bytes0 | Address
4040
value: U256
4141
data: Bytes
4242
v: U256
@@ -55,7 +55,7 @@ class AccessListTransaction:
5555
nonce: U256
5656
gas_price: Uint
5757
gas: Uint
58-
to: Union[Bytes0, Address]
58+
to: Bytes0 | Address
5959
value: U256
6060
data: Bytes
6161
access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...]
@@ -64,10 +64,10 @@ class AccessListTransaction:
6464
s: U256
6565

6666

67-
Transaction = Union[LegacyTransaction, AccessListTransaction]
67+
Transaction = LegacyTransaction | AccessListTransaction
6868

6969

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

8181

82-
def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
82+
def decode_transaction(tx: LegacyTransaction | Bytes) -> Transaction:
8383
"""
8484
Decode a transaction. Needed because non-legacy transactions aren't RLP.
8585
"""
@@ -318,7 +318,7 @@ def signing_hash_2930(tx: AccessListTransaction) -> Hash32:
318318
)
319319

320320

321-
def get_transaction_hash(tx: Union[Bytes, LegacyTransaction]) -> Hash32:
321+
def get_transaction_hash(tx: Bytes | LegacyTransaction) -> Hash32:
322322
"""
323323
Parameters
324324
----------

Diff for: src/ethereum/berlin/trie.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
Optional,
2626
Sequence,
2727
TypeVar,
28-
Union,
2928
)
3029

3130
from ethereum_rlp import rlp
@@ -60,15 +59,15 @@
6059
)
6160
)
6261

63-
Node = Union[Account, Bytes, LegacyTransaction, Receipt, Uint, U256, None]
62+
Node = Account | Bytes | LegacyTransaction | Receipt | Uint | U256 | None
6463
K = TypeVar("K", bound=Bytes)
6564
V = TypeVar(
6665
"V",
6766
Optional[Account],
6867
Optional[Bytes],
6968
Bytes,
70-
Optional[Union[LegacyTransaction, Bytes]],
71-
Optional[Union[Receipt, Bytes]],
69+
Optional[LegacyTransaction | Bytes],
70+
Optional[Receipt | Bytes],
7271
Uint,
7372
U256,
7473
)
@@ -101,7 +100,7 @@ class BranchNode:
101100
value: rlp.Extended
102101

103102

104-
InternalNode = Union[LeafNode, ExtensionNode, BranchNode]
103+
InternalNode = LeafNode | ExtensionNode | BranchNode
105104

106105

107106
def encode_internal_node(node: Optional[InternalNode]) -> rlp.Extended:

Diff for: src/ethereum/berlin/utils/address.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
Address specific functions used in this berlin version of
1313
specification.
1414
"""
15-
from typing import Union
16-
1715
from ethereum_rlp import rlp
1816
from ethereum_types.bytes import Bytes32
1917
from ethereum_types.numeric import U256, Uint
@@ -24,7 +22,7 @@
2422
from ..fork_types import Address
2523

2624

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

0 commit comments

Comments
 (0)