faster-eth-utils 5.3.19__cp311-cp311-win32.whl → 5.3.23__cp311-cp311-win32.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.

Potentially problematic release.


This version of faster-eth-utils might be problematic. Click here for more details.

Files changed (43) hide show
  1. faster_eth_utils/abi.cp311-win32.pyd +0 -0
  2. faster_eth_utils/abi.py +76 -55
  3. faster_eth_utils/address.cp311-win32.pyd +0 -0
  4. faster_eth_utils/address.py +7 -14
  5. faster_eth_utils/applicators.cp311-win32.pyd +0 -0
  6. faster_eth_utils/applicators.py +20 -33
  7. faster_eth_utils/conversions.cp311-win32.pyd +0 -0
  8. faster_eth_utils/conversions.py +18 -20
  9. faster_eth_utils/crypto.cp311-win32.pyd +0 -0
  10. faster_eth_utils/crypto.py +3 -8
  11. faster_eth_utils/currency.cp311-win32.pyd +0 -0
  12. faster_eth_utils/currency.py +11 -8
  13. faster_eth_utils/curried/__init__.py +35 -44
  14. faster_eth_utils/debug.cp311-win32.pyd +0 -0
  15. faster_eth_utils/decorators.cp311-win32.pyd +0 -0
  16. faster_eth_utils/decorators.py +16 -20
  17. faster_eth_utils/encoding.cp311-win32.pyd +0 -0
  18. faster_eth_utils/encoding.py +1 -1
  19. faster_eth_utils/exceptions.cp311-win32.pyd +0 -0
  20. faster_eth_utils/exceptions.py +1 -1
  21. faster_eth_utils/functional.cp311-win32.pyd +0 -0
  22. faster_eth_utils/functional.py +10 -12
  23. faster_eth_utils/hexadecimal.cp311-win32.pyd +0 -0
  24. faster_eth_utils/hexadecimal.py +8 -12
  25. faster_eth_utils/humanize.cp311-win32.pyd +0 -0
  26. faster_eth_utils/humanize.py +16 -16
  27. faster_eth_utils/logging.py +33 -27
  28. faster_eth_utils/module_loading.cp311-win32.pyd +0 -0
  29. faster_eth_utils/network.cp311-win32.pyd +0 -0
  30. faster_eth_utils/network.py +2 -3
  31. faster_eth_utils/numeric.cp311-win32.pyd +0 -0
  32. faster_eth_utils/pydantic.py +4 -6
  33. faster_eth_utils/toolz.cp311-win32.pyd +0 -0
  34. faster_eth_utils/types.cp311-win32.pyd +0 -0
  35. faster_eth_utils/types.py +5 -8
  36. faster_eth_utils/units.cp311-win32.pyd +0 -0
  37. {faster_eth_utils-5.3.19.dist-info → faster_eth_utils-5.3.23.dist-info}/METADATA +8 -9
  38. faster_eth_utils-5.3.23.dist-info/RECORD +53 -0
  39. faster_eth_utils__mypyc.cp311-win32.pyd +0 -0
  40. faster_eth_utils-5.3.19.dist-info/RECORD +0 -53
  41. {faster_eth_utils-5.3.19.dist-info → faster_eth_utils-5.3.23.dist-info}/WHEEL +0 -0
  42. {faster_eth_utils-5.3.19.dist-info → faster_eth_utils-5.3.23.dist-info}/licenses/LICENSE +0 -0
  43. {faster_eth_utils-5.3.19.dist-info → faster_eth_utils-5.3.23.dist-info}/top_level.txt +0 -0
@@ -46,11 +46,12 @@ class denoms:
46
46
 
47
47
  MIN_WEI: Final = 0
48
48
  MAX_WEI: Final = 2**256 - 1
49
+ DECIMAL_ZERO: Final = decimal.Decimal(0)
49
50
 
50
51
  _NumberType = Union[int, float, str, decimal.Decimal]
51
52
 
52
53
 
53
- def _from_wei(number: int, unit_value: decimal.Decimal) -> Union[int, decimal.Decimal]:
54
+ def _from_wei(number: int, unit_value: decimal.Decimal) -> int | decimal.Decimal:
54
55
  if number == 0:
55
56
  return 0
56
57
 
@@ -75,7 +76,7 @@ def _to_wei(number: _NumberType, unit_value: decimal.Decimal) -> int:
75
76
  else:
76
77
  raise TypeError("Unsupported type. Must be one of integer, float, or string")
77
78
 
78
- if d_number == decimal.Decimal(0):
79
+ if d_number == DECIMAL_ZERO:
79
80
  return 0
80
81
 
81
82
  s_number = str(number)
@@ -97,14 +98,15 @@ def _to_wei(number: _NumberType, unit_value: decimal.Decimal) -> int:
97
98
  return int(result_value)
98
99
 
99
100
 
100
- def from_wei(number: int, unit: str) -> Union[int, decimal.Decimal]:
101
+ def from_wei(number: int, unit: str) -> int | decimal.Decimal:
101
102
  """
102
103
  Takes a number of wei and converts it to any other ether unit.
103
104
  """
104
- if unit.lower() not in units:
105
+ unit_key = unit.lower()
106
+ if unit_key not in units:
105
107
  raise ValueError(f"Unknown unit. Must be one of {'/'.join(units.keys())}")
106
108
 
107
- unit_value = units[unit.lower()]
109
+ unit_value = units[unit_key]
108
110
 
109
111
  return _from_wei(number, unit_value)
110
112
 
@@ -113,15 +115,16 @@ def to_wei(number: _NumberType, unit: str) -> int:
113
115
  """
114
116
  Takes a number of a unit and converts it to wei.
115
117
  """
116
- if unit.lower() not in units:
118
+ unit_key = unit.lower()
119
+ if unit_key not in units:
117
120
  raise ValueError(f"Unknown unit. Must be one of {'/'.join(units.keys())}")
118
121
 
119
- unit_value = units[unit.lower()]
122
+ unit_value = units[unit_key]
120
123
 
121
124
  return _to_wei(number, unit_value)
122
125
 
123
126
 
124
- def from_wei_decimals(number: int, decimals: int) -> Union[int, decimal.Decimal]:
127
+ def from_wei_decimals(number: int, decimals: int) -> int | decimal.Decimal:
125
128
  """
126
129
  Takes a number of wei and converts it to a decimal with the specified
127
130
  number of decimals.
@@ -1,18 +1,14 @@
1
1
  import sys
2
+ from collections.abc import Callable, Generator, Sequence
2
3
  from typing import (
3
4
  TYPE_CHECKING,
4
5
  Any,
5
- Callable,
6
- Dict,
7
- Generator,
8
6
  Optional,
9
- Sequence,
10
- Tuple,
7
+ TypeGuard,
11
8
  TypeVar,
12
9
  Union,
13
10
  overload,
14
11
  )
15
- from typing_extensions import TypeGuard
16
12
 
17
13
  from faster_eth_utils import (
18
14
  CamelModel,
@@ -122,11 +118,8 @@ from faster_eth_utils.toolz import (
122
118
  )
123
119
 
124
120
  if TYPE_CHECKING:
125
- if sys.version_info >= (3, 9):
126
- from _typeshed import SupportsBool
121
+ from _typeshed import SupportsBool
127
122
  # We have to sacrifice a little bit of specificity on dinosaur Python3.8
128
- else:
129
- SupportsBool = Any
130
123
 
131
124
 
132
125
  TArg = TypeVar("TArg")
@@ -138,44 +131,44 @@ TValue = TypeVar("TValue")
138
131
  @overload
139
132
  def apply_formatter_if(
140
133
  condition: Callable[[TArg], TypeGuard[TOther]],
141
- ) -> Callable[[Callable[[TOther], TReturn]], Callable[[TArg], Union[TReturn, TArg]]]:
134
+ ) -> Callable[[Callable[[TOther], TReturn]], Callable[[TArg], TReturn | TArg]]:
142
135
  ...
143
136
 
144
137
  @overload
145
138
  def apply_formatter_if(
146
139
  condition: Callable[[TArg], TypeGuard[TOther]], formatter: Callable[[TOther], TReturn]
147
- ) -> Callable[[TArg], Union[TReturn, TArg]]:
140
+ ) -> Callable[[TArg], TReturn | TArg]:
148
141
  ...
149
142
 
150
143
  @overload
151
144
  def apply_formatter_if(
152
145
  condition: Callable[[TArg], TypeGuard[TOther]], formatter: Callable[[TOther], TReturn], value: TArg
153
- ) -> Union[TReturn, TArg]:
146
+ ) -> TReturn | TArg:
154
147
  ...
155
148
 
156
149
  @overload
157
150
  def apply_formatter_if(
158
151
  condition: Callable[[TArg], bool], formatter: Callable[[TArg], TReturn], value: TArg
159
- ) -> Union[TReturn, TArg]:
152
+ ) -> TReturn | TArg:
160
153
  ...
161
154
 
162
155
  def apply_formatter_if( # type: ignore
163
- condition: Union[Callable[[TArg], TypeGuard[TOther]], Callable[[TArg], bool]],
164
- formatter: Optional[Union[Callable[[TOther], TReturn], Callable[[TArg], TReturn]]] = None,
165
- value: Optional[TArg] = None,
166
- ) -> Union[
167
- Callable[[Callable[[TOther], TReturn]], Callable[[TArg], Union[TReturn, TArg]]],
168
- Callable[[TArg], Union[TReturn, TArg]],
169
- TReturn,
170
- TArg,
171
- ]:
156
+ condition: Callable[[TArg], TypeGuard[TOther]] | Callable[[TArg], bool],
157
+ formatter: Callable[[TOther], TReturn] | Callable[[TArg], TReturn] | None = None,
158
+ value: TArg | None = None,
159
+ ) -> (
160
+ Callable[[Callable[[TOther], TReturn]], Callable[[TArg], TReturn | TArg]] |
161
+ Callable[[TArg], TReturn | TArg] |
162
+ TReturn |
163
+ TArg
164
+ ):
172
165
  pass
173
166
 
174
167
 
175
168
  @overload
176
169
  def apply_one_of_formatters(
177
170
  formatter_condition_pairs: Sequence[
178
- Tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]]
171
+ tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]]
179
172
  ],
180
173
  ) -> Callable[[TArg], TReturn]: ...
181
174
 
@@ -183,78 +176,78 @@ def apply_one_of_formatters(
183
176
  @overload
184
177
  def apply_one_of_formatters(
185
178
  formatter_condition_pairs: Sequence[
186
- Tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]]
179
+ tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]]
187
180
  ],
188
181
  value: TArg,
189
182
  ) -> TReturn: ...
190
183
 
191
184
 
192
185
  # This is just a stub to appease mypy, it gets overwritten later
193
- def apply_one_of_formatters(
186
+ def apply_one_of_formatters( # type: ignore[empty-body]
194
187
  formatter_condition_pairs: Sequence[
195
- Tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]]
188
+ tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]]
196
189
  ],
197
- value: Optional[TArg] = None,
198
- ) -> TReturn: ...
190
+ value: TArg | None = None,
191
+ ) -> Callable[[TArg], TReturn] | TReturn: ...
199
192
 
200
193
 
201
194
  @overload
202
195
  def hexstr_if_str(
203
196
  to_type: Callable[..., TReturn],
204
- ) -> Callable[[Union[bytes, int, str]], TReturn]: ...
197
+ ) -> Callable[[bytes | int | str], TReturn]: ...
205
198
 
206
199
 
207
200
  @overload
208
201
  def hexstr_if_str(
209
- to_type: Callable[..., TReturn], to_format: Union[bytes, int, str]
202
+ to_type: Callable[..., TReturn], to_format: bytes | int | str
210
203
  ) -> TReturn: ...
211
204
 
212
205
 
213
206
  # This is just a stub to appease mypy, it gets overwritten later
214
207
  def hexstr_if_str( # type: ignore
215
- to_type: Callable[..., TReturn], to_format: Optional[Union[bytes, int, str]] = None
208
+ to_type: Callable[..., TReturn], to_format: bytes | int | str | None = None
216
209
  ) -> TReturn: ...
217
210
 
218
211
 
219
212
  @overload
220
213
  def text_if_str(
221
214
  to_type: Callable[..., TReturn],
222
- ) -> Callable[[Union[bytes, int, str]], TReturn]: ...
215
+ ) -> Callable[[bytes | int | str], TReturn]: ...
223
216
 
224
217
 
225
218
  @overload
226
219
  def text_if_str(
227
- to_type: Callable[..., TReturn], text_or_primitive: Union[bytes, int, str]
220
+ to_type: Callable[..., TReturn], text_or_primitive: bytes | int | str
228
221
  ) -> TReturn: ...
229
222
 
230
223
 
231
224
  # This is just a stub to appease mypy, it gets overwritten later
232
225
  def text_if_str( # type: ignore
233
226
  to_type: Callable[..., TReturn],
234
- text_or_primitive: Optional[Union[bytes, int, str]] = None,
227
+ text_or_primitive: bytes | int | str | None = None,
235
228
  ) -> TReturn: ...
236
229
 
237
230
 
238
231
  @overload
239
232
  def apply_formatters_to_dict(
240
- formatters: Dict[Any, Any], unaliased: bool = False
241
- ) -> Callable[[Union[Dict[Any, Any], CamelModel]], Dict[Any, Any]]:
233
+ formatters: dict[Any, Any], unaliased: bool = False
234
+ ) -> Callable[[dict[Any, Any] | CamelModel], dict[Any, Any]]:
242
235
  ...
243
236
 
244
237
 
245
238
  @overload
246
239
  def apply_formatters_to_dict(
247
- formatters: Dict[Any, Any], value: Union[Dict[Any, Any], CamelModel], unaliased: bool = False
248
- ) -> Dict[Any, Any]:
240
+ formatters: dict[Any, Any], value: dict[Any, Any] | CamelModel, unaliased: bool = False
241
+ ) -> dict[Any, Any]:
249
242
  ...
250
243
 
251
244
 
252
245
  # This is just a stub to appease mypy, it gets overwritten later
253
246
  def apply_formatters_to_dict(
254
- formatters: Dict[Any, Any],
255
- value: Optional[Union[Dict[Any, Any], CamelModel]] = None,
247
+ formatters: dict[Any, Any],
248
+ value: dict[Any, Any] | CamelModel | None = None,
256
249
  unaliased: bool = False,
257
- ) -> Dict[Any, Any]: ...
250
+ ) -> dict[Any, Any]: ...
258
251
 
259
252
 
260
253
  apply_formatter_at_index = curry(apply_formatter_at_index)
@@ -287,13 +280,11 @@ clamp = curry(clamp)
287
280
  # `from eth_utils.curried import *`
288
281
  del Any
289
282
  del Callable
290
- del Dict
291
283
  del Generator
292
284
  del Optional
293
285
  del Sequence
294
286
  del TReturn
295
287
  del TValue
296
- del Tuple
297
288
  del TypeGuard
298
289
  del TypeVar
299
290
  del Union
Binary file
Binary file
@@ -1,19 +1,15 @@
1
1
  import functools
2
+ from collections.abc import Callable
2
3
  from typing import (
3
4
  Any,
4
- Callable,
5
- Dict,
5
+ Concatenate,
6
6
  Final,
7
7
  Generic,
8
- Optional,
9
- Tuple,
10
- Type,
11
8
  TypeVar,
12
- Union,
13
9
  final,
14
10
  )
15
11
 
16
- from typing_extensions import Concatenate, ParamSpec
12
+ from typing_extensions import ParamSpec
17
13
 
18
14
  P = ParamSpec("P")
19
15
 
@@ -26,7 +22,7 @@ TInstance = TypeVar("TInstance", bound=object)
26
22
  @final
27
23
  class combomethod(Generic[TInstance, P, T]):
28
24
  def __init__(
29
- self, method: Callable[Concatenate[Union[TInstance, Type[TInstance]], P], T]
25
+ self, method: Callable[Concatenate[TInstance | type[TInstance], P], T]
30
26
  ) -> None:
31
27
  self.method: Final = method
32
28
 
@@ -35,22 +31,22 @@ class combomethod(Generic[TInstance, P, T]):
35
31
 
36
32
  def __get__(
37
33
  self,
38
- obj: Optional[TInstance],
39
- objtype: Type[TInstance],
34
+ obj: TInstance | None,
35
+ objtype: type[TInstance],
40
36
  ) -> Callable[P, T]:
41
37
 
42
- @functools.wraps(self.method)
38
+ method = self.method
39
+ bound_arg = objtype if obj is None else obj
40
+
41
+ @functools.wraps(method)
43
42
  def _wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
44
- if obj is not None:
45
- return self.method(obj, *args, **kwargs)
46
- else:
47
- return self.method(objtype, *args, **kwargs) # type: ignore [arg-type]
43
+ return method(bound_arg, *args, **kwargs)
48
44
 
49
45
  return _wrapper
50
46
 
51
47
 
52
48
  _return_arg_type_deco_cache: Final[
53
- Dict[int, Callable[[Callable[P, T]], Callable[P, Any]]]
49
+ dict[int, Callable[[Callable[P, T]], Callable[P, Any]]]
54
50
  ] = {}
55
51
  # No need to hold so many unique instances in memory
56
52
 
@@ -76,10 +72,10 @@ def return_arg_type(at_position: int) -> Callable[[Callable[P, T]], Callable[P,
76
72
  return decorator
77
73
 
78
74
 
79
- ExcType = Type[BaseException]
75
+ ExcType = type[BaseException]
80
76
 
81
- ReplaceExceptionsCache = Dict[
82
- Tuple[Tuple[ExcType, ExcType], ...],
77
+ ReplaceExceptionsCache = dict[
78
+ tuple[tuple[ExcType, ExcType], ...],
83
79
  Callable[[Callable[P, T]], Callable[P, T]],
84
80
  ]
85
81
 
@@ -88,7 +84,7 @@ _replace_exceptions_deco_cache: Final[ReplaceExceptionsCache[..., Any]] = {}
88
84
 
89
85
 
90
86
  def replace_exceptions(
91
- old_to_new_exceptions: Dict[ExcType, ExcType],
87
+ old_to_new_exceptions: dict[ExcType, ExcType],
92
88
  ) -> Callable[[Callable[P, T]], Callable[P, T]]:
93
89
  """
94
90
  Replaces old exceptions with new exceptions to be raised in their place.
Binary file
@@ -2,5 +2,5 @@ def int_to_big_endian(value: int) -> bytes:
2
2
  return value.to_bytes((value.bit_length() + 7) // 8 or 1, "big")
3
3
 
4
4
 
5
- def big_endian_to_int(value: bytes) -> int:
5
+ def big_endian_to_int(value: bytes | bytearray) -> int:
6
6
  return int.from_bytes(value, "big")
Binary file
@@ -5,7 +5,7 @@ does not require any change to your existing exception handlers. They will conti
5
5
 
6
6
  import eth_utils.exceptions
7
7
 
8
- class ValidationError(eth_utils.exceptions.ValidationError):
8
+ class ValidationError(eth_utils.exceptions.ValidationError): # type: ignore[misc]
9
9
  """
10
10
  Raised when something does not pass a validation check.
11
11
  """
Binary file
@@ -1,12 +1,10 @@
1
1
  import collections
2
2
  import functools
3
3
  import itertools
4
+ from collections.abc import Callable, Iterable, Mapping
4
5
  from typing import ( # noqa: F401
5
- Callable,
6
6
  Dict,
7
- Iterable,
8
7
  List,
9
- Mapping,
10
8
  Set,
11
9
  Tuple,
12
10
  TypeVar,
@@ -57,25 +55,25 @@ def apply_to_return_value(
57
55
  TVal = TypeVar("TVal")
58
56
  TKey = TypeVar("TKey")
59
57
 
60
- def to_tuple(fn: Callable[P, Iterable[TVal]]) -> Callable[P, Tuple[TVal, ...]]:
61
- def to_tuple_wrap(*args: P.args, **kwargs: P.kwargs) -> Tuple[TVal, ...]:
58
+ def to_tuple(fn: Callable[P, Iterable[TVal]]) -> Callable[P, tuple[TVal, ...]]:
59
+ def to_tuple_wrap(*args: P.args, **kwargs: P.kwargs) -> tuple[TVal, ...]:
62
60
  return tuple(fn(*args, **kwargs))
63
61
  return to_tuple_wrap
64
62
 
65
- def to_list(fn: Callable[P, Iterable[TVal]]) -> Callable[P, List[TVal]]:
66
- def to_list_wrap(*args: P.args, **kwargs: P.kwargs) -> List[TVal]:
63
+ def to_list(fn: Callable[P, Iterable[TVal]]) -> Callable[P, list[TVal]]:
64
+ def to_list_wrap(*args: P.args, **kwargs: P.kwargs) -> list[TVal]:
67
65
  return list(fn(*args, **kwargs))
68
66
  return to_list_wrap
69
67
 
70
- def to_set(fn: Callable[P, Iterable[TVal]]) -> Callable[P, Set[TVal]]:
71
- def to_set_wrap(*args: P.args, **kwargs: P.kwargs) -> Set[TVal]:
68
+ def to_set(fn: Callable[P, Iterable[TVal]]) -> Callable[P, set[TVal]]:
69
+ def to_set_wrap(*args: P.args, **kwargs: P.kwargs) -> set[TVal]:
72
70
  return set(fn(*args, **kwargs))
73
71
  return to_set_wrap
74
72
 
75
73
  def to_dict(
76
- fn: Callable[P, Union[Mapping[TKey, TVal], Iterable[Tuple[TKey, TVal]]]]
77
- ) -> Callable[P, Dict[TKey, TVal]]:
78
- def to_dict_wrap(*args: P.args, **kwargs: P.kwargs) -> Dict[TKey, TVal]:
74
+ fn: Callable[P, Mapping[TKey, TVal] | Iterable[tuple[TKey, TVal]]]
75
+ ) -> Callable[P, dict[TKey, TVal]]:
76
+ def to_dict_wrap(*args: P.args, **kwargs: P.kwargs) -> dict[TKey, TVal]:
79
77
  return dict(fn(*args, **kwargs))
80
78
  return to_dict_wrap
81
79
 
@@ -4,22 +4,18 @@ import binascii
4
4
  import re
5
5
  from typing import (
6
6
  Any,
7
- AnyStr,
8
7
  Final,
9
- Union,
8
+ TypeGuard,
10
9
  )
11
10
 
12
11
  from eth_typing import (
13
12
  HexStr,
14
13
  )
15
- from typing_extensions import (
16
- TypeGuard,
17
- )
18
14
 
19
15
  _HEX_REGEXP_MATCH: Final = re.compile("(0[xX])?[0-9a-fA-F]*").fullmatch
20
16
 
21
- hexlify: Final = binascii.hexlify
22
- unhexlify: Final = binascii.unhexlify
17
+ _hexlify: Final = binascii.hexlify
18
+ _unhexlify: Final = binascii.unhexlify
23
19
 
24
20
 
25
21
 
@@ -29,11 +25,11 @@ def decode_hex(value: str) -> bytes:
29
25
  non_prefixed = remove_0x_prefix(HexStr(value))
30
26
  # unhexlify will only accept bytes type someday
31
27
  ascii_hex = non_prefixed.encode("ascii")
32
- return unhexlify(ascii_hex)
28
+ return _unhexlify(ascii_hex)
33
29
 
34
30
 
35
- def encode_hex(value: AnyStr) -> HexStr:
36
- ascii_bytes: Union[bytes, bytearray]
31
+ def encode_hex(value: str | bytes | bytearray) -> HexStr:
32
+ ascii_bytes: bytes | bytearray
37
33
  if isinstance(value, (bytes, bytearray)):
38
34
  ascii_bytes = value
39
35
  elif isinstance(value, str):
@@ -41,7 +37,7 @@ def encode_hex(value: AnyStr) -> HexStr:
41
37
  else:
42
38
  raise TypeError("Value must be an instance of str or unicode")
43
39
 
44
- binary_hex = hexlify(ascii_bytes)
40
+ binary_hex = _hexlify(ascii_bytes)
45
41
  return add_0x_prefix(HexStr(binary_hex.decode("ascii")))
46
42
 
47
43
 
@@ -51,7 +47,7 @@ def is_0x_prefixed(value: str) -> bool:
51
47
  # raise TypeError(
52
48
  # f"is_0x_prefixed requires text typed arguments. Got: {repr(value)}"
53
49
  # )
54
- return value.startswith(("0x", "0X"))
50
+ return value.startswith("0x") or value.startswith("0X")
55
51
 
56
52
 
57
53
  def remove_0x_prefix(value: HexStr) -> HexStr:
Binary file
@@ -1,10 +1,10 @@
1
+ from collections.abc import (
2
+ Iterable,
3
+ Iterator,
4
+ )
1
5
  from typing import (
2
6
  Any,
3
7
  Final,
4
- Iterable,
5
- Iterator,
6
- Tuple,
7
- Union,
8
8
  )
9
9
  from urllib import (
10
10
  parse,
@@ -23,13 +23,14 @@ from faster_eth_utils.currency import (
23
23
  from . import toolz
24
24
 
25
25
 
26
- def humanize_seconds(seconds: Union[float, int]) -> str:
27
- if int(seconds) == 0:
26
+ def humanize_seconds(seconds: float | int) -> str:
27
+ seconds_int = int(seconds)
28
+ if seconds_int == 0:
28
29
  return "0s"
29
30
 
30
- unit_values = _consume_leading_zero_units(_humanize_seconds(int(seconds)))
31
+ unit_values = _consume_leading_zero_units(_humanize_seconds(seconds_int))
31
32
 
32
- return "".join((f"{amount}{unit}" for amount, unit in toolz.take(3, unit_values)))
33
+ return "".join(f"{amount}{unit}" for amount, unit in toolz.take(3, unit_values))
33
34
 
34
35
 
35
36
  SECOND: Final = 1
@@ -53,8 +54,8 @@ UNITS: Final = (
53
54
 
54
55
 
55
56
  def _consume_leading_zero_units(
56
- units_iter: Iterator[Tuple[int, str]]
57
- ) -> Iterator[Tuple[int, str]]:
57
+ units_iter: Iterator[tuple[int, str]]
58
+ ) -> Iterator[tuple[int, str]]:
58
59
  for amount, unit in units_iter:
59
60
  if amount == 0:
60
61
  continue
@@ -65,7 +66,7 @@ def _consume_leading_zero_units(
65
66
  yield from units_iter
66
67
 
67
68
 
68
- def _humanize_seconds(seconds: int) -> Iterator[Tuple[int, str]]:
69
+ def _humanize_seconds(seconds: int) -> Iterator[tuple[int, str]]:
69
70
  remainder = seconds
70
71
 
71
72
  for duration, unit in UNITS:
@@ -140,7 +141,7 @@ def _is_CIDv0_ipfs_hash(ipfs_hash: str) -> bool:
140
141
  return False
141
142
 
142
143
 
143
- def _find_breakpoints(values: Tuple[int, ...]) -> Iterator[int]:
144
+ def _find_breakpoints(values: tuple[int, ...]) -> Iterator[int]:
144
145
  yield 0
145
146
  for index, (left, right) in enumerate(toolz.sliding_window(2, values), 1):
146
147
  if left + 1 == right:
@@ -150,7 +151,7 @@ def _find_breakpoints(values: Tuple[int, ...]) -> Iterator[int]:
150
151
  yield len(values)
151
152
 
152
153
 
153
- def _extract_integer_ranges(values: Tuple[int, ...]) -> Iterator[Tuple[int, int]]:
154
+ def _extract_integer_ranges(values: tuple[int, ...]) -> Iterator[tuple[int, int]]:
154
155
  """
155
156
  Return a tuple of consecutive ranges of integers.
156
157
 
@@ -165,7 +166,7 @@ def _extract_integer_ranges(values: Tuple[int, ...]) -> Iterator[Tuple[int, int]
165
166
  yield chunk[0], chunk[-1]
166
167
 
167
168
 
168
- def _humanize_range(bounds: Tuple[int, int]) -> str:
169
+ def _humanize_range(bounds: tuple[int, int]) -> str:
169
170
  left, right = bounds
170
171
  if left == right:
171
172
  return str(left)
@@ -197,5 +198,4 @@ def humanize_wei(number: int) -> str:
197
198
  else:
198
199
  unit = "wei"
199
200
  amount = from_wei(number, unit)
200
- x = f"{str(amount)} {unit}"
201
- return x
201
+ return f"{str(amount)} {unit}"