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/contract/contract.py CHANGED
@@ -2,12 +2,8 @@ from typing import (
2
2
  TYPE_CHECKING,
3
3
  Any,
4
4
  Callable,
5
- Dict,
6
5
  Iterable,
7
- List,
8
- Optional,
9
6
  Sequence,
10
- Type,
11
7
  cast,
12
8
  )
13
9
 
@@ -106,10 +102,10 @@ class ContractEvent(BaseContractEvent):
106
102
  @combomethod
107
103
  def get_logs(
108
104
  self,
109
- argument_filters: Optional[Dict[str, Any]] = None,
110
- from_block: Optional[BlockIdentifier] = None,
111
- to_block: Optional[BlockIdentifier] = None,
112
- block_hash: Optional[HexBytes] = None,
105
+ argument_filters: dict[str, Any] | None = None,
106
+ from_block: BlockIdentifier | None = None,
107
+ to_block: BlockIdentifier | None = None,
108
+ block_hash: HexBytes | None = None,
113
109
  ) -> Iterable[EventData]:
114
110
  """
115
111
  Get events for this contract instance using eth_getLogs API.
@@ -200,11 +196,11 @@ class ContractEvent(BaseContractEvent):
200
196
  def create_filter(
201
197
  self,
202
198
  *, # PEP 3102
203
- argument_filters: Optional[Dict[str, Any]] = None,
204
- from_block: Optional[BlockIdentifier] = None,
199
+ argument_filters: dict[str, Any] | None = None,
200
+ from_block: BlockIdentifier | None = None,
205
201
  to_block: BlockIdentifier = "latest",
206
- address: Optional[ChecksumAddress] = None,
207
- topics: Optional[Sequence[Any]] = None,
202
+ address: ChecksumAddress | None = None,
203
+ topics: Sequence[Any] | None = None,
208
204
  ) -> LogFilter:
209
205
  """
210
206
  Create filter object that tracks logs emitted by this contract event.
@@ -239,7 +235,7 @@ class ContractEvent(BaseContractEvent):
239
235
 
240
236
  class ContractEvents(BaseContractEvents[ContractEvent]):
241
237
  def __init__(
242
- self, abi: ABI, w3: "Web3", address: Optional[ChecksumAddress] = None
238
+ self, abi: ABI, w3: "Web3", address: ChecksumAddress | None = None
243
239
  ) -> None:
244
240
  super().__init__(abi, w3, ContractEvent, address)
245
241
 
@@ -250,10 +246,10 @@ class ContractFunction(BaseContractFunction):
250
246
 
251
247
  def call(
252
248
  self,
253
- transaction: Optional[TxParams] = None,
254
- block_identifier: Optional[BlockIdentifier] = None,
255
- state_override: Optional[StateOverride] = None,
256
- ccip_read_enabled: Optional[bool] = None,
249
+ transaction: TxParams | None = None,
250
+ block_identifier: BlockIdentifier | None = None,
251
+ state_override: StateOverride | None = None,
252
+ ccip_read_enabled: bool | None = None,
257
253
  ) -> Any:
258
254
  """
259
255
  Execute a contract function call using the `eth_call` interface.
@@ -304,7 +300,7 @@ class ContractFunction(BaseContractFunction):
304
300
  **self.kwargs or {},
305
301
  )
306
302
 
307
- def transact(self, transaction: Optional[TxParams] = None) -> HexBytes:
303
+ def transact(self, transaction: TxParams | None = None) -> HexBytes:
308
304
  setup_transaction = self._transact(transaction)
309
305
  abi_element_identifier = abi_to_signature(self.abi)
310
306
 
@@ -321,9 +317,9 @@ class ContractFunction(BaseContractFunction):
321
317
 
322
318
  def estimate_gas(
323
319
  self,
324
- transaction: Optional[TxParams] = None,
325
- block_identifier: Optional[BlockIdentifier] = None,
326
- state_override: Optional[StateOverride] = None,
320
+ transaction: TxParams | None = None,
321
+ block_identifier: BlockIdentifier | None = None,
322
+ state_override: StateOverride | None = None,
327
323
  ) -> int:
328
324
  setup_transaction = self._estimate_gas(transaction)
329
325
  abi_element_identifier = abi_to_signature(self.abi)
@@ -340,7 +336,7 @@ class ContractFunction(BaseContractFunction):
340
336
  **self.kwargs or {},
341
337
  )
342
338
 
343
- def build_transaction(self, transaction: Optional[TxParams] = None) -> TxParams:
339
+ def build_transaction(self, transaction: TxParams | None = None) -> TxParams:
344
340
  built_transaction = self._build_transaction(transaction)
345
341
  abi_element_identifier = abi_to_signature(self.abi)
346
342
 
@@ -359,7 +355,7 @@ class ContractFunction(BaseContractFunction):
359
355
  def get_fallback_function(
360
356
  abi: ABI,
361
357
  w3: "Web3",
362
- address: Optional[ChecksumAddress] = None,
358
+ address: ChecksumAddress | None = None,
363
359
  ) -> "ContractFunction":
364
360
  if abi and fallback_func_abi_exists(abi):
365
361
  fallback_abi = filter_abi_by_type("fallback", abi)[0]
@@ -377,7 +373,7 @@ class ContractFunction(BaseContractFunction):
377
373
  def get_receive_function(
378
374
  abi: ABI,
379
375
  w3: "Web3",
380
- address: Optional[ChecksumAddress] = None,
376
+ address: ChecksumAddress | None = None,
381
377
  ) -> "ContractFunction":
382
378
  if abi and receive_func_abi_exists(abi):
383
379
  receive_abi = filter_abi_by_type("receive", abi)[0]
@@ -397,8 +393,8 @@ class ContractFunctions(BaseContractFunctions[ContractFunction]):
397
393
  self,
398
394
  abi: ABI,
399
395
  w3: "Web3",
400
- address: Optional[ChecksumAddress] = None,
401
- decode_tuples: Optional[bool] = False,
396
+ address: ChecksumAddress | None = None,
397
+ decode_tuples: bool | None = False,
402
398
  ) -> None:
403
399
  super().__init__(abi, w3, ContractFunction, address, decode_tuples)
404
400
 
@@ -412,7 +408,7 @@ class Contract(BaseContract):
412
408
  # Instance of :class:`ContractEvents` presenting available Event ABIs
413
409
  events: ContractEvents = None
414
410
 
415
- def __init__(self, address: Optional[ChecksumAddress] = None) -> None:
411
+ def __init__(self, address: ChecksumAddress | None = None) -> None:
416
412
  """
417
413
  Create a new smart contract proxy object.
418
414
  :param address: Contract address as 0x hex string
@@ -459,8 +455,8 @@ class Contract(BaseContract):
459
455
 
460
456
  @classmethod
461
457
  def factory(
462
- cls, w3: "Web3", class_name: Optional[str] = None, **kwargs: Any
463
- ) -> Type[Self]:
458
+ cls, w3: "Web3", class_name: str | None = None, **kwargs: Any
459
+ ) -> type[Self]:
464
460
  kwargs["w3"] = w3
465
461
 
466
462
  normalizers = {
@@ -472,7 +468,7 @@ class Contract(BaseContract):
472
468
  }
473
469
 
474
470
  contract = cast(
475
- Type[Self],
471
+ type[Self],
476
472
  PropertyCheckingFactory(
477
473
  class_name or cls.__name__,
478
474
  (cls,),
@@ -536,9 +532,9 @@ class Contract(BaseContract):
536
532
  w3: "Web3",
537
533
  address: ChecksumAddress,
538
534
  callable_check: Callable[..., Any],
539
- ) -> List["ContractFunction"]:
535
+ ) -> list["ContractFunction"]:
540
536
  return cast(
541
- List["ContractFunction"],
537
+ list["ContractFunction"],
542
538
  find_functions_by_identifier(
543
539
  contract_abi, w3, address, callable_check, ContractFunction
544
540
  ),
@@ -557,7 +553,7 @@ class Contract(BaseContract):
557
553
  w3: "Web3",
558
554
  address: ChecksumAddress,
559
555
  callable_check: Callable[..., Any],
560
- ) -> List["ContractEvent"]:
556
+ ) -> list["ContractEvent"]:
561
557
  return find_events_by_identifier(
562
558
  contract_abi, w3, address, callable_check, ContractEvent
563
559
  )
@@ -578,11 +574,11 @@ class ContractCaller(BaseContractCaller):
578
574
  abi: ABI,
579
575
  w3: "Web3",
580
576
  address: ChecksumAddress,
581
- transaction: Optional[TxParams] = None,
577
+ transaction: TxParams | None = None,
582
578
  block_identifier: BlockIdentifier = None,
583
- ccip_read_enabled: Optional[bool] = None,
584
- decode_tuples: Optional[bool] = False,
585
- contract_functions: Optional[ContractFunctions] = None,
579
+ ccip_read_enabled: bool | None = None,
580
+ decode_tuples: bool | None = False,
581
+ contract_functions: ContractFunctions | None = None,
586
582
  ) -> None:
587
583
  super().__init__(abi, w3, address, decode_tuples=decode_tuples)
588
584
 
@@ -608,9 +604,9 @@ class ContractCaller(BaseContractCaller):
608
604
 
609
605
  def __call__(
610
606
  self,
611
- transaction: Optional[TxParams] = None,
607
+ transaction: TxParams | None = None,
612
608
  block_identifier: BlockIdentifier = None,
613
- ccip_read_enabled: Optional[bool] = None,
609
+ ccip_read_enabled: bool | None = None,
614
610
  ) -> "ContractCaller":
615
611
  if transaction is None:
616
612
  transaction = {}
@@ -631,11 +627,11 @@ class ContractConstructor(BaseContractConstructor):
631
627
  w3: "Web3"
632
628
 
633
629
  @combomethod
634
- def transact(self, transaction: Optional[TxParams] = None) -> HexBytes:
630
+ def transact(self, transaction: TxParams | None = None) -> HexBytes:
635
631
  return self.w3.eth.send_transaction(self._get_transaction(transaction))
636
632
 
637
633
  @combomethod
638
- def build_transaction(self, transaction: Optional[TxParams] = None) -> TxParams:
634
+ def build_transaction(self, transaction: TxParams | None = None) -> TxParams:
639
635
  """
640
636
  Build the transaction dictionary without sending
641
637
  """
@@ -645,8 +641,8 @@ class ContractConstructor(BaseContractConstructor):
645
641
  @combomethod
646
642
  def estimate_gas(
647
643
  self,
648
- transaction: Optional[TxParams] = None,
649
- block_identifier: Optional[BlockIdentifier] = None,
644
+ transaction: TxParams | None = None,
645
+ block_identifier: BlockIdentifier | None = None,
650
646
  ) -> int:
651
647
  transaction = self._estimate_gas(transaction)
652
648
 
web3/contract/utils.py CHANGED
@@ -3,11 +3,7 @@ from typing import (
3
3
  TYPE_CHECKING,
4
4
  Any,
5
5
  Callable,
6
- List,
7
- Optional,
8
6
  Sequence,
9
- Tuple,
10
- Type,
11
7
  Union,
12
8
  cast,
13
9
  )
@@ -89,7 +85,7 @@ def format_contract_call_return_data_curried(
89
85
  decode_tuples: bool,
90
86
  fn_abi: ABICallable,
91
87
  abi_element_identifier: ABIElementIdentifier,
92
- normalizers: Tuple[Callable[..., Any], ...],
88
+ normalizers: tuple[Callable[..., Any], ...],
93
89
  output_types: Sequence[TypeStr],
94
90
  return_data: Any,
95
91
  ) -> Any:
@@ -123,15 +119,15 @@ def format_contract_call_return_data_curried(
123
119
  def call_contract_function(
124
120
  w3: "Web3",
125
121
  address: ChecksumAddress,
126
- normalizers: Tuple[Callable[..., Any], ...],
122
+ normalizers: tuple[Callable[..., Any], ...],
127
123
  abi_element_identifier: ABIElementIdentifier,
128
124
  transaction: TxParams,
129
- block_id: Optional[BlockIdentifier] = None,
130
- contract_abi: Optional[ABI] = None,
131
- abi_callable: Optional[ABICallable] = None,
132
- state_override: Optional[StateOverride] = None,
133
- ccip_read_enabled: Optional[bool] = None,
134
- decode_tuples: Optional[bool] = False,
125
+ block_id: BlockIdentifier | None = None,
126
+ contract_abi: ABI | None = None,
127
+ abi_callable: ABICallable | None = None,
128
+ state_override: StateOverride | None = None,
129
+ ccip_read_enabled: bool | None = None,
130
+ decode_tuples: bool | None = False,
135
131
  *args: Any,
136
132
  **kwargs: Any,
137
133
  ) -> Any:
@@ -240,10 +236,10 @@ def call_contract_function(
240
236
  def transact_with_contract_function(
241
237
  address: ChecksumAddress,
242
238
  w3: "Web3",
243
- abi_element_identifier: Optional[ABIElementIdentifier] = None,
244
- transaction: Optional[TxParams] = None,
245
- contract_abi: Optional[ABI] = None,
246
- fn_abi: Optional[ABIFunction] = None,
239
+ abi_element_identifier: ABIElementIdentifier | None = None,
240
+ transaction: TxParams | None = None,
241
+ contract_abi: ABI | None = None,
242
+ fn_abi: ABIFunction | None = None,
247
243
  *args: Any,
248
244
  **kwargs: Any,
249
245
  ) -> HexBytes:
@@ -269,12 +265,12 @@ def transact_with_contract_function(
269
265
  def estimate_gas_for_function(
270
266
  address: ChecksumAddress,
271
267
  w3: "Web3",
272
- abi_element_identifier: Optional[ABIElementIdentifier] = None,
273
- transaction: Optional[TxParams] = None,
274
- contract_abi: Optional[ABI] = None,
275
- fn_abi: Optional[ABIFunction] = None,
276
- block_identifier: Optional[BlockIdentifier] = None,
277
- state_override: Optional[StateOverride] = None,
268
+ abi_element_identifier: ABIElementIdentifier | None = None,
269
+ transaction: TxParams | None = None,
270
+ contract_abi: ABI | None = None,
271
+ fn_abi: ABIFunction | None = None,
272
+ block_identifier: BlockIdentifier | None = None,
273
+ state_override: StateOverride | None = None,
278
274
  *args: Any,
279
275
  **kwargs: Any,
280
276
  ) -> int:
@@ -301,10 +297,10 @@ def estimate_gas_for_function(
301
297
  def build_transaction_for_function(
302
298
  address: ChecksumAddress,
303
299
  w3: "Web3",
304
- abi_element_identifier: Optional[ABIElementIdentifier] = None,
305
- transaction: Optional[TxParams] = None,
306
- contract_abi: Optional[ABI] = None,
307
- fn_abi: Optional[ABIFunction] = None,
300
+ abi_element_identifier: ABIElementIdentifier | None = None,
301
+ transaction: TxParams | None = None,
302
+ contract_abi: ABI | None = None,
303
+ fn_abi: ABIFunction | None = None,
308
304
  *args: Any,
309
305
  **kwargs: Any,
310
306
  ) -> TxParams:
@@ -335,8 +331,8 @@ def find_functions_by_identifier(
335
331
  w3: Union["Web3", "AsyncWeb3[Any]"],
336
332
  address: ChecksumAddress,
337
333
  callable_check: Callable[..., Any],
338
- function_type: Type[TContractFn],
339
- ) -> List[TContractFn]:
334
+ function_type: type[TContractFn],
335
+ ) -> list[TContractFn]:
340
336
  """
341
337
  Given a contract ABI, return a list of TContractFunction instances.
342
338
  """
@@ -379,8 +375,8 @@ def find_events_by_identifier(
379
375
  w3: Union["Web3", "AsyncWeb3[Any]"],
380
376
  address: ChecksumAddress,
381
377
  callable_check: Callable[..., Any],
382
- event_type: Type[TContractEvent],
383
- ) -> List[TContractEvent]:
378
+ event_type: type[TContractEvent],
379
+ ) -> list[TContractEvent]:
384
380
  """
385
381
  Given a contract ABI, return a list of TContractEvent instances.
386
382
  """
@@ -420,15 +416,15 @@ def get_event_by_identifier(
420
416
  async def async_call_contract_function(
421
417
  async_w3: "AsyncWeb3[Any]",
422
418
  address: ChecksumAddress,
423
- normalizers: Tuple[Callable[..., Any], ...],
419
+ normalizers: tuple[Callable[..., Any], ...],
424
420
  abi_element_identifier: ABIElementIdentifier,
425
421
  transaction: TxParams,
426
- block_id: Optional[BlockIdentifier] = None,
427
- contract_abi: Optional[ABI] = None,
428
- fn_abi: Optional[ABIFunction] = None,
429
- state_override: Optional[StateOverride] = None,
430
- ccip_read_enabled: Optional[bool] = None,
431
- decode_tuples: Optional[bool] = False,
422
+ block_id: BlockIdentifier | None = None,
423
+ contract_abi: ABI | None = None,
424
+ fn_abi: ABIFunction | None = None,
425
+ state_override: StateOverride | None = None,
426
+ ccip_read_enabled: bool | None = None,
427
+ decode_tuples: bool | None = False,
432
428
  *args: Any,
433
429
  **kwargs: Any,
434
430
  ) -> Any:
@@ -535,10 +531,10 @@ async def async_call_contract_function(
535
531
  async def async_transact_with_contract_function(
536
532
  address: ChecksumAddress,
537
533
  async_w3: "AsyncWeb3[Any]",
538
- abi_element_identifier: Optional[ABIElementIdentifier] = None,
539
- transaction: Optional[TxParams] = None,
540
- contract_abi: Optional[ABI] = None,
541
- fn_abi: Optional[ABIFunction] = None,
534
+ abi_element_identifier: ABIElementIdentifier | None = None,
535
+ transaction: TxParams | None = None,
536
+ contract_abi: ABI | None = None,
537
+ fn_abi: ABIFunction | None = None,
542
538
  *args: Any,
543
539
  **kwargs: Any,
544
540
  ) -> HexBytes:
@@ -564,12 +560,12 @@ async def async_transact_with_contract_function(
564
560
  async def async_estimate_gas_for_function(
565
561
  address: ChecksumAddress,
566
562
  async_w3: "AsyncWeb3[Any]",
567
- abi_element_identifier: Optional[ABIElementIdentifier] = None,
568
- transaction: Optional[TxParams] = None,
569
- contract_abi: Optional[ABI] = None,
570
- fn_abi: Optional[ABIFunction] = None,
571
- block_identifier: Optional[BlockIdentifier] = None,
572
- state_override: Optional[StateOverride] = None,
563
+ abi_element_identifier: ABIElementIdentifier | None = None,
564
+ transaction: TxParams | None = None,
565
+ contract_abi: ABI | None = None,
566
+ fn_abi: ABIFunction | None = None,
567
+ block_identifier: BlockIdentifier | None = None,
568
+ state_override: StateOverride | None = None,
573
569
  *args: Any,
574
570
  **kwargs: Any,
575
571
  ) -> int:
@@ -598,10 +594,10 @@ async def async_estimate_gas_for_function(
598
594
  async def async_build_transaction_for_function(
599
595
  address: ChecksumAddress,
600
596
  async_w3: "AsyncWeb3[Any]",
601
- abi_element_identifier: Optional[ABIElementIdentifier] = None,
602
- transaction: Optional[TxParams] = None,
603
- contract_abi: Optional[ABI] = None,
604
- fn_abi: Optional[ABIFunction] = None,
597
+ abi_element_identifier: ABIElementIdentifier | None = None,
598
+ transaction: TxParams | None = None,
599
+ contract_abi: ABI | None = None,
600
+ fn_abi: ABIFunction | None = None,
605
601
  *args: Any,
606
602
  **kwargs: Any,
607
603
  ) -> TxParams:
web3/datastructures.py CHANGED
@@ -2,22 +2,17 @@ from collections import (
2
2
  OrderedDict,
3
3
  )
4
4
  from collections.abc import (
5
- Hashable,
5
+ MutableMapping,
6
+ ValuesView,
6
7
  )
7
8
  from typing import (
8
9
  Any,
9
10
  Callable,
10
- Dict,
11
+ Hashable,
11
12
  Iterator,
12
- List,
13
13
  Mapping,
14
- MutableMapping,
15
- Optional,
16
14
  Sequence,
17
- Tuple,
18
15
  TypeVar,
19
- Union,
20
- ValuesView,
21
16
  cast,
22
17
  )
23
18
 
@@ -47,7 +42,7 @@ class ReadableAttributeDict(Mapping[TKey, TValue]):
47
42
  """
48
43
 
49
44
  def __init__(
50
- self, dictionary: Dict[TKey, TValue], *args: Any, **kwargs: Any
45
+ self, dictionary: dict[TKey, TValue], *args: Any, **kwargs: Any
51
46
  ) -> None:
52
47
  # type ignored on 46/50 b/c dict() expects str index type not TKey
53
48
  self.__dict__ = dict(dictionary) # type: ignore
@@ -139,7 +134,7 @@ def tupleize_lists_nested(d: Mapping[TKey, TValue]) -> AttributeDict[TKey, TValu
139
134
  Other unhashable types found will raise a TypeError
140
135
  """
141
136
 
142
- def _to_tuple(value: Union[List[Any], Tuple[Any, ...]]) -> Any:
137
+ def _to_tuple(value: list[Any] | tuple[Any, ...]) -> Any:
143
138
  return tuple(_to_tuple(i) if isinstance(i, (list, tuple)) else i for i in value)
144
139
 
145
140
  ret = dict()
@@ -174,7 +169,7 @@ class NamedElementOnion(Mapping[TKey, TValue]):
174
169
  else:
175
170
  self.add(*element)
176
171
 
177
- def add(self, element: TValue, name: Optional[TKey] = None) -> None:
172
+ def add(self, element: TValue, name: TKey | None = None) -> None:
178
173
  if name is None:
179
174
  name = cast(TKey, element)
180
175
 
@@ -191,7 +186,7 @@ class NamedElementOnion(Mapping[TKey, TValue]):
191
186
  self._queue[name] = element
192
187
 
193
188
  def inject(
194
- self, element: TValue, name: Optional[TKey] = None, layer: Optional[int] = None
189
+ self, element: TValue, name: TKey | None = None, layer: int | None = None
195
190
  ) -> None:
196
191
  """
197
192
  Inject a named element to an arbitrary layer in the onion.
@@ -296,7 +291,7 @@ class NamedElementOnion(Mapping[TKey, TValue]):
296
291
  return NotImplemented
297
292
  combined = self._queue.copy()
298
293
  combined.update(other._queue)
299
- return NamedElementOnion(cast(List[Any], combined.items()))
294
+ return NamedElementOnion(cast(list[Any], combined.items()))
300
295
 
301
296
  def __contains__(self, element: Any) -> bool:
302
297
  element_name = self._build_name(element)
@@ -310,7 +305,7 @@ class NamedElementOnion(Mapping[TKey, TValue]):
310
305
  return len(self._queue)
311
306
 
312
307
  def __reversed__(self) -> Iterator[TValue]:
313
- elements = cast(List[Any], self._queue.values())
308
+ elements = cast(list[Any], self._queue.values())
314
309
  if not isinstance(elements, Sequence):
315
310
  elements = list(elements)
316
311
  return iter(elements)
@@ -324,7 +319,7 @@ class NamedElementOnion(Mapping[TKey, TValue]):
324
319
  elements = list(elements) # type: ignore
325
320
  return reversed(elements)
326
321
 
327
- def as_tuple_of_middleware(self) -> Tuple[TValue, ...]:
322
+ def as_tuple_of_middleware(self) -> tuple[TValue, ...]:
328
323
  """
329
324
  Helps with type hinting since we return `Iterator[TKey]` type, though it's
330
325
  actually a `Iterator[TValue]` type, for the `__iter__()` method. This is in