web3 7.14.1__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 (99) 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 -22
  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 +50 -54
  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 +17 -20
  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 +51 -58
  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.1.dist-info → web3-8.0.0b1.dist-info}/METADATA +10 -9
  93. web3-8.0.0b1.dist-info/RECORD +170 -0
  94. {web3-7.14.1.dist-info → web3-8.0.0b1.dist-info}/WHEEL +1 -1
  95. ens/specs/.DS_Store +0 -0
  96. web3/providers/legacy_websocket.py +0 -159
  97. web3-7.14.1.dist-info/RECORD +0 -172
  98. {web3-7.14.1.dist-info → web3-8.0.0b1.dist-info}/licenses/LICENSE +0 -0
  99. {web3-7.14.1.dist-info → web3-8.0.0b1.dist-info}/top_level.txt +0 -0
web3/_utils/abi.py CHANGED
@@ -12,15 +12,9 @@ from typing import (
12
12
  Callable,
13
13
  Collection,
14
14
  Coroutine,
15
- Dict,
16
15
  Iterable,
17
- List,
18
16
  Mapping,
19
- Optional,
20
17
  Sequence,
21
- Tuple,
22
- Type,
23
- Union,
24
18
  cast,
25
19
  )
26
20
 
@@ -114,21 +108,21 @@ def receive_func_abi_exists(contract_abi: ABI) -> Sequence[ABIReceive]:
114
108
  return filter_abi_by_type("receive", contract_abi)
115
109
 
116
110
 
117
- def get_indexed_event_inputs(event_abi: ABIEvent) -> List[ABIComponentIndexed]:
111
+ def get_indexed_event_inputs(event_abi: ABIEvent) -> list[ABIComponentIndexed]:
118
112
  return [arg for arg in event_abi["inputs"] if arg["indexed"] is True]
119
113
 
120
114
 
121
- def exclude_indexed_event_inputs(event_abi: ABIEvent) -> List[ABIComponentIndexed]:
115
+ def exclude_indexed_event_inputs(event_abi: ABIEvent) -> list[ABIComponentIndexed]:
122
116
  return [arg for arg in event_abi["inputs"] if arg["indexed"] is False]
123
117
 
124
118
 
125
- def filter_by_types(types: Collection[str], contract_abi: ABI) -> List[ABIElement]:
119
+ def filter_by_types(types: Collection[str], contract_abi: ABI) -> list[ABIElement]:
126
120
  return [abi_element for abi_element in contract_abi if abi_element["type"] in types]
127
121
 
128
122
 
129
123
  def filter_by_argument_name(
130
124
  argument_names: Collection[str], contract_abi: ABI
131
- ) -> List[ABIElement]:
125
+ ) -> list[ABIElement]:
132
126
  """
133
127
  Return a list of each ``ABIElement`` which contains arguments matching provided
134
128
  names.
@@ -150,7 +144,7 @@ def filter_by_argument_name(
150
144
 
151
145
  def filter_by_argument_type(
152
146
  argument_types: Collection[str], contract_abi: ABI
153
- ) -> List[ABIElement]:
147
+ ) -> list[ABIElement]:
154
148
  """
155
149
  Return a list of each ``ABIElement`` which contains arguments matching provided
156
150
  types.
@@ -185,7 +179,7 @@ def get_name_from_abi_element_identifier(
185
179
 
186
180
  def get_abi_element_signature(
187
181
  abi_element_identifier: ABIElementIdentifier,
188
- abi_element_argument_types: Optional[Iterable[str]] = None,
182
+ abi_element_argument_types: Iterable[str] | None = None,
189
183
  ) -> str:
190
184
  element_name = get_name_from_abi_element_identifier(abi_element_identifier)
191
185
  argument_types = ",".join(abi_element_argument_types or [])
@@ -206,7 +200,7 @@ class AddressEncoder(encoding.AddressEncoder):
206
200
 
207
201
 
208
202
  class AcceptsHexStrEncoder(encoding.BaseEncoder):
209
- subencoder_cls: Type[encoding.BaseEncoder] = None
203
+ subencoder_cls: type[encoding.BaseEncoder] = None
210
204
  is_strict: bool = None
211
205
  is_big_endian: bool = False
212
206
  data_byte_size: int = None
@@ -215,7 +209,7 @@ class AcceptsHexStrEncoder(encoding.BaseEncoder):
215
209
  def __init__(
216
210
  self,
217
211
  subencoder: encoding.BaseEncoder,
218
- **kwargs: Dict[str, Any],
212
+ **kwargs: dict[str, Any],
219
213
  ) -> None:
220
214
  super().__init__(**kwargs) # type: ignore[no-untyped-call]
221
215
  self.subencoder = subencoder
@@ -234,7 +228,7 @@ class AcceptsHexStrEncoder(encoding.BaseEncoder):
234
228
  return cls(subencoder)
235
229
 
236
230
  @classmethod
237
- def get_subencoder_class(cls) -> Type[encoding.BaseEncoder]:
231
+ def get_subencoder_class(cls) -> type[encoding.BaseEncoder]:
238
232
  if cls.subencoder_cls is None:
239
233
  raise Web3AttributeError(f"No subencoder class is set. {cls.__name__}")
240
234
  return cls.subencoder_cls
@@ -358,7 +352,7 @@ class TextStringEncoder(encoding.TextStringEncoder):
358
352
  TUPLE_TYPE_STR_RE = re.compile(r"^(tuple)((\[([1-9]\d*\b)?])*)??$")
359
353
 
360
354
 
361
- def get_tuple_type_str_parts(s: str) -> Optional[Tuple[str, Optional[str]]]:
355
+ def get_tuple_type_str_parts(s: str) -> tuple[str, str | None] | None:
362
356
  """
363
357
  Takes a JSON ABI type string. For tuple type strings, returns the separated
364
358
  prefix and array dimension parts. For all other strings, returns ``None``.
@@ -375,8 +369,8 @@ def get_tuple_type_str_parts(s: str) -> Optional[Tuple[str, Optional[str]]]:
375
369
 
376
370
 
377
371
  def _align_abi_input(
378
- arg_abi: Union[ABIComponent, ABIComponentIndexed], arg: Any
379
- ) -> Tuple[Any, ...]:
372
+ arg_abi: ABIComponent | ABIComponentIndexed, arg: Any
373
+ ) -> tuple[Any, ...]:
380
374
  """
381
375
  Aligns the values of any mapping at any level of nesting in ``arg``
382
376
  according to the layout of the corresponding abi spec.
@@ -565,7 +559,7 @@ def is_probably_enum(abi_type: TypeStr) -> bool:
565
559
  @to_tuple
566
560
  def normalize_event_input_types(
567
561
  abi_args: Collection[ABIEvent],
568
- ) -> Iterable[Union[ABIEvent, Dict[TypeStr, Any]]]:
562
+ ) -> Iterable[ABIEvent | dict[TypeStr, Any]]:
569
563
  for arg in abi_args:
570
564
  if is_recognized_type(arg["type"]):
571
565
  yield arg
@@ -584,7 +578,7 @@ def normalize_event_input_types(
584
578
 
585
579
  @curry
586
580
  def map_abi_data(
587
- normalizers: Iterable[Callable[[TypeStr, Any], Tuple[TypeStr, Any]]],
581
+ normalizers: Iterable[Callable[[TypeStr, Any], tuple[TypeStr, Any]]],
588
582
  types: Iterable[TypeStr],
589
583
  data: Iterable[Any],
590
584
  ) -> Any:
@@ -624,7 +618,7 @@ def map_abi_data(
624
618
  @curry
625
619
  def abi_data_tree(
626
620
  types: Iterable[TypeStr], data: Iterable[Any]
627
- ) -> List["ABITypedData"]:
621
+ ) -> list["ABITypedData"]:
628
622
  """
629
623
  Decorate the data tree with pairs of (type, data). The pair tuple is actually an
630
624
  ABITypedData, but can be accessed as a tuple.
@@ -639,7 +633,7 @@ def abi_data_tree(
639
633
 
640
634
  @curry
641
635
  def data_tree_map(
642
- func: Callable[[TypeStr, Any], Tuple[TypeStr, Any]], data_tree: Any
636
+ func: Callable[[TypeStr, Any], tuple[TypeStr, Any]], data_tree: Any
643
637
  ) -> "ABITypedData":
644
638
  """
645
639
  Map func to every ABITypedData element in the tree. func will
@@ -679,7 +673,7 @@ class ABITypedData(namedtuple("ABITypedData", "abi_type, data")):
679
673
 
680
674
 
681
675
  def abi_sub_tree(
682
- type_str_or_abi_type: Optional[Union[TypeStr, ABIType]], data_value: Any
676
+ type_str_or_abi_type: TypeStr | ABIType | None, data_value: Any
683
677
  ) -> ABITypedData:
684
678
  if type_str_or_abi_type is None:
685
679
  return ABITypedData([None, data_value])
@@ -801,12 +795,16 @@ def build_strict_registry() -> ABIRegistry:
801
795
 
802
796
  def named_tree(
803
797
  abi: Iterable[
804
- Union[
805
- ABIComponent, ABIComponentIndexed, ABIFunction, ABIEvent, Dict[TypeStr, Any]
806
- ]
798
+ (
799
+ ABIComponent
800
+ | ABIComponentIndexed
801
+ | ABIFunction
802
+ | ABIEvent
803
+ | dict[TypeStr, Any]
804
+ )
807
805
  ],
808
- data: Iterable[Tuple[Any, ...]],
809
- ) -> Dict[str, Any]:
806
+ data: Iterable[tuple[Any, ...]],
807
+ ) -> dict[str, Any]:
810
808
  """
811
809
  Convert function inputs/outputs or event data tuple to dict with names from ABI.
812
810
  """
@@ -817,12 +815,12 @@ def named_tree(
817
815
 
818
816
 
819
817
  def _named_subtree(
820
- abi: Union[
821
- ABIComponent, ABIComponentIndexed, ABIFunction, ABIEvent, Dict[TypeStr, Any]
822
- ],
823
- data: Tuple[Any, ...],
824
- ) -> Union[Dict[str, Any], Tuple[Any, ...], List[Any]]:
825
- abi_type = parse(collapse_if_tuple(cast(Dict[str, Any], abi)))
818
+ abi: (
819
+ ABIComponent | ABIComponentIndexed | ABIFunction | ABIEvent | dict[TypeStr, Any]
820
+ ),
821
+ data: tuple[Any, ...],
822
+ ) -> dict[str, Any] | tuple[Any, ...] | list[Any]:
823
+ abi_type = parse(collapse_if_tuple(cast(dict[str, Any], abi)))
826
824
 
827
825
  if abi_type.is_array:
828
826
  item_type = abi_type.item_type.to_type_str()
@@ -850,10 +848,10 @@ def _named_subtree(
850
848
  return data
851
849
 
852
850
 
853
- def recursive_dict_to_namedtuple(data: Dict[str, Any]) -> Tuple[Any, ...]:
851
+ def recursive_dict_to_namedtuple(data: dict[str, Any]) -> tuple[Any, ...]:
854
852
  def _dict_to_namedtuple(
855
- value: Union[Dict[str, Any], List[Any]],
856
- ) -> Union[Tuple[Any, ...], List[Any]]:
853
+ value: dict[str, Any] | list[Any],
854
+ ) -> tuple[Any, ...] | list[Any]:
857
855
  if not isinstance(value, dict):
858
856
  return value
859
857
 
@@ -864,8 +862,8 @@ def recursive_dict_to_namedtuple(data: Dict[str, Any]) -> Tuple[Any, ...]:
864
862
 
865
863
 
866
864
  def abi_decoded_namedtuple_factory(
867
- fields: Tuple[Any, ...],
868
- ) -> Callable[..., Tuple[Any, ...]]:
865
+ fields: tuple[Any, ...],
866
+ ) -> Callable[..., tuple[Any, ...]]:
869
867
  class ABIDecodedNamedTuple(namedtuple("ABIDecodedNamedTuple", fields, rename=True)): # type: ignore # noqa: E501
870
868
  def __new__(self, args: Any) -> "ABIDecodedNamedTuple":
871
869
  return super().__new__(self, *args)
@@ -879,7 +877,7 @@ def abi_decoded_namedtuple_factory(
879
877
  async def async_data_tree_map(
880
878
  async_w3: "AsyncWeb3[Any]",
881
879
  func: Callable[
882
- ["AsyncWeb3[Any]", TypeStr, Any], Coroutine[Any, Any, Tuple[TypeStr, Any]]
880
+ ["AsyncWeb3[Any]", TypeStr, Any], Coroutine[Any, Any, tuple[TypeStr, Any]]
883
881
  ],
884
882
  data_tree: Any,
885
883
  ) -> "ABITypedData":
@@ -1,9 +1,6 @@
1
1
  from typing import (
2
2
  TYPE_CHECKING,
3
3
  Any,
4
- Dict,
5
- Optional,
6
- Union,
7
4
  cast,
8
5
  )
9
6
 
@@ -47,13 +44,13 @@ if TYPE_CHECKING:
47
44
 
48
45
  # unused vars present in these funcs because they all need to have the same signature
49
46
  async def _estimate_gas(
50
- async_w3: "AsyncWeb3[Any]", tx: TxParams, _defaults: Dict[str, Union[bytes, int]]
47
+ async_w3: "AsyncWeb3[Any]", tx: TxParams, _defaults: dict[str, bytes | int]
51
48
  ) -> int:
52
49
  return await async_w3.eth.estimate_gas(tx)
53
50
 
54
51
 
55
52
  async def _max_fee_per_gas(
56
- async_w3: "AsyncWeb3[Any]", tx: TxParams, defaults: Dict[str, Union[bytes, int]]
53
+ async_w3: "AsyncWeb3[Any]", tx: TxParams, defaults: dict[str, bytes | int]
57
54
  ) -> Wei:
58
55
  block = await async_w3.eth.get_block("latest")
59
56
  max_priority_fee = tx.get(
@@ -63,13 +60,13 @@ async def _max_fee_per_gas(
63
60
 
64
61
 
65
62
  async def _max_priority_fee_gas(
66
- async_w3: "AsyncWeb3[Any]", _tx: TxParams, _defaults: Dict[str, Union[bytes, int]]
63
+ async_w3: "AsyncWeb3[Any]", _tx: TxParams, _defaults: dict[str, bytes | int]
67
64
  ) -> Wei:
68
65
  return await async_w3.eth.max_priority_fee
69
66
 
70
67
 
71
68
  async def _chain_id(
72
- async_w3: "AsyncWeb3[Any]", _tx: TxParams, _defaults: Dict[str, Union[bytes, int]]
69
+ async_w3: "AsyncWeb3[Any]", _tx: TxParams, _defaults: dict[str, bytes | int]
73
70
  ) -> int:
74
71
  return await async_w3.eth.chain_id
75
72
 
@@ -86,7 +83,7 @@ TRANSACTION_DEFAULTS = {
86
83
 
87
84
 
88
85
  async def get_block_gas_limit(
89
- web3_eth: "AsyncEth", block_identifier: Optional[BlockIdentifier] = None
86
+ web3_eth: "AsyncEth", block_identifier: BlockIdentifier | None = None
90
87
  ) -> int:
91
88
  block = await web3_eth.get_block(block_identifier or "latest")
92
89
  return block["gasLimit"]
@@ -136,7 +133,7 @@ async def async_fill_transaction_defaults(
136
133
  or any_in_dict(DYNAMIC_FEE_TXN_PARAMS, transaction)
137
134
  )
138
135
 
139
- defaults: Dict[str, Union[bytes, int]] = {}
136
+ defaults: dict[str, bytes | int] = {}
140
137
  for key, default_getter in TRANSACTION_DEFAULTS.items():
141
138
  if key not in transaction:
142
139
  if (
web3/_utils/batching.py CHANGED
@@ -6,11 +6,7 @@ from typing import (
6
6
  Any,
7
7
  Callable,
8
8
  Coroutine,
9
- Dict,
10
9
  Generic,
11
- List,
12
- Tuple,
13
- Type,
14
10
  Union,
15
11
  cast,
16
12
  )
@@ -58,7 +54,7 @@ if TYPE_CHECKING:
58
54
 
59
55
  BATCH_REQUEST_ID = "batch_request" # for use as the cache key for batch requests
60
56
 
61
- BatchRequestInformation = Tuple[Tuple["RPCEndpoint", Any], Tuple[Any, ...]]
57
+ BatchRequestInformation = tuple[tuple["RPCEndpoint", Any], tuple[Any, ...]]
62
58
  RPC_METHODS_UNSUPPORTED_DURING_BATCH = {
63
59
  "eth_subscribe",
64
60
  "eth_unsubscribe",
@@ -73,8 +69,8 @@ RPC_METHODS_UNSUPPORTED_DURING_BATCH = {
73
69
  class RequestBatcher(Generic[TFunc]):
74
70
  def __init__(self, web3: Union["AsyncWeb3[Any]", "Web3"]) -> None:
75
71
  self.web3 = web3
76
- self._requests_info: List[BatchRequestInformation] = []
77
- self._async_requests_info: List[
72
+ self._requests_info: list[BatchRequestInformation] = []
73
+ self._async_requests_info: list[
78
74
  Coroutine[Any, Any, BatchRequestInformation]
79
75
  ] = []
80
76
  self._initialize_batching()
@@ -120,14 +116,14 @@ class RequestBatcher(Generic[TFunc]):
120
116
 
121
117
  def add_mapping(
122
118
  self,
123
- batch_payload: Dict[
119
+ batch_payload: dict[
124
120
  Union[
125
121
  "Method[Callable[..., Any]]",
126
122
  Callable[..., Any],
127
123
  "ContractFunction",
128
124
  "AsyncContractFunction",
129
125
  ],
130
- List[Any],
126
+ list[Any],
131
127
  ],
132
128
  ) -> None:
133
129
  self._validate_is_batching()
@@ -135,7 +131,7 @@ class RequestBatcher(Generic[TFunc]):
135
131
  for param in params:
136
132
  self.add(method(param))
137
133
 
138
- def execute(self) -> List["RPCResponse"]:
134
+ def execute(self) -> list["RPCResponse"]:
139
135
  self._validate_is_batching()
140
136
  responses = self.web3.manager._make_batch_request(self._requests_info)
141
137
  self._end_batching()
@@ -156,7 +152,7 @@ class RequestBatcher(Generic[TFunc]):
156
152
 
157
153
  def __exit__(
158
154
  self,
159
- exc_type: Type[BaseException],
155
+ exc_type: type[BaseException],
160
156
  exc_val: BaseException,
161
157
  exc_tb: TracebackType,
162
158
  ) -> None:
@@ -164,7 +160,7 @@ class RequestBatcher(Generic[TFunc]):
164
160
 
165
161
  # -- async -- #
166
162
 
167
- async def async_execute(self) -> List["RPCResponse"]:
163
+ async def async_execute(self) -> list["RPCResponse"]:
168
164
  self._validate_is_batching()
169
165
  if self._provider.has_persistent_connection:
170
166
  responses = await self.web3.manager._async_make_socket_batch_request(
@@ -185,7 +181,7 @@ class RequestBatcher(Generic[TFunc]):
185
181
 
186
182
  async def __aexit__(
187
183
  self,
188
- exc_type: Type[BaseException],
184
+ exc_type: type[BaseException],
189
185
  exc_val: BaseException,
190
186
  exc_tb: TracebackType,
191
187
  ) -> None:
@@ -193,8 +189,8 @@ class RequestBatcher(Generic[TFunc]):
193
189
 
194
190
 
195
191
  def sort_batch_response_by_response_ids(
196
- responses: List["RPCResponse"],
197
- ) -> List["RPCResponse"]:
192
+ responses: list["RPCResponse"],
193
+ ) -> list["RPCResponse"]:
198
194
  if all(response.get("id") is not None for response in responses):
199
195
  # If all responses have an `id`, sort them by `id`, since the JSON-RPC 2.0 spec
200
196
  # doesn't guarantee order.
web3/_utils/blocks.py CHANGED
@@ -1,6 +1,5 @@
1
1
  from typing import (
2
2
  Any,
3
- Optional,
4
3
  )
5
4
 
6
5
  from eth_utils import (
@@ -62,7 +61,7 @@ def is_hex_encoded_block_number(value: Any) -> bool:
62
61
  @curry
63
62
  def select_method_for_block_identifier(
64
63
  value: Any, if_hash: RPCEndpoint, if_number: RPCEndpoint, if_predefined: RPCEndpoint
65
- ) -> Optional[RPCEndpoint]:
64
+ ) -> RPCEndpoint | None:
66
65
  if is_predefined_block_number(value):
67
66
  return if_predefined
68
67
  elif isinstance(value, bytes):
@@ -1,18 +1,13 @@
1
- from asyncio import (
2
- iscoroutinefunction,
3
- )
4
1
  import collections
5
2
  import hashlib
3
+ import inspect
6
4
  import threading
7
5
  from typing import (
8
6
  TYPE_CHECKING,
9
7
  Any,
10
8
  Callable,
11
9
  Coroutine,
12
- Dict,
13
- List,
14
10
  Sequence,
15
- Tuple,
16
11
  Union,
17
12
  )
18
13
 
@@ -99,8 +94,8 @@ class RequestInformation:
99
94
  self,
100
95
  method: RPCEndpoint,
101
96
  params: Any,
102
- response_formatters: Tuple[
103
- Union[Dict[str, Callable[..., Any]], Callable[..., Any]],
97
+ response_formatters: tuple[
98
+ dict[str, Callable[..., Any]] | Callable[..., Any],
104
99
  Callable[..., Any],
105
100
  Callable[..., Any],
106
101
  ],
@@ -110,13 +105,13 @@ class RequestInformation:
110
105
  self.params = params
111
106
  self.response_formatters = response_formatters
112
107
  self.subscription_id = subscription_id
113
- self.middleware_response_processors: List[Callable[..., Any]] = []
108
+ self.middleware_response_processors: list[Callable[..., Any]] = []
114
109
 
115
110
 
116
111
  DEFAULT_VALIDATION_THRESHOLD = 60 * 60 # 1 hour
117
112
 
118
- CHAIN_VALIDATION_THRESHOLD_DEFAULTS: Dict[
119
- int, Union[RequestCacheValidationThreshold, int]
113
+ CHAIN_VALIDATION_THRESHOLD_DEFAULTS: dict[
114
+ int, RequestCacheValidationThreshold | int
120
115
  ] = {
121
116
  # Suggested safe values as defaults for each chain. Users can configure a different
122
117
  # value if desired.
@@ -136,7 +131,7 @@ CHAIN_VALIDATION_THRESHOLD_DEFAULTS: Dict[
136
131
 
137
132
 
138
133
  def is_cacheable_request(
139
- provider: Union[ASYNC_PROVIDER_TYPE, SYNC_PROVIDER_TYPE],
134
+ provider: ASYNC_PROVIDER_TYPE | SYNC_PROVIDER_TYPE,
140
135
  method: RPCEndpoint,
141
136
  params: Any,
142
137
  ) -> bool:
@@ -176,10 +171,10 @@ BLOCKHASH_IN_PARAMS = {
176
171
  RPC.eth_getUncleCountByBlockHash,
177
172
  }
178
173
 
179
- INTERNAL_VALIDATION_MAP: Dict[
174
+ INTERNAL_VALIDATION_MAP: dict[
180
175
  RPCEndpoint,
181
176
  Callable[
182
- [SYNC_PROVIDER_TYPE, Sequence[Any], Dict[str, Any]],
177
+ [SYNC_PROVIDER_TYPE, Sequence[Any], dict[str, Any]],
183
178
  bool,
184
179
  ],
185
180
  ] = {
@@ -268,11 +263,11 @@ def handle_request_caching(
268
263
  # -- async -- #
269
264
 
270
265
  ASYNC_VALIDATOR_TYPE = Callable[
271
- ["AsyncBaseProvider", Sequence[Any], Dict[str, Any]],
266
+ ["AsyncBaseProvider", Sequence[Any], dict[str, Any]],
272
267
  Union[bool, Coroutine[Any, Any, bool]],
273
268
  ]
274
269
 
275
- ASYNC_INTERNAL_VALIDATION_MAP: Dict[RPCEndpoint, ASYNC_VALIDATOR_TYPE] = {
270
+ ASYNC_INTERNAL_VALIDATION_MAP: dict[RPCEndpoint, ASYNC_VALIDATOR_TYPE] = {
276
271
  **{endpoint: always_cache_request for endpoint in ALWAYS_CACHE},
277
272
  **{
278
273
  endpoint: async_validate_from_block_id_in_params
@@ -333,7 +328,7 @@ async def _async_should_cache_response(
333
328
  cache_validator = ASYNC_INTERNAL_VALIDATION_MAP[method]
334
329
  return (
335
330
  await cache_validator(provider, params, result)
336
- if iscoroutinefunction(cache_validator)
331
+ if inspect.iscoroutinefunction(cache_validator)
337
332
  else cache_validator(provider, params, result)
338
333
  )
339
334
  return True
@@ -2,10 +2,8 @@ import time
2
2
  from typing import (
3
3
  TYPE_CHECKING,
4
4
  Any,
5
- Dict,
6
5
  Sequence,
7
6
  TypeVar,
8
- Union,
9
7
  )
10
8
 
11
9
  from web3.types import (
@@ -29,7 +27,7 @@ SYNC_PROVIDER_TYPE = TypeVar("SYNC_PROVIDER_TYPE", bound="BaseProvider")
29
27
 
30
28
 
31
29
  def _error_log(
32
- provider: Union[ASYNC_PROVIDER_TYPE, SYNC_PROVIDER_TYPE], e: Exception
30
+ provider: ASYNC_PROVIDER_TYPE | SYNC_PROVIDER_TYPE, e: Exception
33
31
  ) -> None:
34
32
  provider.logger.error(
35
33
  "There was an exception while caching the request.", exc_info=e
@@ -87,7 +85,7 @@ def is_beyond_validation_threshold(
87
85
  def validate_from_block_id_in_params(
88
86
  provider: SYNC_PROVIDER_TYPE,
89
87
  params: Sequence[Any],
90
- _result: Dict[str, Any],
88
+ _result: dict[str, Any],
91
89
  ) -> bool:
92
90
  block_id = params[0]
93
91
  if block_id == "earliest":
@@ -101,7 +99,7 @@ def validate_from_block_id_in_params(
101
99
  def validate_from_blocknum_in_result(
102
100
  provider: SYNC_PROVIDER_TYPE,
103
101
  _params: Sequence[Any],
104
- result: Dict[str, Any],
102
+ result: dict[str, Any],
105
103
  ) -> bool:
106
104
  cache_allowed_requests = provider.cache_allowed_requests
107
105
  try:
@@ -143,7 +141,7 @@ def validate_from_blocknum_in_result(
143
141
  def validate_from_blockhash_in_params(
144
142
  provider: SYNC_PROVIDER_TYPE,
145
143
  params: Sequence[Any],
146
- _result: Dict[str, Any],
144
+ _result: dict[str, Any],
147
145
  ) -> bool:
148
146
  cache_allowed_requests = provider.cache_allowed_requests
149
147
  try:
@@ -214,7 +212,7 @@ async def async_is_beyond_validation_threshold(
214
212
  async def async_validate_from_block_id_in_params(
215
213
  provider: ASYNC_PROVIDER_TYPE,
216
214
  params: Sequence[Any],
217
- _result: Dict[str, Any],
215
+ _result: dict[str, Any],
218
216
  ) -> bool:
219
217
  block_id = params[0]
220
218
  if block_id == "earliest":
@@ -228,7 +226,7 @@ async def async_validate_from_block_id_in_params(
228
226
  async def async_validate_from_blocknum_in_result(
229
227
  provider: ASYNC_PROVIDER_TYPE,
230
228
  _params: Sequence[Any],
231
- result: Dict[str, Any],
229
+ result: dict[str, Any],
232
230
  ) -> bool:
233
231
  cache_allowed_requests = provider.cache_allowed_requests
234
232
  try:
@@ -268,7 +266,7 @@ async def async_validate_from_blocknum_in_result(
268
266
 
269
267
 
270
268
  async def async_validate_from_blockhash_in_params(
271
- provider: ASYNC_PROVIDER_TYPE, params: Sequence[Any], _result: Dict[str, Any]
269
+ provider: ASYNC_PROVIDER_TYPE, params: Sequence[Any], _result: dict[str, Any]
272
270
  ) -> bool:
273
271
  cache_allowed_requests = provider.cache_allowed_requests
274
272
  try:
@@ -11,6 +11,6 @@
11
11
  from typing_extensions import (
12
12
  NotRequired, # py311
13
13
  Self, # py311
14
- Unpack, # py311
15
- TypeAlias, # py310
14
+ Unpack, # py310
16
15
  )
16
+ from typing import TypeAlias
@@ -47,8 +47,6 @@ import os
47
47
  import re
48
48
  from typing import (
49
49
  Any,
50
- Dict,
51
- List,
52
50
  )
53
51
 
54
52
  import solcx
@@ -82,7 +80,7 @@ user_filename = user_args.filename
82
80
  files_to_compile = [user_filename] if user_filename else all_dot_sol_files
83
81
 
84
82
 
85
- def _compile_dot_sol_files(dot_sol_filename: str) -> Dict[str, Any]:
83
+ def _compile_dot_sol_files(dot_sol_filename: str) -> dict[str, Any]:
86
84
  compiled = solcx.compile_files(
87
85
  [f"./{dot_sol_filename}"],
88
86
  output_values=["abi", "bin", "bin-runtime"],
@@ -91,10 +89,10 @@ def _compile_dot_sol_files(dot_sol_filename: str) -> Dict[str, Any]:
91
89
 
92
90
 
93
91
  def _get_compiled_contract_data(
94
- sol_file_output: Dict[str, Dict[str, str]],
92
+ sol_file_output: dict[str, dict[str, str]],
95
93
  dot_sol_filename: str,
96
94
  contract_name: str = None,
97
- ) -> Dict[str, str]:
95
+ ) -> dict[str, str]:
98
96
  if not contract_name:
99
97
  contract_name = dot_sol_filename.replace(".sol", "")
100
98
 
@@ -114,7 +112,7 @@ def _get_compiled_contract_data(
114
112
  contracts_in_file = {}
115
113
 
116
114
 
117
- def compile_files(file_list: List[str]) -> None:
115
+ def compile_files(file_list: list[str]) -> None:
118
116
  for filename in file_list:
119
117
  with open(os.path.join(os.getcwd(), filename)) as f:
120
118
  dot_sol_file = f.readlines()