Skip to content

Commit 170b705

Browse files
danceratopzmarioevz
authored andcommitted
refactor: modernize Union type syntax to use < /dev/null | operator
Replace `Union[X, Y]` with `X | Y` syntax for cleaner type annotations. Applied to type aliases, function signatures, and complex type definitions for improved readability and reduced import dependencies. Python 3.10+ feature - more concise and intuitive union syntax.
1 parent c900d76 commit 170b705

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

src/cli/order_fixtures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
import json
1919
from pathlib import Path
20-
from typing import Any, Dict, List, Union, cast
20+
from typing import Any, Dict, List, cast
2121

2222
import click
2323

2424

25-
def recursive_sort(item: Union[Dict[str, Any], List[Any]]) -> Union[Dict[str, Any], List[Any]]:
25+
def recursive_sort(item: Dict[str, Any] | List[Any]) -> Dict[str, Any] | List[Any]:
2626
"""
2727
Recursively sorts an item.
2828

src/ethereum_test_rpc/rpc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import time
44
from itertools import count
55
from pprint import pprint
6-
from typing import Any, ClassVar, Dict, List, Literal, Union
6+
from typing import Any, ClassVar, Dict, List, Literal
77

88
import requests
99
from jwt import encode
@@ -23,7 +23,7 @@
2323
TransactionByHashResponse,
2424
)
2525

26-
BlockNumberType = Union[int, Literal["latest", "earliest", "pending"]]
26+
BlockNumberType = int | Literal["latest", "earliest", "pending"]
2727

2828

2929
class SendTransactionExceptionError(Exception):
@@ -111,7 +111,7 @@ class EthRPC(BaseRPC):
111111

112112
transaction_wait_timeout: int = 60
113113

114-
BlockNumberType = Union[int, Literal["latest", "earliest", "pending"]]
114+
BlockNumberType = int | Literal["latest", "earliest", "pending"]
115115

116116
def __init__(
117117
self,

src/ethereum_test_rpc/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from enum import Enum
44
from hashlib import sha256
5-
from typing import Annotated, Any, List, Union
5+
from typing import Annotated, Any, List
66

77
from pydantic import AliasChoices, Field, model_validator
88

@@ -97,7 +97,7 @@ class PayloadStatusEnum(str, Enum):
9797

9898

9999
class BlockTransactionExceptionWithMessage(
100-
ExceptionWithMessage[Union[BlockException, TransactionException]] # type: ignore
100+
ExceptionWithMessage[BlockException | TransactionException] # type: ignore
101101
):
102102
"""Exception returned from the execution client with a message."""
103103

src/ethereum_test_types/trie.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
Sequence,
1414
Tuple,
1515
TypeVar,
16-
Union,
1716
cast,
1817
)
1918

@@ -75,7 +74,7 @@ def encode_account(raw_account_data: FrontierAccount, storage_root: Bytes) -> By
7574
bytes.fromhex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
7675
)
7776

78-
Node = Union[FrontierAccount, Bytes, Uint, U256, None]
77+
Node = FrontierAccount | Bytes | Uint | U256 | None
7978
K = TypeVar("K", bound=Bytes)
8079
V = TypeVar(
8180
"V",
@@ -133,7 +132,7 @@ class BranchNode:
133132
value: Extended
134133

135134

136-
InternalNode = Union[LeafNode, ExtensionNode, BranchNode]
135+
InternalNode = LeafNode | ExtensionNode | BranchNode
137136

138137

139138
def encode_internal_node(node: Optional[InternalNode]) -> Extended:

0 commit comments

Comments
 (0)