faster-eth-utils 5.3.2__cp312-cp312-musllinux_1_2_i686.whl → 5.3.22__cp312-cp312-musllinux_1_2_i686.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.
- faster_eth_utils/abi.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/abi.py +99 -74
- faster_eth_utils/address.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/address.py +15 -36
- faster_eth_utils/applicators.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/applicators.py +79 -59
- faster_eth_utils/conversions.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/conversions.py +18 -20
- faster_eth_utils/crypto.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/crypto.py +3 -8
- faster_eth_utils/currency.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/currency.py +11 -8
- faster_eth_utils/curried/__init__.py +65 -65
- faster_eth_utils/debug.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/decorators.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/decorators.py +65 -29
- faster_eth_utils/encoding.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/encoding.py +1 -1
- faster_eth_utils/exceptions.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/exceptions.py +8 -1
- faster_eth_utils/functional.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/functional.py +39 -27
- faster_eth_utils/hexadecimal.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/hexadecimal.py +8 -12
- faster_eth_utils/humanize.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/humanize.py +18 -22
- faster_eth_utils/logging.py +51 -44
- faster_eth_utils/module_loading.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/network.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/network.py +11 -4
- faster_eth_utils/numeric.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/pydantic.py +15 -13
- faster_eth_utils/toolz.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/toolz.py +82 -152
- faster_eth_utils/types.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils/types.py +20 -17
- faster_eth_utils/units.cpython-312-i386-linux-musl.so +0 -0
- {faster_eth_utils-5.3.2.dist-info → faster_eth_utils-5.3.22.dist-info}/METADATA +46 -17
- faster_eth_utils-5.3.22.dist-info/RECORD +53 -0
- faster_eth_utils-5.3.22.dist-info/top_level.txt +3 -0
- faster_eth_utils__mypyc.cpython-312-i386-linux-musl.so +0 -0
- bce0bfc64ce5e845ec4a__mypyc.cpython-312-i386-linux-musl.so +0 -0
- faster_eth_utils-5.3.2.dist-info/RECORD +0 -47
- faster_eth_utils-5.3.2.dist-info/top_level.txt +0 -3
- {faster_eth_utils-5.3.2.dist-info → faster_eth_utils-5.3.22.dist-info}/WHEEL +0 -0
- {faster_eth_utils-5.3.2.dist-info → faster_eth_utils-5.3.22.dist-info}/licenses/LICENSE +0 -0
faster_eth_utils/applicators.py
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
+
from collections.abc import Callable, Generator, Mapping, Sequence
|
|
1
2
|
from typing import (
|
|
3
|
+
TYPE_CHECKING,
|
|
2
4
|
Any,
|
|
3
|
-
|
|
4
|
-
Dict,
|
|
5
|
-
Generator,
|
|
6
|
-
List,
|
|
7
|
-
Tuple,
|
|
5
|
+
TypeGuard,
|
|
8
6
|
TypeVar,
|
|
9
|
-
|
|
7
|
+
cast,
|
|
8
|
+
overload,
|
|
10
9
|
)
|
|
10
|
+
|
|
11
11
|
import warnings
|
|
12
12
|
|
|
13
13
|
from .decorators import (
|
|
14
14
|
return_arg_type,
|
|
15
15
|
)
|
|
16
|
-
from .functional import (
|
|
17
|
-
to_dict,
|
|
18
|
-
)
|
|
19
16
|
from .pydantic import (
|
|
20
17
|
CamelModel,
|
|
21
18
|
)
|
|
@@ -24,16 +21,23 @@ from .toolz import (
|
|
|
24
21
|
curry,
|
|
25
22
|
)
|
|
26
23
|
|
|
24
|
+
if TYPE_CHECKING:
|
|
25
|
+
from _typeshed import SupportsBool
|
|
26
|
+
# We have to sacrifice a little bit of specificity on dinosaur Python3.8
|
|
27
|
+
|
|
27
28
|
TArg = TypeVar("TArg")
|
|
28
29
|
TReturn = TypeVar("TReturn")
|
|
30
|
+
TOther = TypeVar("TOther")
|
|
29
31
|
|
|
30
|
-
Formatters = Callable[[
|
|
32
|
+
Formatters = Callable[[list[Any]], list[Any]]
|
|
31
33
|
|
|
32
34
|
|
|
33
35
|
@return_arg_type(2)
|
|
34
36
|
def apply_formatter_at_index(
|
|
35
|
-
formatter: Callable[
|
|
36
|
-
|
|
37
|
+
formatter: Callable[[TArg], TReturn],
|
|
38
|
+
at_index: int,
|
|
39
|
+
value: Sequence[TArg | TOther],
|
|
40
|
+
) -> Generator[TOther | TReturn, None, None]:
|
|
37
41
|
try:
|
|
38
42
|
item = value[at_index]
|
|
39
43
|
except IndexError:
|
|
@@ -42,12 +46,12 @@ def apply_formatter_at_index(
|
|
|
42
46
|
f"Need: {at_index + 1}"
|
|
43
47
|
) from None
|
|
44
48
|
|
|
45
|
-
yield from value[:at_index]
|
|
46
|
-
yield formatter(item)
|
|
47
|
-
yield from value[at_index + 1 :]
|
|
49
|
+
yield from cast(Sequence[TOther], value[:at_index])
|
|
50
|
+
yield formatter(cast(TArg, item))
|
|
51
|
+
yield from cast(Sequence[TOther], value[at_index + 1 :])
|
|
48
52
|
|
|
49
53
|
|
|
50
|
-
def combine_argument_formatters(*formatters:
|
|
54
|
+
def combine_argument_formatters(*formatters: Callable[..., Any]) -> Formatters:
|
|
51
55
|
warnings.warn(
|
|
52
56
|
DeprecationWarning(
|
|
53
57
|
"combine_argument_formatters(formatter1, formatter2)([item1, item2])"
|
|
@@ -60,7 +64,7 @@ def combine_argument_formatters(*formatters: List[Callable[..., Any]]) -> Format
|
|
|
60
64
|
)
|
|
61
65
|
|
|
62
66
|
_formatter_at_index = curry(apply_formatter_at_index)
|
|
63
|
-
return compose( # type: ignore
|
|
67
|
+
return compose( # type: ignore [no-any-return]
|
|
64
68
|
*(
|
|
65
69
|
_formatter_at_index(formatter, index)
|
|
66
70
|
for index, formatter in enumerate(formatters)
|
|
@@ -70,38 +74,55 @@ def combine_argument_formatters(*formatters: List[Callable[..., Any]]) -> Format
|
|
|
70
74
|
|
|
71
75
|
@return_arg_type(1)
|
|
72
76
|
def apply_formatters_to_sequence(
|
|
73
|
-
formatters:
|
|
74
|
-
) -> Generator[
|
|
75
|
-
|
|
77
|
+
formatters: list[Callable[[Any], TReturn]], sequence: Sequence[Any]
|
|
78
|
+
) -> Generator[TReturn, None, None]:
|
|
79
|
+
num_formatters = len(formatters)
|
|
80
|
+
num_items = len(sequence)
|
|
81
|
+
if num_formatters == num_items:
|
|
76
82
|
for formatter, item in zip(formatters, sequence):
|
|
77
83
|
yield formatter(item)
|
|
78
|
-
elif
|
|
84
|
+
elif num_formatters > num_items:
|
|
79
85
|
raise IndexError(
|
|
80
|
-
f"Too many formatters for sequence: {
|
|
81
|
-
f"{
|
|
86
|
+
f"Too many formatters for sequence: {num_formatters} formatters for "
|
|
87
|
+
f"{sequence!r}"
|
|
82
88
|
)
|
|
83
89
|
else:
|
|
84
90
|
raise IndexError(
|
|
85
|
-
f"Too few formatters for sequence: {
|
|
86
|
-
f"{
|
|
91
|
+
f"Too few formatters for sequence: {num_formatters} formatters for "
|
|
92
|
+
f"{sequence!r}"
|
|
87
93
|
)
|
|
88
94
|
|
|
89
95
|
|
|
96
|
+
@overload
|
|
97
|
+
def apply_formatter_if(
|
|
98
|
+
condition: Callable[[TArg], TypeGuard[TOther]],
|
|
99
|
+
formatter: Callable[[TOther], TReturn],
|
|
100
|
+
value: TArg,
|
|
101
|
+
) -> TArg | TReturn: ...
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@overload
|
|
90
105
|
def apply_formatter_if(
|
|
91
106
|
condition: Callable[[TArg], bool], formatter: Callable[[TArg], TReturn], value: TArg
|
|
92
|
-
) ->
|
|
107
|
+
) -> TArg | TReturn: ...
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def apply_formatter_if( # type: ignore [misc]
|
|
111
|
+
condition: Callable[[TArg], TypeGuard[TOther]] | Callable[[TArg], bool],
|
|
112
|
+
formatter: Callable[[TOther], TReturn] | Callable[[TArg], TReturn],
|
|
113
|
+
value: TArg,
|
|
114
|
+
) -> TArg | TReturn:
|
|
93
115
|
if condition(value):
|
|
94
|
-
return formatter(value)
|
|
116
|
+
return formatter(value) # type: ignore [arg-type]
|
|
95
117
|
else:
|
|
96
118
|
return value
|
|
97
119
|
|
|
98
120
|
|
|
99
|
-
@to_dict
|
|
100
121
|
def apply_formatters_to_dict(
|
|
101
|
-
formatters:
|
|
102
|
-
value:
|
|
122
|
+
formatters: dict[Any, Any],
|
|
123
|
+
value: dict[Any, Any] | CamelModel,
|
|
103
124
|
unaliased: bool = False,
|
|
104
|
-
) ->
|
|
125
|
+
) -> dict[Any, Any]:
|
|
105
126
|
"""
|
|
106
127
|
Apply formatters to a dictionary of values. If the value is a pydantic model,
|
|
107
128
|
it will be serialized to a dictionary first, taking into account the
|
|
@@ -116,36 +137,37 @@ def apply_formatters_to_dict(
|
|
|
116
137
|
if isinstance(value, CamelModel):
|
|
117
138
|
value = value.model_dump(by_alias=not unaliased)
|
|
118
139
|
|
|
119
|
-
|
|
120
|
-
if key in formatters:
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
yield key, item
|
|
140
|
+
def get_value(key: Any, val: Any) -> Any:
|
|
141
|
+
if key not in formatters:
|
|
142
|
+
return val
|
|
143
|
+
try:
|
|
144
|
+
return formatters[key](val)
|
|
145
|
+
except ValueError as exc:
|
|
146
|
+
raise ValueError(
|
|
147
|
+
f"Could not format invalid value {val!r} as field {key!r}"
|
|
148
|
+
) from exc
|
|
149
|
+
except TypeError as exc:
|
|
150
|
+
raise TypeError(
|
|
151
|
+
f"Could not format invalid type {val!r} as field {key!r}"
|
|
152
|
+
) from exc
|
|
153
|
+
|
|
154
|
+
return {key: get_value(key, val) for key, val in value.items()}
|
|
135
155
|
|
|
136
156
|
|
|
137
157
|
@return_arg_type(1)
|
|
138
158
|
def apply_formatter_to_array(
|
|
139
|
-
formatter: Callable[[TArg], TReturn], value:
|
|
159
|
+
formatter: Callable[[TArg], TReturn], value: Sequence[TArg]
|
|
140
160
|
) -> Generator[TReturn, None, None]:
|
|
141
161
|
for item in value:
|
|
142
162
|
yield formatter(item)
|
|
143
163
|
|
|
144
164
|
|
|
145
165
|
def apply_one_of_formatters(
|
|
146
|
-
formatter_condition_pairs:
|
|
147
|
-
|
|
148
|
-
|
|
166
|
+
formatter_condition_pairs: tuple[
|
|
167
|
+
tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]], ...
|
|
168
|
+
],
|
|
169
|
+
value: TArg,
|
|
170
|
+
) -> TReturn:
|
|
149
171
|
for condition, formatter in formatter_condition_pairs:
|
|
150
172
|
if condition(value):
|
|
151
173
|
return formatter(value)
|
|
@@ -155,10 +177,9 @@ def apply_one_of_formatters(
|
|
|
155
177
|
)
|
|
156
178
|
|
|
157
179
|
|
|
158
|
-
@to_dict
|
|
159
180
|
def apply_key_map(
|
|
160
|
-
key_mappings:
|
|
161
|
-
) ->
|
|
181
|
+
key_mappings: dict[Any, Any], value: Mapping[Any, Any]
|
|
182
|
+
) -> dict[Any, Any]:
|
|
162
183
|
key_conflicts = (
|
|
163
184
|
set(value.keys())
|
|
164
185
|
.difference(key_mappings.keys())
|
|
@@ -169,8 +190,7 @@ def apply_key_map(
|
|
|
169
190
|
f"Could not apply key map due to conflicting key(s): {key_conflicts}"
|
|
170
191
|
)
|
|
171
192
|
|
|
172
|
-
|
|
173
|
-
if key in key_mappings
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
yield key, item
|
|
193
|
+
def get_key(key: Any) -> Any:
|
|
194
|
+
return key_mappings[key] if key in key_mappings else key
|
|
195
|
+
|
|
196
|
+
return {get_key(key): item for key, item in value.items()}
|
|
Binary file
|
faster_eth_utils/conversions.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
from typing import (
|
|
2
|
-
Callable,
|
|
3
|
-
Optional,
|
|
4
2
|
TypeVar,
|
|
5
3
|
Union,
|
|
6
4
|
)
|
|
5
|
+
from collections.abc import Callable
|
|
7
6
|
|
|
8
7
|
from eth_typing import (
|
|
9
8
|
HexStr,
|
|
@@ -31,9 +30,9 @@ BytesLike = Union[Primitives, bytearray, memoryview]
|
|
|
31
30
|
|
|
32
31
|
|
|
33
32
|
def to_hex(
|
|
34
|
-
primitive:
|
|
35
|
-
hexstr:
|
|
36
|
-
text:
|
|
33
|
+
primitive: BytesLike | None = None,
|
|
34
|
+
hexstr: HexStr | None = None,
|
|
35
|
+
text: str | None = None,
|
|
37
36
|
) -> HexStr:
|
|
38
37
|
"""
|
|
39
38
|
Auto converts any supported value into its hex representation.
|
|
@@ -71,9 +70,9 @@ def to_hex(
|
|
|
71
70
|
|
|
72
71
|
|
|
73
72
|
def to_int(
|
|
74
|
-
primitive:
|
|
75
|
-
hexstr:
|
|
76
|
-
text:
|
|
73
|
+
primitive: BytesLike | None = None,
|
|
74
|
+
hexstr: HexStr | None = None,
|
|
75
|
+
text: str | None = None,
|
|
77
76
|
) -> int:
|
|
78
77
|
"""
|
|
79
78
|
Converts value to its integer representation.
|
|
@@ -107,9 +106,9 @@ def to_int(
|
|
|
107
106
|
|
|
108
107
|
|
|
109
108
|
def to_bytes(
|
|
110
|
-
primitive:
|
|
111
|
-
hexstr:
|
|
112
|
-
text:
|
|
109
|
+
primitive: BytesLike | None = None,
|
|
110
|
+
hexstr: HexStr | None = None,
|
|
111
|
+
text: str | None = None,
|
|
113
112
|
) -> bytes:
|
|
114
113
|
if isinstance(primitive, bool):
|
|
115
114
|
return b"\x01" if primitive else b"\x00"
|
|
@@ -118,10 +117,10 @@ def to_bytes(
|
|
|
118
117
|
elif isinstance(primitive, bytes):
|
|
119
118
|
return primitive
|
|
120
119
|
elif isinstance(primitive, int):
|
|
121
|
-
return
|
|
120
|
+
return int_to_big_endian(primitive)
|
|
122
121
|
elif hexstr is not None:
|
|
123
122
|
if len(hexstr) % 2:
|
|
124
|
-
hexstr = "0x0
|
|
123
|
+
hexstr = HexStr(f"0x0{remove_0x_prefix(hexstr)}")
|
|
125
124
|
return decode_hex(hexstr)
|
|
126
125
|
elif text is not None:
|
|
127
126
|
return text.encode("utf-8")
|
|
@@ -132,9 +131,9 @@ def to_bytes(
|
|
|
132
131
|
|
|
133
132
|
|
|
134
133
|
def to_text(
|
|
135
|
-
primitive:
|
|
136
|
-
hexstr:
|
|
137
|
-
text:
|
|
134
|
+
primitive: BytesLike | None = None,
|
|
135
|
+
hexstr: HexStr | None = None,
|
|
136
|
+
text: str | None = None,
|
|
138
137
|
) -> str:
|
|
139
138
|
if hexstr is not None:
|
|
140
139
|
return to_bytes(hexstr=hexstr).decode("utf-8")
|
|
@@ -147,13 +146,12 @@ def to_text(
|
|
|
147
146
|
elif isinstance(primitive, memoryview):
|
|
148
147
|
return bytes(primitive).decode("utf-8")
|
|
149
148
|
elif isinstance(primitive, int):
|
|
150
|
-
|
|
151
|
-
return to_text(byte_encoding)
|
|
149
|
+
return int_to_big_endian(primitive).decode("utf-8")
|
|
152
150
|
raise TypeError("Expected an int, bytes, bytearray or hexstr.")
|
|
153
151
|
|
|
154
152
|
|
|
155
153
|
def text_if_str(
|
|
156
|
-
to_type: Callable[..., T], text_or_primitive:
|
|
154
|
+
to_type: Callable[..., T], text_or_primitive: bytes | int | str
|
|
157
155
|
) -> T:
|
|
158
156
|
"""
|
|
159
157
|
Convert to a type, assuming that strings can be only unicode text (not a hexstr).
|
|
@@ -169,7 +167,7 @@ def text_if_str(
|
|
|
169
167
|
|
|
170
168
|
|
|
171
169
|
def hexstr_if_str(
|
|
172
|
-
to_type: Callable[..., T], hexstr_or_primitive:
|
|
170
|
+
to_type: Callable[..., T], hexstr_or_primitive: bytes | int | str
|
|
173
171
|
) -> T:
|
|
174
172
|
"""
|
|
175
173
|
Convert to a type, assuming that strings can be only hexstr (not unicode text).
|
|
Binary file
|
faster_eth_utils/crypto.py
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
from typing import (
|
|
2
|
-
Optional,
|
|
3
|
-
Union,
|
|
4
|
-
)
|
|
5
|
-
|
|
6
1
|
from eth_hash.auto import (
|
|
7
2
|
keccak as keccak_256,
|
|
8
3
|
)
|
|
@@ -14,8 +9,8 @@ from .conversions import (
|
|
|
14
9
|
|
|
15
10
|
|
|
16
11
|
def keccak(
|
|
17
|
-
primitive:
|
|
18
|
-
hexstr:
|
|
19
|
-
text:
|
|
12
|
+
primitive: bytes | int | bool | None = None,
|
|
13
|
+
hexstr: HexStr | None = None,
|
|
14
|
+
text: str | None = None,
|
|
20
15
|
) -> bytes:
|
|
21
16
|
return bytes(keccak_256(to_bytes(primitive, hexstr, text)))
|
|
Binary file
|
faster_eth_utils/currency.py
CHANGED
|
@@ -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) ->
|
|
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 ==
|
|
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) ->
|
|
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
|
-
|
|
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[
|
|
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
|
-
|
|
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[
|
|
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) ->
|
|
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,11 +1,10 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from collections.abc import Callable, Generator, Sequence
|
|
1
3
|
from typing import (
|
|
4
|
+
TYPE_CHECKING,
|
|
2
5
|
Any,
|
|
3
|
-
Callable,
|
|
4
|
-
Dict,
|
|
5
|
-
Generator,
|
|
6
6
|
Optional,
|
|
7
|
-
|
|
8
|
-
Tuple,
|
|
7
|
+
TypeGuard,
|
|
9
8
|
TypeVar,
|
|
10
9
|
Union,
|
|
11
10
|
overload,
|
|
@@ -118,138 +117,137 @@ from faster_eth_utils.toolz import (
|
|
|
118
117
|
curry,
|
|
119
118
|
)
|
|
120
119
|
|
|
120
|
+
if TYPE_CHECKING:
|
|
121
|
+
from _typeshed import SupportsBool
|
|
122
|
+
# We have to sacrifice a little bit of specificity on dinosaur Python3.8
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
TArg = TypeVar("TArg")
|
|
126
|
+
TOther = TypeVar("TOther")
|
|
121
127
|
TReturn = TypeVar("TReturn")
|
|
122
128
|
TValue = TypeVar("TValue")
|
|
123
129
|
|
|
124
130
|
|
|
125
131
|
@overload
|
|
126
132
|
def apply_formatter_if(
|
|
127
|
-
condition: Callable[
|
|
128
|
-
) -> Callable[[Callable[
|
|
129
|
-
|
|
130
|
-
|
|
133
|
+
condition: Callable[[TArg], TypeGuard[TOther]],
|
|
134
|
+
) -> Callable[[Callable[[TOther], TReturn]], Callable[[TArg], TReturn | TArg]]:
|
|
135
|
+
...
|
|
131
136
|
|
|
132
137
|
@overload
|
|
133
138
|
def apply_formatter_if(
|
|
134
|
-
condition: Callable[
|
|
135
|
-
) -> Callable[[
|
|
136
|
-
|
|
137
|
-
|
|
139
|
+
condition: Callable[[TArg], TypeGuard[TOther]], formatter: Callable[[TOther], TReturn]
|
|
140
|
+
) -> Callable[[TArg], TReturn | TArg]:
|
|
141
|
+
...
|
|
138
142
|
|
|
139
143
|
@overload
|
|
140
144
|
def apply_formatter_if(
|
|
141
|
-
condition: Callable[
|
|
142
|
-
) ->
|
|
143
|
-
|
|
145
|
+
condition: Callable[[TArg], TypeGuard[TOther]], formatter: Callable[[TOther], TReturn], value: TArg
|
|
146
|
+
) -> TReturn | TArg:
|
|
147
|
+
...
|
|
144
148
|
|
|
149
|
+
@overload
|
|
150
|
+
def apply_formatter_if(
|
|
151
|
+
condition: Callable[[TArg], bool], formatter: Callable[[TArg], TReturn], value: TArg
|
|
152
|
+
) -> TReturn | TArg:
|
|
153
|
+
...
|
|
145
154
|
|
|
146
|
-
# This is just a stub to appease mypy, it gets overwritten later
|
|
147
155
|
def apply_formatter_if( # type: ignore
|
|
148
|
-
condition: Callable[
|
|
149
|
-
formatter:
|
|
150
|
-
value:
|
|
151
|
-
) ->
|
|
152
|
-
Callable[[Callable[
|
|
153
|
-
Callable[[
|
|
154
|
-
TReturn
|
|
155
|
-
|
|
156
|
-
|
|
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
|
+
):
|
|
157
165
|
pass
|
|
158
166
|
|
|
159
167
|
|
|
160
168
|
@overload
|
|
161
169
|
def apply_one_of_formatters(
|
|
162
170
|
formatter_condition_pairs: Sequence[
|
|
163
|
-
|
|
171
|
+
tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]]
|
|
164
172
|
],
|
|
165
|
-
) -> Callable[[
|
|
166
|
-
...
|
|
173
|
+
) -> Callable[[TArg], TReturn]: ...
|
|
167
174
|
|
|
168
175
|
|
|
169
176
|
@overload
|
|
170
177
|
def apply_one_of_formatters(
|
|
171
178
|
formatter_condition_pairs: Sequence[
|
|
172
|
-
|
|
179
|
+
tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]]
|
|
173
180
|
],
|
|
174
|
-
value:
|
|
175
|
-
) -> TReturn:
|
|
176
|
-
...
|
|
181
|
+
value: TArg,
|
|
182
|
+
) -> TReturn: ...
|
|
177
183
|
|
|
178
184
|
|
|
179
185
|
# This is just a stub to appease mypy, it gets overwritten later
|
|
180
|
-
def apply_one_of_formatters( # type: ignore
|
|
186
|
+
def apply_one_of_formatters( # type: ignore[empty-body]
|
|
181
187
|
formatter_condition_pairs: Sequence[
|
|
182
|
-
|
|
188
|
+
tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]]
|
|
183
189
|
],
|
|
184
|
-
value:
|
|
185
|
-
) -> TReturn:
|
|
186
|
-
...
|
|
190
|
+
value: TArg | None = None,
|
|
191
|
+
) -> Callable[[TArg], TReturn] | TReturn: ...
|
|
187
192
|
|
|
188
193
|
|
|
189
194
|
@overload
|
|
190
195
|
def hexstr_if_str(
|
|
191
196
|
to_type: Callable[..., TReturn],
|
|
192
|
-
) -> Callable[[
|
|
193
|
-
...
|
|
197
|
+
) -> Callable[[bytes | int | str], TReturn]: ...
|
|
194
198
|
|
|
195
199
|
|
|
196
200
|
@overload
|
|
197
201
|
def hexstr_if_str(
|
|
198
|
-
to_type: Callable[..., TReturn], to_format:
|
|
199
|
-
) -> TReturn:
|
|
200
|
-
...
|
|
202
|
+
to_type: Callable[..., TReturn], to_format: bytes | int | str
|
|
203
|
+
) -> TReturn: ...
|
|
201
204
|
|
|
202
205
|
|
|
203
206
|
# This is just a stub to appease mypy, it gets overwritten later
|
|
204
207
|
def hexstr_if_str( # type: ignore
|
|
205
|
-
to_type: Callable[..., TReturn], to_format:
|
|
206
|
-
) -> TReturn:
|
|
207
|
-
...
|
|
208
|
+
to_type: Callable[..., TReturn], to_format: bytes | int | str | None = None
|
|
209
|
+
) -> TReturn: ...
|
|
208
210
|
|
|
209
211
|
|
|
210
212
|
@overload
|
|
211
213
|
def text_if_str(
|
|
212
214
|
to_type: Callable[..., TReturn],
|
|
213
|
-
) -> Callable[[
|
|
214
|
-
...
|
|
215
|
+
) -> Callable[[bytes | int | str], TReturn]: ...
|
|
215
216
|
|
|
216
217
|
|
|
217
218
|
@overload
|
|
218
219
|
def text_if_str(
|
|
219
|
-
to_type: Callable[..., TReturn], text_or_primitive:
|
|
220
|
-
) -> TReturn:
|
|
221
|
-
...
|
|
220
|
+
to_type: Callable[..., TReturn], text_or_primitive: bytes | int | str
|
|
221
|
+
) -> TReturn: ...
|
|
222
222
|
|
|
223
223
|
|
|
224
224
|
# This is just a stub to appease mypy, it gets overwritten later
|
|
225
225
|
def text_if_str( # type: ignore
|
|
226
226
|
to_type: Callable[..., TReturn],
|
|
227
|
-
text_or_primitive:
|
|
228
|
-
) -> TReturn:
|
|
229
|
-
...
|
|
227
|
+
text_or_primitive: bytes | int | str | None = None,
|
|
228
|
+
) -> TReturn: ...
|
|
230
229
|
|
|
231
230
|
|
|
232
231
|
@overload
|
|
233
232
|
def apply_formatters_to_dict(
|
|
234
|
-
formatters:
|
|
235
|
-
) -> Callable[[
|
|
233
|
+
formatters: dict[Any, Any], unaliased: bool = False
|
|
234
|
+
) -> Callable[[dict[Any, Any] | CamelModel], dict[Any, Any]]:
|
|
236
235
|
...
|
|
237
236
|
|
|
238
237
|
|
|
239
238
|
@overload
|
|
240
239
|
def apply_formatters_to_dict(
|
|
241
|
-
formatters:
|
|
242
|
-
) ->
|
|
240
|
+
formatters: dict[Any, Any], value: dict[Any, Any] | CamelModel, unaliased: bool = False
|
|
241
|
+
) -> dict[Any, Any]:
|
|
243
242
|
...
|
|
244
243
|
|
|
245
244
|
|
|
246
245
|
# This is just a stub to appease mypy, it gets overwritten later
|
|
247
|
-
def apply_formatters_to_dict(
|
|
248
|
-
formatters:
|
|
249
|
-
value:
|
|
246
|
+
def apply_formatters_to_dict(
|
|
247
|
+
formatters: dict[Any, Any],
|
|
248
|
+
value: dict[Any, Any] | CamelModel | None = None,
|
|
250
249
|
unaliased: bool = False,
|
|
251
|
-
) ->
|
|
252
|
-
...
|
|
250
|
+
) -> dict[Any, Any]: ...
|
|
253
251
|
|
|
254
252
|
|
|
255
253
|
apply_formatter_at_index = curry(apply_formatter_at_index)
|
|
@@ -261,6 +259,7 @@ apply_key_map = curry(apply_key_map)
|
|
|
261
259
|
apply_one_of_formatters = curry(non_curried_apply_one_of_formatters) # noqa: F811
|
|
262
260
|
filter_abi_by_name = curry(filter_abi_by_name)
|
|
263
261
|
filter_abi_by_type = curry(filter_abi_by_type)
|
|
262
|
+
flatten_return = curry(flatten_return)
|
|
264
263
|
from_wei = curry(from_wei)
|
|
265
264
|
from_wei_decimals = curry(from_wei_decimals)
|
|
266
265
|
get_aligned_abi_inputs = curry(get_aligned_abi_inputs)
|
|
@@ -268,7 +267,9 @@ get_logger = curry(get_logger)
|
|
|
268
267
|
get_normalized_abi_inputs = curry(get_normalized_abi_inputs)
|
|
269
268
|
hexstr_if_str = curry(non_curried_hexstr_if_str) # noqa: F811
|
|
270
269
|
is_same_address = curry(is_same_address)
|
|
270
|
+
sort_return = curry(sort_return)
|
|
271
271
|
text_if_str = curry(non_curried_text_if_str) # noqa: F811
|
|
272
|
+
to_ordered_dict = curry(to_ordered_dict)
|
|
272
273
|
to_wei = curry(to_wei)
|
|
273
274
|
to_wei_decimals = curry(to_wei_decimals)
|
|
274
275
|
clamp = curry(clamp)
|
|
@@ -279,13 +280,12 @@ clamp = curry(clamp)
|
|
|
279
280
|
# `from eth_utils.curried import *`
|
|
280
281
|
del Any
|
|
281
282
|
del Callable
|
|
282
|
-
del Dict
|
|
283
283
|
del Generator
|
|
284
284
|
del Optional
|
|
285
285
|
del Sequence
|
|
286
286
|
del TReturn
|
|
287
287
|
del TValue
|
|
288
|
-
del
|
|
288
|
+
del TypeGuard
|
|
289
289
|
del TypeVar
|
|
290
290
|
del Union
|
|
291
291
|
del curry
|
|
Binary file
|
|
Binary file
|