faster-eth-abi 5.2.13__cp38-cp38-win32.whl → 5.2.15__cp38-cp38-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-abi might be problematic. Click here for more details.
- 29859a9e7da9d19bb98c__mypyc.cp38-win32.pyd +0 -0
- benchmarks/test_registry_benchmarks.py +7 -4
- faster_eth_abi/_codec.cp38-win32.pyd +0 -0
- faster_eth_abi/_codec.py +1 -1
- faster_eth_abi/_decoding.cp38-win32.pyd +0 -0
- faster_eth_abi/_encoding.cp38-win32.pyd +0 -0
- faster_eth_abi/_encoding.py +141 -6
- faster_eth_abi/_grammar.cp38-win32.pyd +0 -0
- faster_eth_abi/_grammar.py +9 -3
- faster_eth_abi/abi.cp38-win32.pyd +0 -0
- faster_eth_abi/codec.py +1550 -0
- faster_eth_abi/constants.cp38-win32.pyd +0 -0
- faster_eth_abi/decoding.py +41 -16
- faster_eth_abi/encoding.py +55 -27
- faster_eth_abi/from_type_str.cp38-win32.pyd +0 -0
- faster_eth_abi/packed.cp38-win32.pyd +0 -0
- faster_eth_abi/registry.py +47 -31
- faster_eth_abi/tools/__init__.cp38-win32.pyd +0 -0
- faster_eth_abi/tools/_strategies.cp38-win32.pyd +0 -0
- faster_eth_abi/typing.py +4543 -0
- faster_eth_abi/utils/__init__.cp38-win32.pyd +0 -0
- faster_eth_abi/utils/numeric.cp38-win32.pyd +0 -0
- faster_eth_abi/utils/padding.cp38-win32.pyd +0 -0
- faster_eth_abi/utils/string.cp38-win32.pyd +0 -0
- faster_eth_abi/utils/validation.cp38-win32.pyd +0 -0
- {faster_eth_abi-5.2.13.dist-info → faster_eth_abi-5.2.15.dist-info}/METADATA +4 -4
- faster_eth_abi-5.2.15.dist-info/RECORD +58 -0
- faster_eth_abi-5.2.13.dist-info/RECORD +0 -57
- {faster_eth_abi-5.2.13.dist-info → faster_eth_abi-5.2.15.dist-info}/LICENSE +0 -0
- {faster_eth_abi-5.2.13.dist-info → faster_eth_abi-5.2.15.dist-info}/WHEEL +0 -0
- {faster_eth_abi-5.2.13.dist-info → faster_eth_abi-5.2.15.dist-info}/top_level.txt +0 -0
|
Binary file
|
faster_eth_abi/decoding.py
CHANGED
|
@@ -163,10 +163,7 @@ class SingleDecoder(BaseDecoder):
|
|
|
163
163
|
def decode(self, stream: ContextFramesBytesIO) -> Any:
|
|
164
164
|
raw_data = self.read_data_from_stream(stream)
|
|
165
165
|
data, padding_bytes = self.split_data_and_padding(raw_data)
|
|
166
|
-
|
|
167
|
-
if decoder_fn is None:
|
|
168
|
-
raise AssertionError("`decoder_fn` is None")
|
|
169
|
-
value = decoder_fn(data)
|
|
166
|
+
value = self.decoder_fn(data) # type: ignore [misc]
|
|
170
167
|
self.validate_padding_bytes(value, padding_bytes)
|
|
171
168
|
|
|
172
169
|
return value
|
|
@@ -190,6 +187,7 @@ class BaseArrayDecoder(BaseDecoder):
|
|
|
190
187
|
item_decoder = self.item_decoder
|
|
191
188
|
if item_decoder.is_dynamic:
|
|
192
189
|
self.item_decoder = HeadTailDecoder(tail_decoder=item_decoder)
|
|
190
|
+
self.validate_pointers = MethodType(validate_pointers_array, self)
|
|
193
191
|
else:
|
|
194
192
|
|
|
195
193
|
def noop(stream: ContextFramesBytesIO, array_size: int) -> None:
|
|
@@ -354,6 +352,13 @@ decode_uint_256 = UnsignedIntegerDecoder(value_bit_size=256)
|
|
|
354
352
|
class SignedIntegerDecoder(Fixed32ByteSizeDecoder):
|
|
355
353
|
is_big_endian = True
|
|
356
354
|
|
|
355
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
356
|
+
super().__init__(*args, **kwargs)
|
|
357
|
+
|
|
358
|
+
# Only assign validate_padding_bytes if not overridden in subclass
|
|
359
|
+
if type(self).validate_padding_bytes is SignedIntegerDecoder.validate_padding_bytes:
|
|
360
|
+
self.validate_padding_bytes = MethodType(validate_padding_bytes_signed_integer, self)
|
|
361
|
+
|
|
357
362
|
@cached_property
|
|
358
363
|
def neg_threshold(self) -> int:
|
|
359
364
|
return int(2 ** (self.value_bit_size - 1))
|
|
@@ -394,6 +399,10 @@ class BytesDecoder(Fixed32ByteSizeDecoder):
|
|
|
394
399
|
class BaseFixedDecoder(Fixed32ByteSizeDecoder):
|
|
395
400
|
frac_places: int = None
|
|
396
401
|
is_big_endian = True
|
|
402
|
+
|
|
403
|
+
@cached_property
|
|
404
|
+
def denominator(self) -> decimal.Decimal:
|
|
405
|
+
return TEN**self.frac_places
|
|
397
406
|
|
|
398
407
|
def validate(self) -> None:
|
|
399
408
|
super().validate()
|
|
@@ -407,11 +416,12 @@ class BaseFixedDecoder(Fixed32ByteSizeDecoder):
|
|
|
407
416
|
|
|
408
417
|
|
|
409
418
|
class UnsignedFixedDecoder(BaseFixedDecoder):
|
|
419
|
+
|
|
410
420
|
def decoder_fn(self, data: bytes) -> decimal.Decimal:
|
|
411
421
|
value = big_endian_to_int(data)
|
|
412
422
|
|
|
413
423
|
with decimal.localcontext(abi_decimal_context):
|
|
414
|
-
decimal_value = decimal.Decimal(value) /
|
|
424
|
+
decimal_value = decimal.Decimal(value) / self.denominator
|
|
415
425
|
|
|
416
426
|
return decimal_value
|
|
417
427
|
|
|
@@ -423,27 +433,42 @@ class UnsignedFixedDecoder(BaseFixedDecoder):
|
|
|
423
433
|
|
|
424
434
|
|
|
425
435
|
class SignedFixedDecoder(BaseFixedDecoder):
|
|
436
|
+
|
|
437
|
+
@cached_property
|
|
438
|
+
def neg_threshold(self) -> int:
|
|
439
|
+
return int(2 ** (self.value_bit_size - 1))
|
|
440
|
+
|
|
441
|
+
@cached_property
|
|
442
|
+
def neg_offset(self) -> int:
|
|
443
|
+
return int(2**self.value_bit_size)
|
|
444
|
+
|
|
445
|
+
@cached_property
|
|
446
|
+
def expected_padding_pos(self) -> bytes:
|
|
447
|
+
value_byte_size = get_value_byte_size(self)
|
|
448
|
+
padding_size = self.data_byte_size - value_byte_size
|
|
449
|
+
return b"\x00" * padding_size
|
|
450
|
+
|
|
451
|
+
@cached_property
|
|
452
|
+
def expected_padding_neg(self) -> bytes:
|
|
453
|
+
value_byte_size = get_value_byte_size(self)
|
|
454
|
+
padding_size = self.data_byte_size - value_byte_size
|
|
455
|
+
return b"\xff" * padding_size
|
|
456
|
+
|
|
426
457
|
def decoder_fn(self, data: bytes) -> decimal.Decimal:
|
|
427
458
|
value = big_endian_to_int(data)
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
signed_value = value - 2**value_bit_size
|
|
431
|
-
else:
|
|
432
|
-
signed_value = value
|
|
459
|
+
if value >= self.neg_threshold:
|
|
460
|
+
value -= self.neg_offset
|
|
433
461
|
|
|
434
462
|
with decimal.localcontext(abi_decimal_context):
|
|
435
|
-
decimal_value = decimal.Decimal(
|
|
463
|
+
decimal_value = decimal.Decimal(value) / self.denominator
|
|
436
464
|
|
|
437
465
|
return decimal_value
|
|
438
466
|
|
|
439
467
|
def validate_padding_bytes(self, value: Any, padding_bytes: bytes) -> None:
|
|
440
|
-
value_byte_size = get_value_byte_size(self)
|
|
441
|
-
padding_size = self.data_byte_size - value_byte_size
|
|
442
|
-
|
|
443
468
|
if value >= 0:
|
|
444
|
-
expected_padding_bytes =
|
|
469
|
+
expected_padding_bytes = self.expected_padding_pos
|
|
445
470
|
else:
|
|
446
|
-
expected_padding_bytes =
|
|
471
|
+
expected_padding_bytes = self.expected_padding_neg
|
|
447
472
|
|
|
448
473
|
if padding_bytes != expected_padding_bytes:
|
|
449
474
|
raise NonEmptyPaddingBytes(
|
faster_eth_abi/encoding.py
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import abc
|
|
2
2
|
import codecs
|
|
3
3
|
import decimal
|
|
4
|
+
from functools import (
|
|
5
|
+
cached_property,
|
|
6
|
+
)
|
|
7
|
+
from types import (
|
|
8
|
+
MethodType,
|
|
9
|
+
)
|
|
4
10
|
from typing import (
|
|
5
11
|
Any,
|
|
6
12
|
Callable,
|
|
7
13
|
ClassVar,
|
|
14
|
+
Final,
|
|
8
15
|
NoReturn,
|
|
9
16
|
Optional,
|
|
10
17
|
Sequence,
|
|
11
18
|
Tuple,
|
|
12
19
|
Type,
|
|
20
|
+
final,
|
|
13
21
|
)
|
|
14
22
|
|
|
15
23
|
from faster_eth_utils import (
|
|
@@ -32,7 +40,11 @@ from faster_eth_abi._encoding import (
|
|
|
32
40
|
encode_fixed,
|
|
33
41
|
encode_signed,
|
|
34
42
|
encode_tuple,
|
|
43
|
+
encode_tuple_all_dynamic,
|
|
44
|
+
encode_tuple_no_dynamic,
|
|
45
|
+
encode_tuple_no_dynamic_funcs,
|
|
35
46
|
int_to_big_endian,
|
|
47
|
+
validate_tuple,
|
|
36
48
|
)
|
|
37
49
|
from faster_eth_abi.base import (
|
|
38
50
|
BaseCoder,
|
|
@@ -111,7 +123,33 @@ class TupleEncoder(BaseEncoder):
|
|
|
111
123
|
def __init__(self, encoders: Tuple[BaseEncoder, ...], **kwargs: Any) -> None:
|
|
112
124
|
super().__init__(encoders=encoders, **kwargs)
|
|
113
125
|
|
|
114
|
-
self.
|
|
126
|
+
self._is_dynamic: Final = tuple(getattr(e, "is_dynamic", False) for e in self.encoders)
|
|
127
|
+
self.is_dynamic = any(self._is_dynamic)
|
|
128
|
+
|
|
129
|
+
validators = []
|
|
130
|
+
for encoder in self.encoders:
|
|
131
|
+
try:
|
|
132
|
+
validator = encoder.validate_value
|
|
133
|
+
except AttributeError:
|
|
134
|
+
validators.append(encoder)
|
|
135
|
+
else:
|
|
136
|
+
validators.append(validator)
|
|
137
|
+
|
|
138
|
+
self.validators: Final[Callable[[Any], None]] = tuple(validators)
|
|
139
|
+
|
|
140
|
+
if type(self).encode is TupleEncoder.encode:
|
|
141
|
+
encode_func = (
|
|
142
|
+
encode_tuple_all_dynamic
|
|
143
|
+
if all(self._is_dynamic)
|
|
144
|
+
else encode_tuple_no_dynamic_funcs.get(
|
|
145
|
+
len(self.encoders),
|
|
146
|
+
encode_tuple_no_dynamic,
|
|
147
|
+
)
|
|
148
|
+
if not self.is_dynamic
|
|
149
|
+
else encode_tuple
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
self.encode = MethodType(encode_func, self)
|
|
115
153
|
|
|
116
154
|
def validate(self) -> None:
|
|
117
155
|
super().validate()
|
|
@@ -119,33 +157,15 @@ class TupleEncoder(BaseEncoder):
|
|
|
119
157
|
if self.encoders is None:
|
|
120
158
|
raise ValueError("`encoders` may not be none")
|
|
121
159
|
|
|
160
|
+
@final
|
|
122
161
|
def validate_value(self, value: Sequence[Any]) -> None:
|
|
123
|
-
|
|
124
|
-
self.invalidate_value(
|
|
125
|
-
value,
|
|
126
|
-
msg="must be list-like object such as array or tuple",
|
|
127
|
-
)
|
|
128
|
-
|
|
129
|
-
encoders = self.encoders
|
|
130
|
-
if len(value) != len(encoders):
|
|
131
|
-
self.invalidate_value(
|
|
132
|
-
value,
|
|
133
|
-
exc=ValueOutOfBounds,
|
|
134
|
-
msg=f"value has {len(value)} items when {len(encoders)} "
|
|
135
|
-
"were expected",
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
for item, encoder in zip(value, encoders):
|
|
139
|
-
try:
|
|
140
|
-
encoder.validate_value(item)
|
|
141
|
-
except AttributeError:
|
|
142
|
-
encoder(item)
|
|
162
|
+
validate_tuple(self, value)
|
|
143
163
|
|
|
144
164
|
def encode(self, values: Sequence[Any]) -> bytes:
|
|
145
|
-
self
|
|
146
|
-
return encode_tuple(values, self.encoders)
|
|
165
|
+
return encode_tuple(self, values)
|
|
147
166
|
|
|
148
|
-
__call__:
|
|
167
|
+
def __call__(self, values: Sequence[Any]) -> bytes:
|
|
168
|
+
return self.encode(values)
|
|
149
169
|
|
|
150
170
|
@parse_tuple_type_str
|
|
151
171
|
def from_type_str(cls, abi_type, registry):
|
|
@@ -328,11 +348,19 @@ class BaseFixedEncoder(NumberEncoder):
|
|
|
328
348
|
|
|
329
349
|
return False
|
|
330
350
|
|
|
351
|
+
@cached_property
|
|
352
|
+
def denominator(self) -> decimal.Decimal:
|
|
353
|
+
return TEN**self.frac_places
|
|
354
|
+
|
|
355
|
+
@cached_property
|
|
356
|
+
def precision(self) -> int:
|
|
357
|
+
return TEN**-self.frac_places
|
|
358
|
+
|
|
331
359
|
def validate_value(self, value):
|
|
332
360
|
super().validate_value(value)
|
|
333
361
|
|
|
334
362
|
with decimal.localcontext(abi_decimal_context):
|
|
335
|
-
residue = value %
|
|
363
|
+
residue = value % self.precision
|
|
336
364
|
|
|
337
365
|
if residue > 0:
|
|
338
366
|
self.invalidate_value(
|
|
@@ -359,7 +387,7 @@ class UnsignedFixedEncoder(BaseFixedEncoder):
|
|
|
359
387
|
|
|
360
388
|
def encode_fn(self, value):
|
|
361
389
|
with decimal.localcontext(abi_decimal_context):
|
|
362
|
-
scaled_value = value *
|
|
390
|
+
scaled_value = value * self.denominator
|
|
363
391
|
integer_value = int(scaled_value)
|
|
364
392
|
|
|
365
393
|
return int_to_big_endian(integer_value)
|
|
@@ -392,7 +420,7 @@ class SignedFixedEncoder(BaseFixedEncoder):
|
|
|
392
420
|
|
|
393
421
|
def encode_fn(self, value):
|
|
394
422
|
with decimal.localcontext(abi_decimal_context):
|
|
395
|
-
scaled_value = value *
|
|
423
|
+
scaled_value = value * self.denominator
|
|
396
424
|
integer_value = int(scaled_value)
|
|
397
425
|
|
|
398
426
|
unsigned_integer_value = integer_value % (2**self.value_bit_size)
|
|
Binary file
|
|
Binary file
|
faster_eth_abi/registry.py
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import abc
|
|
2
|
+
from copy import (
|
|
3
|
+
copy,
|
|
4
|
+
)
|
|
2
5
|
import functools
|
|
3
|
-
from copy import copy
|
|
4
6
|
from typing import (
|
|
5
7
|
Any,
|
|
6
8
|
Callable,
|
|
7
9
|
Dict,
|
|
8
10
|
Final,
|
|
9
11
|
Generic,
|
|
12
|
+
Iterator,
|
|
10
13
|
Optional,
|
|
11
14
|
Type,
|
|
12
15
|
TypeVar,
|
|
@@ -17,6 +20,8 @@ from eth_typing import (
|
|
|
17
20
|
TypeStr,
|
|
18
21
|
)
|
|
19
22
|
from typing_extensions import (
|
|
23
|
+
Concatenate,
|
|
24
|
+
ParamSpec,
|
|
20
25
|
Self,
|
|
21
26
|
)
|
|
22
27
|
|
|
@@ -38,6 +43,7 @@ from .io import (
|
|
|
38
43
|
)
|
|
39
44
|
|
|
40
45
|
T = TypeVar("T")
|
|
46
|
+
P = ParamSpec("P")
|
|
41
47
|
|
|
42
48
|
Lookup = Union[TypeStr, Callable[[TypeStr], bool]]
|
|
43
49
|
|
|
@@ -177,25 +183,25 @@ class Predicate:
|
|
|
177
183
|
``ABIRegistry``.
|
|
178
184
|
"""
|
|
179
185
|
|
|
180
|
-
__slots__ =
|
|
186
|
+
__slots__ = ()
|
|
181
187
|
|
|
182
188
|
def __call__(self, *args, **kwargs): # pragma: no cover
|
|
183
189
|
raise NotImplementedError("Must implement `__call__`")
|
|
184
190
|
|
|
185
|
-
def __str__(self)
|
|
191
|
+
def __str__(self) -> str:
|
|
186
192
|
raise NotImplementedError("Must implement `__str__`")
|
|
187
193
|
|
|
188
|
-
def __repr__(self):
|
|
194
|
+
def __repr__(self) -> str:
|
|
189
195
|
return f"<{type(self).__name__} {self}>"
|
|
190
196
|
|
|
191
|
-
def __iter__(self):
|
|
197
|
+
def __iter__(self) -> Iterator[Any]:
|
|
192
198
|
for attr in self.__slots__:
|
|
193
199
|
yield getattr(self, attr)
|
|
194
200
|
|
|
195
|
-
def __hash__(self):
|
|
201
|
+
def __hash__(self) -> int:
|
|
196
202
|
return hash(tuple(self))
|
|
197
203
|
|
|
198
|
-
def __eq__(self, other):
|
|
204
|
+
def __eq__(self, other: Any) -> bool:
|
|
199
205
|
return type(self) is type(other) and tuple(self) == tuple(other)
|
|
200
206
|
|
|
201
207
|
|
|
@@ -209,10 +215,10 @@ class Equals(Predicate):
|
|
|
209
215
|
def __init__(self, value):
|
|
210
216
|
self.value = value
|
|
211
217
|
|
|
212
|
-
def __call__(self, other):
|
|
218
|
+
def __call__(self, other: Any) -> bool:
|
|
213
219
|
return self.value == other
|
|
214
220
|
|
|
215
|
-
def __str__(self):
|
|
221
|
+
def __str__(self) -> str:
|
|
216
222
|
return f"(== {self.value!r})"
|
|
217
223
|
|
|
218
224
|
|
|
@@ -231,7 +237,7 @@ class BaseEquals(Predicate):
|
|
|
231
237
|
self.base = base
|
|
232
238
|
self.with_sub = with_sub
|
|
233
239
|
|
|
234
|
-
def __call__(self, type_str):
|
|
240
|
+
def __call__(self, type_str: TypeStr) -> bool:
|
|
235
241
|
try:
|
|
236
242
|
abi_type = grammar.parse(type_str)
|
|
237
243
|
except (exceptions.ParseError, ValueError):
|
|
@@ -253,7 +259,7 @@ class BaseEquals(Predicate):
|
|
|
253
259
|
# e.g. if it contained a tuple type
|
|
254
260
|
return False
|
|
255
261
|
|
|
256
|
-
def __str__(self):
|
|
262
|
+
def __str__(self) -> str:
|
|
257
263
|
return (
|
|
258
264
|
f"(base == {self.base!r}"
|
|
259
265
|
+ (
|
|
@@ -265,7 +271,7 @@ class BaseEquals(Predicate):
|
|
|
265
271
|
)
|
|
266
272
|
|
|
267
273
|
|
|
268
|
-
def has_arrlist(type_str):
|
|
274
|
+
def has_arrlist(type_str: TypeStr) -> bool:
|
|
269
275
|
"""
|
|
270
276
|
A predicate that matches a type string with an array dimension list.
|
|
271
277
|
"""
|
|
@@ -277,7 +283,7 @@ def has_arrlist(type_str):
|
|
|
277
283
|
return abi_type.arrlist is not None
|
|
278
284
|
|
|
279
285
|
|
|
280
|
-
def is_base_tuple(type_str):
|
|
286
|
+
def is_base_tuple(type_str: TypeStr) -> bool:
|
|
281
287
|
"""
|
|
282
288
|
A predicate that matches a tuple type with no array dimension list.
|
|
283
289
|
"""
|
|
@@ -289,9 +295,11 @@ def is_base_tuple(type_str):
|
|
|
289
295
|
return isinstance(abi_type, grammar.TupleType) and abi_type.arrlist is None
|
|
290
296
|
|
|
291
297
|
|
|
292
|
-
def _clear_encoder_cache(
|
|
298
|
+
def _clear_encoder_cache(
|
|
299
|
+
old_method: Callable[Concatenate["ABIRegistry", P], T]
|
|
300
|
+
) -> Callable[Concatenate["ABIRegistry", P], T]:
|
|
293
301
|
@functools.wraps(old_method)
|
|
294
|
-
def new_method(self: "ABIRegistry", *args:
|
|
302
|
+
def new_method(self: "ABIRegistry", *args: P.args, **kwargs: P.kwargs) -> T:
|
|
295
303
|
self.get_encoder.cache_clear()
|
|
296
304
|
self.get_tuple_encoder.cache_clear()
|
|
297
305
|
return old_method(self, *args, **kwargs)
|
|
@@ -299,9 +307,11 @@ def _clear_encoder_cache(old_method: Callable[..., None]) -> Callable[..., None]
|
|
|
299
307
|
return new_method
|
|
300
308
|
|
|
301
309
|
|
|
302
|
-
def _clear_decoder_cache(
|
|
310
|
+
def _clear_decoder_cache(
|
|
311
|
+
old_method: Callable[Concatenate["ABIRegistry", P], T]
|
|
312
|
+
) -> Callable[Concatenate["ABIRegistry", P], T]:
|
|
303
313
|
@functools.wraps(old_method)
|
|
304
|
-
def new_method(self: "ABIRegistry", *args:
|
|
314
|
+
def new_method(self: "ABIRegistry", *args: P.args, **kwargs: P.kwargs) -> T:
|
|
305
315
|
self.get_decoder.cache_clear()
|
|
306
316
|
self.get_tuple_decoder.cache_clear()
|
|
307
317
|
return old_method(self, *args, **kwargs)
|
|
@@ -311,7 +321,12 @@ def _clear_decoder_cache(old_method: Callable[..., None]) -> Callable[..., None]
|
|
|
311
321
|
|
|
312
322
|
class BaseRegistry:
|
|
313
323
|
@staticmethod
|
|
314
|
-
def _register(
|
|
324
|
+
def _register(
|
|
325
|
+
mapping: PredicateMapping[T],
|
|
326
|
+
lookup: Lookup,
|
|
327
|
+
value: T,
|
|
328
|
+
label: Optional[str] = None,
|
|
329
|
+
) -> None:
|
|
315
330
|
if callable(lookup):
|
|
316
331
|
mapping.add(lookup, value, label)
|
|
317
332
|
return
|
|
@@ -325,7 +340,7 @@ class BaseRegistry:
|
|
|
325
340
|
)
|
|
326
341
|
|
|
327
342
|
@staticmethod
|
|
328
|
-
def _unregister(mapping, lookup_or_label):
|
|
343
|
+
def _unregister(mapping: PredicateMapping[Any], lookup_or_label: Lookup) -> None:
|
|
329
344
|
if callable(lookup_or_label):
|
|
330
345
|
mapping.remove_by_equality(lookup_or_label)
|
|
331
346
|
return
|
|
@@ -340,7 +355,7 @@ class BaseRegistry:
|
|
|
340
355
|
)
|
|
341
356
|
|
|
342
357
|
@staticmethod
|
|
343
|
-
def _get_registration(mapping, type_str):
|
|
358
|
+
def _get_registration(mapping: PredicateMapping[T], type_str: TypeStr) -> T:
|
|
344
359
|
try:
|
|
345
360
|
value = mapping.find(type_str)
|
|
346
361
|
except ValueError as e:
|
|
@@ -473,16 +488,15 @@ class ABIRegistry(Copyable, BaseRegistry):
|
|
|
473
488
|
self.unregister_encoder(label)
|
|
474
489
|
self.unregister_decoder(label)
|
|
475
490
|
|
|
476
|
-
def _get_encoder_uncached(self, type_str: TypeStr)
|
|
491
|
+
def _get_encoder_uncached(self, type_str: TypeStr) -> Encoder:
|
|
477
492
|
return self._get_registration(self._encoders, type_str)
|
|
478
493
|
|
|
479
494
|
def _get_tuple_encoder_uncached(
|
|
480
|
-
self,
|
|
495
|
+
self,
|
|
481
496
|
*type_strs: TypeStr,
|
|
482
497
|
) -> encoding.TupleEncoder:
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
)
|
|
498
|
+
encoders = tuple(map(self.get_encoder, type_strs))
|
|
499
|
+
return encoding.TupleEncoder(encoders=encoders)
|
|
486
500
|
|
|
487
501
|
def has_encoder(self, type_str: TypeStr) -> bool:
|
|
488
502
|
"""
|
|
@@ -500,7 +514,7 @@ class ABIRegistry(Copyable, BaseRegistry):
|
|
|
500
514
|
|
|
501
515
|
return True
|
|
502
516
|
|
|
503
|
-
def _get_decoder_uncached(self, type_str: TypeStr, strict: bool = True)
|
|
517
|
+
def _get_decoder_uncached(self, type_str: TypeStr, strict: bool = True) -> Decoder:
|
|
504
518
|
decoder = self._get_registration(self._decoders, type_str)
|
|
505
519
|
|
|
506
520
|
if hasattr(decoder, "is_dynamic") and decoder.is_dynamic:
|
|
@@ -512,15 +526,17 @@ class ABIRegistry(Copyable, BaseRegistry):
|
|
|
512
526
|
return decoder
|
|
513
527
|
|
|
514
528
|
def _get_tuple_decoder_uncached(
|
|
515
|
-
self,
|
|
516
|
-
*type_strs: TypeStr,
|
|
529
|
+
self,
|
|
530
|
+
*type_strs: TypeStr,
|
|
517
531
|
strict: bool = True,
|
|
518
532
|
) -> decoding.TupleDecoder:
|
|
519
|
-
|
|
520
|
-
|
|
533
|
+
decoders = tuple(
|
|
534
|
+
self.get_decoder(type_str, strict) # type: ignore [misc]
|
|
535
|
+
for type_str in type_strs
|
|
521
536
|
)
|
|
537
|
+
return decoding.TupleDecoder(decoders=decoders)
|
|
522
538
|
|
|
523
|
-
def copy(self):
|
|
539
|
+
def copy(self) -> Self:
|
|
524
540
|
"""
|
|
525
541
|
Copies a registry such that new registrations can be made or existing
|
|
526
542
|
registrations can be unregistered without affecting any instance from
|
|
Binary file
|
|
Binary file
|