web3 7.14.0__py3-none-any.whl → 8.0.0b1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. ens/_normalization.py +23 -29
  2. ens/async_ens.py +30 -24
  3. ens/base_ens.py +2 -3
  4. ens/ens.py +18 -20
  5. ens/utils.py +6 -10
  6. web3/__init__.py +0 -4
  7. web3/_utils/abi.py +38 -40
  8. web3/_utils/async_transactions.py +6 -9
  9. web3/_utils/batching.py +11 -15
  10. web3/_utils/blocks.py +1 -2
  11. web3/_utils/caching/caching_utils.py +12 -17
  12. web3/_utils/caching/request_caching_validation.py +7 -9
  13. web3/_utils/compat/__init__.py +2 -2
  14. web3/_utils/contract_sources/compile_contracts.py +4 -6
  15. web3/_utils/contracts.py +25 -29
  16. web3/_utils/datatypes.py +6 -10
  17. web3/_utils/decorators.py +1 -3
  18. web3/_utils/encoding.py +10 -14
  19. web3/_utils/ens.py +4 -5
  20. web3/_utils/events.py +19 -24
  21. web3/_utils/filters.py +23 -29
  22. web3/_utils/formatters.py +8 -13
  23. web3/_utils/http_session_manager.py +11 -15
  24. web3/_utils/math.py +1 -2
  25. web3/_utils/method_formatters.py +41 -43
  26. web3/_utils/module.py +3 -6
  27. web3/_utils/module_testing/eth_module.py +7 -9
  28. web3/_utils/module_testing/go_ethereum_admin_module.py +1 -2
  29. web3/_utils/module_testing/module_testing_utils.py +9 -5
  30. web3/_utils/module_testing/persistent_connection_provider.py +3 -7
  31. web3/_utils/module_testing/utils.py +32 -21
  32. web3/_utils/normalizers.py +21 -24
  33. web3/_utils/rpc_abi.py +8 -11
  34. web3/_utils/threads.py +3 -4
  35. web3/_utils/transactions.py +3 -6
  36. web3/_utils/type_conversion.py +2 -6
  37. web3/_utils/utility_methods.py +5 -7
  38. web3/_utils/validation.py +6 -8
  39. web3/_utils/windows.py +1 -4
  40. web3/beacon/async_beacon.py +51 -55
  41. web3/beacon/beacon.py +50 -54
  42. web3/contract/async_contract.py +38 -46
  43. web3/contract/base_contract.py +70 -75
  44. web3/contract/contract.py +39 -43
  45. web3/contract/utils.py +47 -51
  46. web3/datastructures.py +10 -15
  47. web3/eth/async_eth.py +64 -70
  48. web3/eth/base_eth.py +40 -44
  49. web3/eth/eth.py +50 -66
  50. web3/exceptions.py +8 -13
  51. web3/gas_strategies/rpc.py +1 -7
  52. web3/gas_strategies/time_based.py +2 -3
  53. web3/geth.py +17 -17
  54. web3/main.py +43 -52
  55. web3/manager.py +32 -35
  56. web3/method.py +22 -29
  57. web3/middleware/base.py +5 -8
  58. web3/middleware/filter.py +41 -46
  59. web3/middleware/formatting.py +5 -6
  60. web3/middleware/names.py +1 -3
  61. web3/middleware/signing.py +3 -4
  62. web3/middleware/stalecheck.py +1 -2
  63. web3/middleware/validation.py +1 -2
  64. web3/module.py +11 -14
  65. web3/providers/__init__.py +0 -4
  66. web3/providers/async_base.py +21 -27
  67. web3/providers/auto.py +9 -20
  68. web3/providers/base.py +12 -17
  69. web3/providers/eth_tester/defaults.py +4 -8
  70. web3/providers/eth_tester/main.py +4 -8
  71. web3/providers/eth_tester/middleware.py +2 -4
  72. web3/providers/ipc.py +6 -10
  73. web3/providers/persistent/async_ipc.py +4 -7
  74. web3/providers/persistent/persistent.py +22 -25
  75. web3/providers/persistent/persistent_connection.py +2 -4
  76. web3/providers/persistent/request_processor.py +11 -32
  77. web3/providers/persistent/subscription_container.py +5 -8
  78. web3/providers/persistent/subscription_manager.py +13 -19
  79. web3/providers/persistent/websocket.py +15 -12
  80. web3/providers/rpc/async_rpc.py +10 -16
  81. web3/providers/rpc/rpc.py +11 -17
  82. web3/providers/rpc/utils.py +2 -3
  83. web3/scripts/release/test_package.py +1 -4
  84. web3/testing.py +1 -5
  85. web3/tracing.py +9 -13
  86. web3/types.py +49 -56
  87. web3/utils/abi.py +28 -33
  88. web3/utils/async_exception_handling.py +1 -2
  89. web3/utils/caching.py +6 -10
  90. web3/utils/exception_handling.py +1 -2
  91. web3/utils/subscriptions.py +30 -34
  92. {web3-7.14.0.dist-info → web3-8.0.0b1.dist-info}/METADATA +13 -12
  93. web3-8.0.0b1.dist-info/RECORD +170 -0
  94. web3/providers/legacy_websocket.py +0 -159
  95. web3-7.14.0.dist-info/RECORD +0 -171
  96. {web3-7.14.0.dist-info → web3-8.0.0b1.dist-info}/WHEEL +0 -0
  97. {web3-7.14.0.dist-info → web3-8.0.0b1.dist-info}/licenses/LICENSE +0 -0
  98. {web3-7.14.0.dist-info → web3-8.0.0b1.dist-info}/top_level.txt +0 -0
web3/_utils/contracts.py CHANGED
@@ -4,11 +4,7 @@ from typing import (
4
4
  TYPE_CHECKING,
5
5
  Any,
6
6
  Callable,
7
- Dict,
8
- List,
9
- Optional,
10
7
  Sequence,
11
- Tuple,
12
8
  Union,
13
9
  cast,
14
10
  )
@@ -97,10 +93,10 @@ if TYPE_CHECKING:
97
93
 
98
94
  def find_matching_event_abi(
99
95
  abi: ABI,
100
- event_name: Optional[str] = None,
101
- argument_names: Optional[Sequence[str]] = None,
96
+ event_name: str | None = None,
97
+ argument_names: Sequence[str] | None = None,
102
98
  ) -> ABIEvent:
103
- filters: List[functools.partial[Sequence[ABIElement]]] = [
99
+ filters: list[functools.partial[Sequence[ABIElement]]] = [
104
100
  functools.partial(filter_abi_by_type, "event"),
105
101
  ]
106
102
 
@@ -124,7 +120,7 @@ def encode_abi(
124
120
  w3: Union["AsyncWeb3[Any]", "Web3"],
125
121
  abi: ABIElement,
126
122
  arguments: Sequence[Any],
127
- data: Optional[HexStr] = None,
123
+ data: HexStr | None = None,
128
124
  ) -> HexStr:
129
125
  argument_types = []
130
126
  try:
@@ -170,11 +166,11 @@ def prepare_transaction(
170
166
  address: ChecksumAddress,
171
167
  w3: Union["AsyncWeb3[Any]", "Web3"],
172
168
  abi_element_identifier: ABIElementIdentifier,
173
- contract_abi: Optional[ABI] = None,
174
- abi_callable: Optional[ABICallable] = None,
175
- transaction: Optional[TxParams] = None,
176
- fn_args: Optional[Sequence[Any]] = None,
177
- fn_kwargs: Optional[Any] = None,
169
+ contract_abi: ABI | None = None,
170
+ abi_callable: ABICallable | None = None,
171
+ transaction: TxParams | None = None,
172
+ fn_args: Sequence[Any] | None = None,
173
+ fn_kwargs: Any | None = None,
178
174
  ) -> TxParams:
179
175
  """
180
176
  Returns a dictionary of the transaction that could be used to call this
@@ -234,10 +230,10 @@ def prepare_transaction(
234
230
  def encode_transaction_data(
235
231
  w3: Union["AsyncWeb3[Any]", "Web3"],
236
232
  abi_element_identifier: ABIElementIdentifier,
237
- contract_abi: Optional[ABI] = None,
238
- abi_callable: Optional[ABICallable] = None,
239
- args: Optional[Sequence[Any]] = None,
240
- kwargs: Optional[Any] = None,
233
+ contract_abi: ABI | None = None,
234
+ abi_callable: ABICallable | None = None,
235
+ args: Sequence[Any] | None = None,
236
+ kwargs: Any | None = None,
241
237
  ) -> HexStr:
242
238
  info_abi: ABIElement
243
239
  abi_element_name = get_name_from_abi_element_identifier(abi_element_identifier)
@@ -269,8 +265,8 @@ def encode_transaction_data(
269
265
  def decode_transaction_data(
270
266
  fn_abi: ABIFunction,
271
267
  data: HexStr,
272
- normalizers: Sequence[Callable[[TypeStr, Any], Tuple[TypeStr, Any]]] = None,
273
- ) -> Dict[str, Any]:
268
+ normalizers: Sequence[Callable[[TypeStr, Any], tuple[TypeStr, Any]]] = None,
269
+ ) -> dict[str, Any]:
274
270
  data_bytes = HexBytes(data)
275
271
  types = get_abi_input_types(fn_abi)
276
272
  abi_codec = ABICodec(default_registry)
@@ -281,34 +277,34 @@ def decode_transaction_data(
281
277
 
282
278
 
283
279
  def get_constructor_function_info(
284
- contract_abi: Optional[ABI] = None, constructor_abi: Optional[ABIConstructor] = None
285
- ) -> Tuple[ABIConstructor, HexStr, Tuple[Any, ...]]:
280
+ contract_abi: ABI | None = None, constructor_abi: ABIConstructor | None = None
281
+ ) -> tuple[ABIConstructor, HexStr, tuple[Any, ...]]:
286
282
  if constructor_abi is None:
287
283
  constructor_abi = cast(
288
284
  ABIConstructor, get_abi_element(contract_abi, "constructor")
289
285
  )
290
286
  fn_selector = encode_hex(b"")
291
- fn_arguments: Tuple[Any, ...] = tuple()
287
+ fn_arguments: tuple[Any, ...] = tuple()
292
288
  return constructor_abi, fn_selector, fn_arguments
293
289
 
294
290
 
295
291
  def get_fallback_function_info(
296
- contract_abi: Optional[ABI] = None, fallback_abi: Optional[ABIFallback] = None
297
- ) -> Tuple[ABIFallback, HexStr, Tuple[Any, ...]]:
292
+ contract_abi: ABI | None = None, fallback_abi: ABIFallback | None = None
293
+ ) -> tuple[ABIFallback, HexStr, tuple[Any, ...]]:
298
294
  if fallback_abi is None:
299
295
  fallback_abi = cast(ABIFallback, get_abi_element(contract_abi, "fallback"))
300
296
  fn_selector = encode_hex(b"")
301
- fn_arguments: Tuple[Any, ...] = tuple()
297
+ fn_arguments: tuple[Any, ...] = tuple()
302
298
  return fallback_abi, fn_selector, fn_arguments
303
299
 
304
300
 
305
301
  def get_receive_function_info(
306
- contract_abi: Optional[ABI] = None, receive_abi: Optional[ABIReceive] = None
307
- ) -> Tuple[ABIReceive, HexStr, Tuple[Any, ...]]:
302
+ contract_abi: ABI | None = None, receive_abi: ABIReceive | None = None
303
+ ) -> tuple[ABIReceive, HexStr, tuple[Any, ...]]:
308
304
  if receive_abi is None:
309
305
  receive_abi = cast(ABIReceive, get_abi_element(contract_abi, "receive"))
310
306
  fn_selector = encode_hex(b"")
311
- fn_arguments: Tuple[Any, ...] = tuple()
307
+ fn_arguments: tuple[Any, ...] = tuple()
312
308
  return receive_abi, fn_selector, fn_arguments
313
309
 
314
310
 
@@ -335,7 +331,7 @@ def validate_payable(transaction: TxParams, abi_callable: ABICallable) -> None:
335
331
 
336
332
 
337
333
  def parse_block_identifier(
338
- w3: "Web3", block_identifier: Optional[BlockIdentifier]
334
+ w3: "Web3", block_identifier: BlockIdentifier | None
339
335
  ) -> BlockIdentifier:
340
336
  if block_identifier is None:
341
337
  return w3.eth.default_block
web3/_utils/datatypes.py CHANGED
@@ -1,10 +1,6 @@
1
1
  from typing import (
2
2
  Any,
3
3
  Collection,
4
- Dict,
5
- Optional,
6
- Tuple,
7
- Type,
8
4
  )
9
5
 
10
6
  from eth_utils import (
@@ -32,9 +28,9 @@ class PropertyCheckingFactory(type):
32
28
  def __init__(
33
29
  cls,
34
30
  name: str,
35
- bases: Tuple[Type[Any], ...],
36
- namespace: Dict[str, Any],
37
- **kwargs: Dict[str, Any],
31
+ bases: tuple[type[Any], ...],
32
+ namespace: dict[str, Any],
33
+ **kwargs: dict[str, Any],
38
34
  ) -> None:
39
35
  # see PEP487. To accept kwargs in __new__, they need to be
40
36
  # filtered out here.
@@ -44,9 +40,9 @@ class PropertyCheckingFactory(type):
44
40
  def __new__(
45
41
  mcs,
46
42
  name: str,
47
- bases: Tuple[type],
48
- namespace: Dict[str, Any],
49
- normalizers: Optional[Dict[str, Any]] = None,
43
+ bases: tuple[type],
44
+ namespace: dict[str, Any],
45
+ normalizers: dict[str, Any] | None = None,
50
46
  ) -> "PropertyCheckingFactory":
51
47
  all_bases = set(concat(base.__mro__ for base in bases))
52
48
  all_keys = set(concat(base.__dict__.keys() for base in all_bases))
web3/_utils/decorators.py CHANGED
@@ -3,8 +3,6 @@ import threading
3
3
  from typing import (
4
4
  Any,
5
5
  Callable,
6
- Set,
7
- Tuple,
8
6
  TypeVar,
9
7
  cast,
10
8
  )
@@ -22,7 +20,7 @@ def reject_recursive_repeats(to_wrap: Callable[..., Any]) -> Callable[..., Any]:
22
20
  Prevent simple cycles by returning None when called recursively with same instance
23
21
  """
24
22
  # types ignored b/c dynamically set attribute
25
- already_called: Set[Tuple[int, ...]] = set()
23
+ already_called: set[tuple[int, ...]] = set()
26
24
  to_wrap.__already_called = already_called # type: ignore
27
25
 
28
26
  add_call = already_called.add
web3/_utils/encoding.py CHANGED
@@ -4,12 +4,8 @@ import re
4
4
  from typing import (
5
5
  Any,
6
6
  Callable,
7
- Dict,
8
7
  Iterable,
9
- Optional,
10
8
  Sequence,
11
- Type,
12
- Union,
13
9
  )
14
10
 
15
11
  from eth_abi.encoding import (
@@ -65,7 +61,7 @@ from web3.exceptions import (
65
61
 
66
62
 
67
63
  def hex_encode_abi_type(
68
- abi_type: TypeStr, value: Any, force_size: Optional[int] = None
64
+ abi_type: TypeStr, value: Any, force_size: int | None = None
69
65
  ) -> HexStr:
70
66
  """
71
67
  Encodes value into a hex string in format of abi_type
@@ -146,7 +142,7 @@ zpad_bytes = pad_bytes(b"\0")
146
142
 
147
143
  @curry
148
144
  def text_if_str(
149
- to_type: Callable[..., str], text_or_primitive: Union[Primitives, HexStr, str]
145
+ to_type: Callable[..., str], text_or_primitive: Primitives | HexStr | str
150
146
  ) -> str:
151
147
  """
152
148
  Convert to a type, assuming that strings can be only unicode text (not a hexstr)
@@ -164,7 +160,7 @@ def text_if_str(
164
160
 
165
161
  @curry
166
162
  def hexstr_if_str(
167
- to_type: Callable[..., HexStr], hexstr_or_primitive: Union[Primitives, HexStr, str]
163
+ to_type: Callable[..., HexStr], hexstr_or_primitive: Primitives | HexStr | str
168
164
  ) -> HexStr:
169
165
  """
170
166
  Convert to a type, assuming that strings can be only hexstr (not unicode text)
@@ -194,7 +190,7 @@ class FriendlyJsonSerde:
194
190
  helpful information in the raised error messages.
195
191
  """
196
192
 
197
- def _json_mapping_errors(self, mapping: Dict[Any, Any]) -> Iterable[str]:
193
+ def _json_mapping_errors(self, mapping: dict[Any, Any]) -> Iterable[str]:
198
194
  for key, val in mapping.items():
199
195
  try:
200
196
  self._friendly_json_encode(val)
@@ -209,7 +205,7 @@ class FriendlyJsonSerde:
209
205
  yield f"{index}: because ({exc})"
210
206
 
211
207
  def _friendly_json_encode(
212
- self, obj: Dict[Any, Any], cls: Optional[Type[json.JSONEncoder]] = None
208
+ self, obj: dict[Any, Any], cls: type[json.JSONEncoder] | None = None
213
209
  ) -> str:
214
210
  try:
215
211
  encoded = json.dumps(obj, cls=cls)
@@ -228,7 +224,7 @@ class FriendlyJsonSerde:
228
224
  else:
229
225
  raise full_exception
230
226
 
231
- def json_decode(self, json_str: str) -> Dict[Any, Any]:
227
+ def json_decode(self, json_str: str) -> dict[Any, Any]:
232
228
  try:
233
229
  decoded = json.loads(json_str)
234
230
  return decoded
@@ -239,7 +235,7 @@ class FriendlyJsonSerde:
239
235
  raise json.decoder.JSONDecodeError(err_msg, exc.doc, exc.pos)
240
236
 
241
237
  def json_encode(
242
- self, obj: Dict[Any, Any], cls: Optional[Type[json.JSONEncoder]] = None
238
+ self, obj: dict[Any, Any], cls: type[json.JSONEncoder] | None = None
243
239
  ) -> str:
244
240
  try:
245
241
  return self._friendly_json_encode(obj, cls=cls)
@@ -247,7 +243,7 @@ class FriendlyJsonSerde:
247
243
  raise Web3TypeError(f"Could not encode to JSON: {exc}")
248
244
 
249
245
 
250
- def to_4byte_hex(hex_or_str_or_bytes: Union[HexStr, str, bytes, int]) -> HexStr:
246
+ def to_4byte_hex(hex_or_str_or_bytes: HexStr | str | bytes | int) -> HexStr:
251
247
  size_of_4bytes = 4 * 8
252
248
  byte_str = hexstr_if_str(to_bytes, hex_or_str_or_bytes)
253
249
  if len(byte_str) > 4:
@@ -297,7 +293,7 @@ def encode_single_packed(_type: TypeStr, value: Any) -> bytes:
297
293
 
298
294
 
299
295
  class Web3JsonEncoder(json.JSONEncoder):
300
- def default(self, obj: Any) -> Union[Dict[Any, Any], HexStr]:
296
+ def default(self, obj: Any) -> dict[Any, Any] | HexStr:
301
297
  if isinstance(obj, AttributeDict):
302
298
  return obj.__dict__
303
299
  elif isinstance(obj, (HexBytes, bytes)):
@@ -310,7 +306,7 @@ class Web3JsonEncoder(json.JSONEncoder):
310
306
  return json.JSONEncoder.default(self, obj)
311
307
 
312
308
 
313
- def to_json(obj: Dict[Any, Any]) -> str:
309
+ def to_json(obj: dict[Any, Any]) -> str:
314
310
  """
315
311
  Convert a complex object (like a transaction object) to a JSON string
316
312
  """
web3/_utils/ens.py CHANGED
@@ -4,7 +4,6 @@ from contextlib import (
4
4
  from typing import (
5
5
  TYPE_CHECKING,
6
6
  Any,
7
- Dict,
8
7
  Iterator,
9
8
  Union,
10
9
  cast,
@@ -58,7 +57,7 @@ def validate_name_has_address(ens: ENS, name: str) -> ChecksumAddress:
58
57
 
59
58
 
60
59
  class StaticENS:
61
- def __init__(self, name_addr_pairs: Dict[str, ChecksumAddress]) -> None:
60
+ def __init__(self, name_addr_pairs: dict[str, ChecksumAddress]) -> None:
62
61
  self.registry = dict(name_addr_pairs)
63
62
 
64
63
  def address(self, name: str) -> ChecksumAddress:
@@ -66,7 +65,7 @@ class StaticENS:
66
65
 
67
66
 
68
67
  class AsyncStaticENS:
69
- def __init__(self, name_addr_pairs: Dict[str, ChecksumAddress]) -> None:
68
+ def __init__(self, name_addr_pairs: dict[str, ChecksumAddress]) -> None:
70
69
  self.registry = dict(name_addr_pairs)
71
70
 
72
71
  async def address(self, name: str) -> ChecksumAddress:
@@ -75,7 +74,7 @@ class AsyncStaticENS:
75
74
 
76
75
  @contextmanager
77
76
  def ens_addresses(
78
- w3: Union["Web3", "AsyncWeb3[Any]"], name_addr_pairs: Dict[str, ChecksumAddress]
77
+ w3: Union["Web3", "AsyncWeb3[Any]"], name_addr_pairs: dict[str, ChecksumAddress]
79
78
  ) -> Iterator[None]:
80
79
  original_ens = w3.ens
81
80
  if w3.provider.is_async:
@@ -88,7 +87,7 @@ def ens_addresses(
88
87
 
89
88
  @contextmanager
90
89
  def contract_ens_addresses(
91
- contract: "Contract", name_addr_pairs: Dict[str, ChecksumAddress]
90
+ contract: "Contract", name_addr_pairs: dict[str, ChecksumAddress]
92
91
  ) -> Iterator[None]:
93
92
  """
94
93
  Use this context manager to temporarily resolve name/address pairs
web3/_utils/events.py CHANGED
@@ -10,13 +10,8 @@ from typing import (
10
10
  TYPE_CHECKING,
11
11
  Any,
12
12
  Collection,
13
- Dict,
14
13
  Iterable,
15
- List,
16
- Optional,
17
14
  Sequence,
18
- Tuple,
19
- Union,
20
15
  cast,
21
16
  )
22
17
 
@@ -105,7 +100,7 @@ if TYPE_CHECKING:
105
100
 
106
101
 
107
102
  def _log_entry_data_to_bytes(
108
- log_entry_data: Union[Primitives, HexStr, str],
103
+ log_entry_data: Primitives | HexStr | str,
109
104
  ) -> bytes:
110
105
  return hexstr_if_str(to_bytes, log_entry_data)
111
106
 
@@ -113,8 +108,8 @@ def _log_entry_data_to_bytes(
113
108
  def construct_event_topic_set(
114
109
  event_abi: ABIEvent,
115
110
  abi_codec: ABICodec,
116
- arguments: Optional[Union[List[Any], Tuple[Any], Dict[str, Any]]] = None,
117
- ) -> List[HexStr]:
111
+ arguments: list[Any] | tuple[Any] | dict[str, Any] | None = None,
112
+ ) -> list[HexStr]:
118
113
  if arguments is None:
119
114
  arguments = {}
120
115
  elif isinstance(arguments, (list, tuple)):
@@ -156,8 +151,8 @@ def construct_event_topic_set(
156
151
  def construct_event_data_set(
157
152
  event_abi: ABIEvent,
158
153
  abi_codec: ABICodec,
159
- arguments: Optional[Union[Sequence[Any], Dict[str, Any]]] = None,
160
- ) -> List[List[Optional[HexStr]]]:
154
+ arguments: Sequence[Any] | dict[str, Any] | None = None,
155
+ ) -> list[list[HexStr | None]]:
161
156
  if arguments is None:
162
157
  arguments = {}
163
158
  if isinstance(arguments, (list, tuple)):
@@ -207,7 +202,7 @@ def is_dynamic_sized_type(type_str: TypeStr) -> bool:
207
202
 
208
203
  @to_tuple
209
204
  def get_event_abi_types_for_decoding(
210
- event_inputs: Sequence[Union[ABIComponent, ABIComponentIndexed]],
205
+ event_inputs: Sequence[ABIComponent | ABIComponentIndexed],
211
206
  ) -> Iterable[TypeStr]:
212
207
  """
213
208
  Event logs use the `keccak(value)` for indexed inputs of type `bytes` or
@@ -310,7 +305,7 @@ def pop_singlets(seq: Sequence[Any]) -> Iterable[Any]:
310
305
 
311
306
  @curry
312
307
  def remove_trailing_from_seq(
313
- seq: Sequence[Any], remove_value: Optional[Any] = None
308
+ seq: Sequence[Any], remove_value: Any | None = None
314
309
  ) -> Sequence[Any]:
315
310
  index = len(seq)
316
311
  while index > 0 and seq[index - 1] == remove_value:
@@ -344,7 +339,7 @@ class BaseEventFilterBuilder:
344
339
  self,
345
340
  event_abi: ABIEvent,
346
341
  abi_codec: ABICodec,
347
- formatter: Optional[EventData] = None,
342
+ formatter: EventData | None = None,
348
343
  ) -> None:
349
344
  self.event_abi = event_abi
350
345
  self.abi_codec = abi_codec
@@ -398,26 +393,26 @@ class BaseEventFilterBuilder:
398
393
  )
399
394
 
400
395
  @property
401
- def ordered_args(self) -> Tuple[Any, ...]:
396
+ def ordered_args(self) -> tuple[Any, ...]:
402
397
  return tuple(map(self.args.__getitem__, self._ordered_arg_names))
403
398
 
404
399
  @property
405
400
  @to_tuple
406
- def indexed_args(self) -> Tuple[Any, ...]:
401
+ def indexed_args(self) -> tuple[Any, ...]:
407
402
  return tuple(filter(is_indexed, self.ordered_args))
408
403
 
409
404
  @property
410
405
  @to_tuple
411
- def data_args(self) -> Tuple[Any, ...]:
406
+ def data_args(self) -> tuple[Any, ...]:
412
407
  return tuple(filter(is_not_indexed, self.ordered_args))
413
408
 
414
409
  @property
415
- def topics(self) -> List[HexStr]:
410
+ def topics(self) -> list[HexStr]:
416
411
  arg_topics = tuple(arg.match_values for arg in self.indexed_args)
417
412
  return normalize_topic_list(cons(to_hex(self.event_topic), arg_topics))
418
413
 
419
414
  @property
420
- def data_argument_values(self) -> Tuple[Any, ...]:
415
+ def data_argument_values(self) -> tuple[Any, ...]:
421
416
  if self.data_args is not None:
422
417
  return tuple(arg.match_values for arg in self.data_args)
423
418
  else:
@@ -471,7 +466,7 @@ class AsyncEventFilterBuilder(BaseEventFilterBuilder):
471
466
  return log_filter
472
467
 
473
468
 
474
- def initialize_event_topics(event_abi: ABIEvent) -> Union[bytes, List[Any]]:
469
+ def initialize_event_topics(event_abi: ABIEvent) -> bytes | list[Any]:
475
470
  if event_abi["anonymous"] is False:
476
471
  return event_abi_to_log_topic(event_abi)
477
472
  else:
@@ -481,7 +476,7 @@ def initialize_event_topics(event_abi: ABIEvent) -> Union[bytes, List[Any]]:
481
476
  @to_dict
482
477
  def _build_argument_filters_from_event_abi(
483
478
  event_abi: ABIEvent, abi_codec: ABICodec
484
- ) -> Iterable[Tuple[str, "BaseArgumentFilter"]]:
479
+ ) -> Iterable[tuple[str, "BaseArgumentFilter"]]:
485
480
  for item in event_abi["inputs"]:
486
481
  key = item["name"]
487
482
  value: "BaseArgumentFilter"
@@ -504,7 +499,7 @@ def _normalize_match_values(match_values: Collection[Any]) -> Iterable[Any]:
504
499
 
505
500
 
506
501
  class BaseArgumentFilter(ABC):
507
- _match_values: Tuple[Any, ...] = None
502
+ _match_values: tuple[Any, ...] = None
508
503
  _immutable = False
509
504
 
510
505
  def __init__(self, arg_type: TypeStr) -> None:
@@ -539,7 +534,7 @@ class BaseArgumentFilter(ABC):
539
534
  class DataArgumentFilter(BaseArgumentFilter):
540
535
  # type ignore b/c conflict with BaseArgumentFilter.match_values type
541
536
  @property
542
- def match_values(self) -> Tuple[TypeStr, Tuple[Any, ...]]: # type: ignore
537
+ def match_values(self) -> tuple[TypeStr, tuple[Any, ...]]: # type: ignore
543
538
  return self.arg_type, self._match_values
544
539
 
545
540
 
@@ -554,7 +549,7 @@ class TopicArgumentFilter(BaseArgumentFilter):
554
549
 
555
550
  # type ignore b/c conflict with BaseArgumentFilter.match_values type
556
551
  @property
557
- def match_values(self) -> Optional[Tuple[HexStr, ...]]: # type: ignore
552
+ def match_values(self) -> tuple[HexStr, ...] | None: # type: ignore
558
553
  if self._match_values is not None:
559
554
  return self._get_match_values()
560
555
  else:
@@ -574,5 +569,5 @@ class EventLogErrorFlags(Enum):
574
569
  Warn = "warn"
575
570
 
576
571
  @classmethod
577
- def flag_options(self) -> List[str]:
572
+ def flag_options(self) -> list[str]:
578
573
  return [key.upper() for key in self.__members__.keys()]
web3/_utils/filters.py CHANGED
@@ -3,14 +3,8 @@ from typing import (
3
3
  Any,
4
4
  Callable,
5
5
  Collection,
6
- Dict,
7
6
  Iterator,
8
- List,
9
- Optional,
10
7
  Sequence,
11
- Set,
12
- Tuple,
13
- Union,
14
8
  )
15
9
 
16
10
  from eth_abi.codec import (
@@ -68,8 +62,8 @@ if TYPE_CHECKING:
68
62
 
69
63
 
70
64
  def _sanitize_addresses(
71
- *address: Union[ChecksumAddress, List[ChecksumAddress]],
72
- ) -> Union[ChecksumAddress, List[ChecksumAddress]]:
65
+ *address: ChecksumAddress | list[ChecksumAddress],
66
+ ) -> ChecksumAddress | list[ChecksumAddress]:
73
67
  """
74
68
  Validates an address or list of addresses and returns a single
75
69
  ChecksumAddress or a list of ChecksumAddresses.
@@ -78,7 +72,7 @@ def _sanitize_addresses(
78
72
  :param address: A single address or a list of addresses.
79
73
  :return: A list of ChecksumAddress.
80
74
  """
81
- address_set: Set[ChecksumAddress] = set()
75
+ address_set: set[ChecksumAddress] = set()
82
76
  for arg in address:
83
77
  if not arg:
84
78
  continue
@@ -103,13 +97,13 @@ def _sanitize_addresses(
103
97
  def construct_event_filter_params(
104
98
  event_abi: ABIEvent,
105
99
  abi_codec: ABICodec,
106
- contract_address: Optional[Union[ChecksumAddress, List[ChecksumAddress]]] = None,
107
- argument_filters: Optional[Dict[str, Any]] = None,
108
- topics: Optional[Sequence[HexStr]] = None,
109
- from_block: Optional[BlockIdentifier] = None,
110
- to_block: Optional[BlockIdentifier] = None,
111
- address: Optional[Union[ChecksumAddress, List[ChecksumAddress]]] = None,
112
- ) -> Tuple[List[List[Optional[HexStr]]], FilterParams]:
100
+ contract_address: ChecksumAddress | list[ChecksumAddress] | None = None,
101
+ argument_filters: dict[str, Any] | None = None,
102
+ topics: Sequence[HexStr] | None = None,
103
+ from_block: BlockIdentifier | None = None,
104
+ to_block: BlockIdentifier | None = None,
105
+ address: ChecksumAddress | list[ChecksumAddress] | None = None,
106
+ ) -> tuple[list[list[HexStr | None]], FilterParams]:
113
107
  filter_params: FilterParams = {}
114
108
  topic_set: Sequence[HexStr] = construct_event_topic_set(
115
109
  event_abi, abi_codec, argument_filters
@@ -141,7 +135,7 @@ def construct_event_filter_params(
141
135
 
142
136
 
143
137
  class BaseFilter:
144
- callbacks: List[Callable[..., Any]] = None
138
+ callbacks: list[Callable[..., Any]] = None
145
139
  stopped = False
146
140
  poll_interval = None
147
141
  filter_id = None
@@ -173,8 +167,8 @@ class BaseFilter:
173
167
  return filter(self.is_valid_entry, entries)
174
168
 
175
169
  def _format_log_entries(
176
- self, log_entries: Optional[Iterator[LogReceipt]] = None
177
- ) -> List[LogReceipt]:
170
+ self, log_entries: Iterator[LogReceipt] | None = None
171
+ ) -> list[LogReceipt]:
178
172
  if log_entries is None:
179
173
  return []
180
174
 
@@ -189,13 +183,13 @@ class Filter(BaseFilter):
189
183
  self.eth_module = eth_module
190
184
  super().__init__(filter_id)
191
185
 
192
- def get_new_entries(self) -> List[LogReceipt]:
186
+ def get_new_entries(self) -> list[LogReceipt]:
193
187
  log_entries = self._filter_valid_entries(
194
188
  self.eth_module.get_filter_changes(self.filter_id)
195
189
  )
196
190
  return self._format_log_entries(log_entries)
197
191
 
198
- def get_all_entries(self) -> List[LogReceipt]:
192
+ def get_all_entries(self) -> list[LogReceipt]:
199
193
  log_entries = self._filter_valid_entries(
200
194
  self.eth_module.get_filter_logs(self.filter_id)
201
195
  )
@@ -207,12 +201,12 @@ class AsyncFilter(BaseFilter):
207
201
  self.eth_module = eth_module
208
202
  super().__init__(filter_id)
209
203
 
210
- async def get_new_entries(self) -> List[LogReceipt]:
204
+ async def get_new_entries(self) -> list[LogReceipt]:
211
205
  filter_changes = await self.eth_module.get_filter_changes(self.filter_id)
212
206
  log_entries = self._filter_valid_entries(filter_changes)
213
207
  return self._format_log_entries(log_entries)
214
208
 
215
- async def get_all_entries(self) -> List[LogReceipt]:
209
+ async def get_all_entries(self) -> list[LogReceipt]:
216
210
  filter_logs = await self.eth_module.get_filter_logs(self.filter_id)
217
211
  log_entries = self._filter_valid_entries(filter_logs)
218
212
  return self._format_log_entries(log_entries)
@@ -257,7 +251,7 @@ class LogFilter(Filter):
257
251
  return entry
258
252
 
259
253
  def set_data_filters(
260
- self, data_filter_set: Collection[Tuple[TypeStr, Any]]
254
+ self, data_filter_set: Collection[tuple[TypeStr, Any]]
261
255
  ) -> None:
262
256
  """
263
257
  Sets the data filters (non indexed argument filters)
@@ -300,7 +294,7 @@ class AsyncLogFilter(AsyncFilter):
300
294
  return entry
301
295
 
302
296
  def set_data_filters(
303
- self, data_filter_set: Collection[Tuple[TypeStr, Any]]
297
+ self, data_filter_set: Collection[tuple[TypeStr, Any]]
304
298
  ) -> None:
305
299
  """
306
300
  Sets the data filters (non indexed argument filters)
@@ -346,7 +340,7 @@ def normalize_data_values(type_string: TypeStr, data_value: Any) -> Any:
346
340
 
347
341
  @curry
348
342
  def match_fn(
349
- codec: ABICodec, match_values_and_abi: Collection[Tuple[str, Any]], data: Any
343
+ codec: ABICodec, match_values_and_abi: Collection[tuple[str, Any]], data: Any
350
344
  ) -> bool:
351
345
  """
352
346
  Match function used for filtering non-indexed event arguments.
@@ -382,17 +376,17 @@ class _UseExistingFilter(Exception):
382
376
  Internal exception, raised when a filter_id is passed into w3.eth.filter()
383
377
  """
384
378
 
385
- def __init__(self, filter_id: Union[str, FilterParams, HexStr]) -> None:
379
+ def __init__(self, filter_id: str | FilterParams | HexStr) -> None:
386
380
  self.filter_id = filter_id
387
381
 
388
382
 
389
383
  @curry
390
384
  def select_filter_method(
391
- value: Union[str, FilterParams, HexStr],
385
+ value: str | FilterParams | HexStr,
392
386
  if_new_block_filter: RPCEndpoint,
393
387
  if_new_pending_transaction_filter: RPCEndpoint,
394
388
  if_new_filter: RPCEndpoint,
395
- ) -> Optional[RPCEndpoint]:
389
+ ) -> RPCEndpoint | None:
396
390
  if is_string(value):
397
391
  if value == "latest":
398
392
  return if_new_block_filter