faster-eth-abi 5.2.13__cp313-cp313-macosx_11_0_arm64.whl → 5.2.15__cp313-cp313-macosx_11_0_arm64.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.

Files changed (31) hide show
  1. benchmarks/test_registry_benchmarks.py +7 -4
  2. faster_eth_abi/_codec.cpython-313-darwin.so +0 -0
  3. faster_eth_abi/_codec.py +1 -1
  4. faster_eth_abi/_decoding.cpython-313-darwin.so +0 -0
  5. faster_eth_abi/_encoding.cpython-313-darwin.so +0 -0
  6. faster_eth_abi/_encoding.py +141 -6
  7. faster_eth_abi/_grammar.cpython-313-darwin.so +0 -0
  8. faster_eth_abi/_grammar.py +9 -3
  9. faster_eth_abi/abi.cpython-313-darwin.so +0 -0
  10. faster_eth_abi/codec.py +1550 -0
  11. faster_eth_abi/constants.cpython-313-darwin.so +0 -0
  12. faster_eth_abi/decoding.py +41 -16
  13. faster_eth_abi/encoding.py +55 -27
  14. faster_eth_abi/from_type_str.cpython-313-darwin.so +0 -0
  15. faster_eth_abi/packed.cpython-313-darwin.so +0 -0
  16. faster_eth_abi/registry.py +47 -31
  17. faster_eth_abi/tools/__init__.cpython-313-darwin.so +0 -0
  18. faster_eth_abi/tools/_strategies.cpython-313-darwin.so +0 -0
  19. faster_eth_abi/typing.py +4543 -0
  20. faster_eth_abi/utils/__init__.cpython-313-darwin.so +0 -0
  21. faster_eth_abi/utils/numeric.cpython-313-darwin.so +0 -0
  22. faster_eth_abi/utils/padding.cpython-313-darwin.so +0 -0
  23. faster_eth_abi/utils/string.cpython-313-darwin.so +0 -0
  24. faster_eth_abi/utils/validation.cpython-313-darwin.so +0 -0
  25. {faster_eth_abi-5.2.13.dist-info → faster_eth_abi-5.2.15.dist-info}/METADATA +4 -4
  26. faster_eth_abi-5.2.15.dist-info/RECORD +58 -0
  27. faster_eth_abi__mypyc.cpython-313-darwin.so +0 -0
  28. faster_eth_abi-5.2.13.dist-info/RECORD +0 -57
  29. {faster_eth_abi-5.2.13.dist-info → faster_eth_abi-5.2.15.dist-info}/WHEEL +0 -0
  30. {faster_eth_abi-5.2.13.dist-info → faster_eth_abi-5.2.15.dist-info}/licenses/LICENSE +0 -0
  31. {faster_eth_abi-5.2.13.dist-info → faster_eth_abi-5.2.15.dist-info}/top_level.txt +0 -0
@@ -18,25 +18,28 @@ from faster_eth_abi.registry import (
18
18
  )
19
19
 
20
20
 
21
+ ITERATIONS = 50_000
22
+
23
+
21
24
  @pytest.mark.benchmark(group="RegistryGetEncoder")
22
25
  @pytest.mark.parametrize("type_str", type_strings)
23
26
  def test_get_encoder(benchmark: BenchmarkFixture, type_str):
24
- benchmark(batch, 1000, registry.get_encoder, type_str)
27
+ benchmark(batch, ITERATIONS, registry.get_encoder, type_str)
25
28
 
26
29
 
27
30
  @pytest.mark.benchmark(group="RegistryGetEncoder")
28
31
  @pytest.mark.parametrize("type_str", type_strings)
29
32
  def test_faster_get_encoder(benchmark: BenchmarkFixture, type_str):
30
- benchmark(batch, 1000, faster_registry.get_encoder, type_str)
33
+ benchmark(batch, ITERATIONS, faster_registry.get_encoder, type_str)
31
34
 
32
35
 
33
36
  @pytest.mark.benchmark(group="RegistryGetDecoder")
34
37
  @pytest.mark.parametrize("type_str", type_strings)
35
38
  def test_get_decoder(benchmark: BenchmarkFixture, type_str):
36
- benchmark(batch, 1000, registry.get_decoder, type_str)
39
+ benchmark(batch, ITERATIONS, registry.get_decoder, type_str)
37
40
 
38
41
 
39
42
  @pytest.mark.benchmark(group="RegistryGetDecoder")
40
43
  @pytest.mark.parametrize("type_str", type_strings)
41
44
  def test_faster_get_decoder(benchmark: BenchmarkFixture, type_str):
42
- benchmark(batch, 1000, faster_registry.get_decoder, type_str)
45
+ benchmark(batch, ITERATIONS, faster_registry.get_decoder, type_str)
Binary file
faster_eth_abi/_codec.py CHANGED
@@ -43,7 +43,7 @@ def encode_c(
43
43
 
44
44
  encoder = self._registry.get_tuple_encoder(*types)
45
45
 
46
- return encoder(args)
46
+ return encoder.encode(args)
47
47
 
48
48
 
49
49
  def decode_c(
@@ -2,29 +2,59 @@ from typing import (
2
2
  TYPE_CHECKING,
3
3
  Any,
4
4
  Callable,
5
+ Dict,
5
6
  List,
6
7
  Optional,
7
8
  Sequence,
9
+ Tuple,
8
10
  TypeVar,
9
11
  )
10
12
 
13
+ from faster_eth_utils import (
14
+ is_list_like,
15
+ )
16
+
17
+ from faster_eth_abi.exceptions import (
18
+ ValueOutOfBounds,
19
+ )
20
+
11
21
  if TYPE_CHECKING:
12
22
  from faster_eth_abi.encoding import (
13
23
  BaseEncoder,
24
+ TupleEncoder,
14
25
  )
15
26
 
16
27
 
17
28
  T = TypeVar("T")
18
29
 
19
30
 
20
- def encode_tuple(
21
- values: Sequence[Any],
22
- encoders: Sequence["BaseEncoder"],
23
- ) -> bytes:
31
+ # TupleEncoder
32
+ def validate_tuple(self: "TupleEncoder", value: Sequence[Any]) -> None:
33
+ # if we check list and tuple first it compiles to much quicker C code
34
+ if not isinstance(value, (list, tuple)) and not is_list_like(value):
35
+ self.invalidate_value(
36
+ value,
37
+ msg="must be list-like object such as array or tuple",
38
+ )
39
+
40
+ validators = self.validators
41
+ if len(value) != len(validators):
42
+ self.invalidate_value(
43
+ value,
44
+ exc=ValueOutOfBounds,
45
+ msg=f"value has {len(value)} items when {len(validators)} " "were expected",
46
+ )
47
+
48
+ for item, validator in zip(value, validators):
49
+ validator(item)
50
+
51
+
52
+ def encode_tuple(self: "TupleEncoder", values: Sequence[Any]) -> bytes:
53
+ validate_tuple(self, values)
24
54
  raw_head_chunks: List[Optional[bytes]] = []
25
55
  tail_chunks: List[bytes] = []
26
- for value, encoder in zip(values, encoders):
27
- if getattr(encoder, "is_dynamic", False):
56
+ for value, encoder, is_dynamic in zip(values, self.encoders, self._is_dynamic):
57
+ if is_dynamic:
28
58
  raw_head_chunks.append(None)
29
59
  tail_chunks.append(encoder(value))
30
60
  else:
@@ -46,6 +76,111 @@ def encode_tuple(
46
76
  return b"".join(head_chunks) + b"".join(tail_chunks)
47
77
 
48
78
 
79
+ def encode_tuple_all_dynamic(self: "TupleEncoder", values: Sequence[Any]) -> bytes:
80
+ validate_tuple(self, values)
81
+ encoders = self.encoders
82
+ tail_chunks = [encoder(value) for encoder, value in zip(encoders, values)]
83
+
84
+ total_offset = 0
85
+ head_length = 32 * len(encoders)
86
+ head_chunks = [encode_uint_256(head_length)]
87
+ for item in tail_chunks[:-1]:
88
+ total_offset += len(item)
89
+ head_chunks.append(encode_uint_256(head_length + total_offset))
90
+
91
+ return b"".join(head_chunks) + b"".join(tail_chunks)
92
+
93
+
94
+ def encode_tuple_no_dynamic(self: "TupleEncoder", values: Sequence[Any]) -> bytes:
95
+ validate_tuple(self, values)
96
+ encoders = self.encoders
97
+ return b"".join(encoders[i](values[i]) for i in range(len(encoders)))
98
+
99
+
100
+ def encode_tuple_no_dynamic1(self: "TupleEncoder", values: Sequence[Any]) -> bytes:
101
+ validate_tuple(self, values)
102
+ encoders: Tuple["BaseEncoder"] = self.encoders
103
+ return encoders[0](values[0])
104
+
105
+
106
+ def encode_tuple_no_dynamic2(self: "TupleEncoder", values: Sequence[Any]) -> bytes:
107
+ validate_tuple(self, values)
108
+ encoders = self.encoders
109
+ # encoders: Tuple["BaseEncoder", "BaseEncoder"] = self.encoders
110
+ return encoders[0](values[0]) + encoders[1](values[1])
111
+
112
+
113
+ def encode_tuple_no_dynamic3(self: "TupleEncoder", values: Sequence[Any]) -> bytes:
114
+ validate_tuple(self, values)
115
+ encoders = self.encoders
116
+ # encoders: Tuple["BaseEncoder", "BaseEncoder", "BaseEncoder"] = self.encoders
117
+ return b"".join(encoders[i](values[i]) for i in range(3))
118
+
119
+
120
+ def encode_tuple_no_dynamic4(self: "TupleEncoder", values: Sequence[Any]) -> bytes:
121
+ validate_tuple(self, values)
122
+ encoders = self.encoders
123
+ # encoders: Tuple["BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder"] = self.encoders
124
+ return b"".join(encoders[i](values[i]) for i in range(4))
125
+
126
+
127
+ def encode_tuple_no_dynamic5(self: "TupleEncoder", values: Sequence[Any]) -> bytes:
128
+ validate_tuple(self, values)
129
+ encoders = self.encoders
130
+ # encoders: Tuple["BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder"] = self.encoders
131
+ return b"".join(encoders[i](values[i]) for i in range(5))
132
+
133
+
134
+ def encode_tuple_no_dynamic6(self: "TupleEncoder", values: Sequence[Any]) -> bytes:
135
+ validate_tuple(self, values)
136
+ encoders = self.encoders
137
+ # encoders: Tuple["BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder"] = self.encoders
138
+ return b"".join(encoders[i](values[i]) for i in range(6))
139
+
140
+
141
+ def encode_tuple_no_dynamic7(self: "TupleEncoder", values: Sequence[Any]) -> bytes:
142
+ validate_tuple(self, values)
143
+ encoders = self.encoders
144
+ # encoders: Tuple["BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder"] = self.encoders
145
+ return b"".join(encoders[i](values[i]) for i in range(7))
146
+
147
+
148
+ def encode_tuple_no_dynamic8(self: "TupleEncoder", values: Sequence[Any]) -> bytes:
149
+ validate_tuple(self, values)
150
+ encoders = self.encoders
151
+ # encoders: Tuple["BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder"] = self.encoders
152
+ return b"".join(encoders[i](values[i]) for i in range(8))
153
+
154
+
155
+ def encode_tuple_no_dynamic9(self: "TupleEncoder", values: Sequence[Any]) -> bytes:
156
+ validate_tuple(self, values)
157
+ encoders = self.encoders
158
+ # encoders: Tuple["BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder"] = self.encoders
159
+ return b"".join(encoders[i](values[i]) for i in range(9))
160
+
161
+
162
+ def encode_tuple_no_dynamic10(self: "TupleEncoder", values: Sequence[Any]) -> bytes:
163
+ validate_tuple(self, values)
164
+ encoders = self.encoders
165
+ # encoders: Tuple["BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder", "BaseEncoder"] = self.encoders
166
+ return b"".join(encoders[i](values[i]) for i in range(10))
167
+
168
+ encode_tuple_no_dynamic_funcs: Dict[
169
+ int, Callable[["TupleEncoder", Sequence[Any]], bytes]
170
+ ] = {
171
+ 1: encode_tuple_no_dynamic1,
172
+ 2: encode_tuple_no_dynamic2,
173
+ 3: encode_tuple_no_dynamic3,
174
+ 4: encode_tuple_no_dynamic4,
175
+ 5: encode_tuple_no_dynamic5,
176
+ 6: encode_tuple_no_dynamic6,
177
+ 7: encode_tuple_no_dynamic7,
178
+ 8: encode_tuple_no_dynamic8,
179
+ 9: encode_tuple_no_dynamic9,
180
+ 10: encode_tuple_no_dynamic10,
181
+ }
182
+
183
+
49
184
  def encode_fixed(
50
185
  value: Any,
51
186
  encode_fn: Callable[[Any], bytes],
@@ -2,6 +2,8 @@ import re
2
2
  from typing import (
3
3
  Any,
4
4
  Final,
5
+ Generic,
6
+ Literal,
5
7
  NewType,
6
8
  NoReturn,
7
9
  Optional,
@@ -29,7 +31,6 @@ from faster_eth_abi.exceptions import (
29
31
  ABITypeError,
30
32
  )
31
33
 
32
-
33
34
  TYPE_ALIASES: Final = {
34
35
  "int": "int256",
35
36
  "uint": "uint256",
@@ -47,6 +48,7 @@ TYPE_ALIAS_RE: Final = re.compile(
47
48
  IntSubtype = NewType("IntSubtype", int)
48
49
  FixedSubtype = NewType("FixedSubtype", Tuple[int, int])
49
50
  Subtype = Union[IntSubtype, FixedSubtype]
51
+ TSub = TypeVar("TSub", IntSubtype, FixedSubtype, Literal[None])
50
52
 
51
53
 
52
54
  @mypyc_attr(allow_interpreted_subclasses=True)
@@ -202,7 +204,7 @@ class TupleType(ABIType):
202
204
 
203
205
 
204
206
  @mypyc_attr(allow_interpreted_subclasses=True)
205
- class BasicType(ABIType):
207
+ class BasicType(ABIType, Generic[TSub]):
206
208
  """
207
209
  Represents the result of parsing a basic type string e.g. "uint", "address",
208
210
  "ufixed128x19[][2]".
@@ -213,7 +215,7 @@ class BasicType(ABIType):
213
215
  def __init__(
214
216
  self,
215
217
  base: str,
216
- sub: Optional[Subtype] = None,
218
+ sub: Optional[TSub] = None,
217
219
  arrlist: Optional[Sequence] = None,
218
220
  *,
219
221
  node: Optional[Node] = None,
@@ -334,6 +336,10 @@ class BasicType(ABIType):
334
336
  self.invalidate("address cannot have suffix")
335
337
 
336
338
 
339
+ BytesType = BasicType[IntSubtype]
340
+ FixedType = BasicType[FixedSubtype]
341
+
342
+
337
343
  def normalize(type_str: TypeStr) -> TypeStr:
338
344
  """
339
345
  Normalizes a type string into its canonical version e.g. the type string
Binary file