faster-eth-abi 5.2.9__tar.gz → 5.2.11__tar.gz

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 (79) hide show
  1. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/PKG-INFO +1 -1
  2. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/_codec.py +0 -4
  3. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/_decoding.py +46 -0
  4. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/_encoding.py +12 -5
  5. faster_eth_abi-5.2.9/faster_eth_abi/grammar.py → faster_eth_abi-5.2.11/faster_eth_abi/_grammar.py +45 -164
  6. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/codec.py +8 -9
  7. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/decoding.py +11 -31
  8. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/from_type_str.py +3 -1
  9. faster_eth_abi-5.2.11/faster_eth_abi/grammar.py +170 -0
  10. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/registry.py +37 -24
  11. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/tools/_strategies.py +9 -5
  12. faster_eth_abi-5.2.11/faster_eth_abi/utils/numeric.py +117 -0
  13. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi.egg-info/PKG-INFO +1 -1
  14. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi.egg-info/SOURCES.txt +1 -0
  15. faster_eth_abi-5.2.11/faster_eth_abi.egg-info/top_level.txt +2 -0
  16. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/pyproject.toml +2 -2
  17. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/setup.py +2 -1
  18. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/abi_tests/test_decode.py +11 -4
  19. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/abi_tests/test_encode.py +14 -3
  20. faster_eth_abi-5.2.9/faster_eth_abi/utils/numeric.py +0 -86
  21. faster_eth_abi-5.2.9/faster_eth_abi.egg-info/top_level.txt +0 -2
  22. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/LICENSE +0 -0
  23. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/MANIFEST.in +0 -0
  24. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/README.md +0 -0
  25. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/__init__.py +0 -0
  26. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/abi.py +0 -0
  27. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/base.py +0 -0
  28. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/constants.py +0 -0
  29. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/encoding.py +0 -0
  30. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/exceptions.py +0 -0
  31. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/io.py +0 -0
  32. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/packed.py +0 -0
  33. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/py.typed +0 -0
  34. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/tools/__init__.py +0 -0
  35. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/utils/__init__.py +0 -0
  36. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/utils/padding.py +0 -0
  37. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/utils/string.py +0 -0
  38. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi/utils/validation.py +0 -0
  39. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi.egg-info/dependency_links.txt +0 -0
  40. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi.egg-info/not-zip-safe +0 -0
  41. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/faster_eth_abi.egg-info/requires.txt +0 -0
  42. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/scripts/benchmark/compare_benchmark_results.py +0 -0
  43. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/scripts/benchmark/generate_benchmark_markdown.py +0 -0
  44. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/scripts/benchmark/parse_benchmark_output.py +0 -0
  45. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/scripts/release/test_package.py +0 -0
  46. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/setup.cfg +0 -0
  47. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/__init__.py +0 -0
  48. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/abi_tests/__init__.py +0 -0
  49. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/abi_tests/test_is_encodable.py +0 -0
  50. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/abi_tests/test_is_encodable_type.py +0 -0
  51. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/abi_tests/test_reversibility_properties.py +0 -0
  52. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/abi_tests/test_uint_properties.py +0 -0
  53. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/base.py +0 -0
  54. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/common/__init__.py +0 -0
  55. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/common/strategies.py +0 -0
  56. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/common/unit.py +0 -0
  57. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/decoding/__init__.py +0 -0
  58. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/decoding/test_context_frames_bytes_io.py +0 -0
  59. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/decoding/test_decoder_properties.py +0 -0
  60. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/encoding/__init__.py +0 -0
  61. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/encoding/test_encoder_properties.py +0 -0
  62. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/end_to_end/__init__.py +0 -0
  63. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/end_to_end/test_custom_registrations.py +0 -0
  64. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/grammar.py +0 -0
  65. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/packed/__init__.py +0 -0
  66. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/packed/test_encode_packed.py +0 -0
  67. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/packed/test_is_encodable_packed.py +0 -0
  68. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/registry/__init__.py +0 -0
  69. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/registry/test_abi_registry.py +0 -0
  70. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/registry/test_predicate_mapping.py +0 -0
  71. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/registry/test_predicates.py +0 -0
  72. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/test_import_and_version.py +0 -0
  73. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/test_tools.py +0 -0
  74. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/utils/__init__.py +0 -0
  75. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/utils/test_abbr.py +0 -0
  76. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/utils/test_ceil32.py +0 -0
  77. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/utils/test_scale_places.py +0 -0
  78. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/utils/test_validation_utils.py +0 -0
  79. {faster_eth_abi-5.2.9 → faster_eth_abi-5.2.11}/tests/core/utils/test_zpad.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: faster_eth_abi
3
- Version: 5.2.9
3
+ Version: 5.2.11
4
4
  Summary: A faster fork of eth_abi: Python utilities for working with Ethereum ABI definitions, especially encoding and decoding. Implemented in C.
5
5
  Home-page: https://github.com/BobTheBuidler/faster-eth-abi
6
6
  Author: The Ethereum Foundation
@@ -39,8 +39,6 @@ def encode_c(
39
39
  :returns: The head-tail encoded binary representation of the python
40
40
  values in ``args`` as values of the ABI types in ``types``.
41
41
  """
42
- # validate encode types and args
43
- validate_list_like_param(types, "types")
44
42
  validate_list_like_param(args, "args")
45
43
 
46
44
  encoder = self._registry.get_tuple_encoder(*types)
@@ -71,8 +69,6 @@ def decode_c(
71
69
  :returns: A tuple of equivalent python values for the ABI values
72
70
  represented in ``data``.
73
71
  """
74
- # validate decode types and data
75
- validate_list_like_param(types, "types")
76
72
  validate_bytes_param(data, "data")
77
73
 
78
74
  decoder = self._registry.get_tuple_decoder(*types, strict=strict)
@@ -10,6 +10,7 @@ from faster_eth_utils import (
10
10
 
11
11
  from faster_eth_abi.exceptions import (
12
12
  InsufficientDataBytes,
13
+ NonEmptyPaddingBytes,
13
14
  )
14
15
  from faster_eth_abi.io import (
15
16
  BytesIO,
@@ -26,6 +27,7 @@ if TYPE_CHECKING:
26
27
  )
27
28
 
28
29
 
30
+ # Helpers
29
31
  def decode_uint_256(stream: ContextFramesBytesIO) -> int:
30
32
  """
31
33
  This function is a faster version of decode_uint_256 in decoding.py.
@@ -39,6 +41,10 @@ def decode_uint_256(stream: ContextFramesBytesIO) -> int:
39
41
  raise InsufficientDataBytes(f"Tried to read 32 bytes, only got {len(data)} bytes.")
40
42
 
41
43
 
44
+ def get_value_byte_size(decoder: "FixedByteSizeDecoder") -> int:
45
+ return decoder.value_bit_size // 8
46
+
47
+
42
48
  # HeadTailDecoder
43
49
  def decode_head_tail(self: "HeadTailDecoder", stream: ContextFramesBytesIO) -> Any:
44
50
  # Decode the offset and move the stream cursor forward 32 bytes
@@ -107,3 +113,43 @@ def read_fixed_byte_size_data_from_stream(
107
113
  raise InsufficientDataBytes(
108
114
  f"Tried to read {data_byte_size} bytes, only got {len(data)} bytes."
109
115
  )
116
+
117
+
118
+ def split_data_and_padding_fixed_byte_size(
119
+ self: "FixedByteSizeDecoder",
120
+ raw_data: bytes,
121
+ ) -> Tuple[bytes, bytes]:
122
+ value_byte_size = get_value_byte_size(self)
123
+ padding_size = self.data_byte_size - value_byte_size
124
+
125
+ if self.is_big_endian:
126
+ if padding_size == 0:
127
+ return raw_data, b""
128
+ padding_bytes = raw_data[:padding_size]
129
+ data = raw_data[padding_size:]
130
+ else:
131
+ data = raw_data[:value_byte_size]
132
+ padding_bytes = raw_data[value_byte_size:]
133
+
134
+ return data, padding_bytes
135
+
136
+
137
+ def validate_padding_bytes_fixed_byte_size(
138
+ self: "FixedByteSizeDecoder",
139
+ value: Any,
140
+ padding_bytes: bytes,
141
+ ) -> None:
142
+ value_byte_size = get_value_byte_size(self)
143
+ padding_size = self.data_byte_size - value_byte_size
144
+
145
+ if padding_bytes != b"\x00" * padding_size:
146
+ raise NonEmptyPaddingBytes(f"Padding bytes were not empty: {padding_bytes!r}")
147
+
148
+
149
+ # BooleanDecoder
150
+ def decoder_fn_boolean(data: bytes) -> bool:
151
+ if data == b"\x00":
152
+ return False
153
+ elif data == b"\x01":
154
+ return True
155
+ raise NonEmptyPaddingBytes(f"Boolean must be either 0x0 or 0x1. Got: {data!r}")
@@ -1,6 +1,3 @@
1
- from itertools import (
2
- accumulate,
3
- )
4
1
  from typing import (
5
2
  TYPE_CHECKING,
6
3
  Any,
@@ -35,7 +32,12 @@ def encode_tuple(
35
32
  tail_chunks.append(b"")
36
33
 
37
34
  head_length = sum(32 if item is None else len(item) for item in raw_head_chunks)
38
- tail_offsets = (0, *accumulate(len(item) for item in tail_chunks[:-1]))
35
+ tail_offsets = [0]
36
+ total_offset = 0
37
+ for item in tail_chunks[:-1]:
38
+ total_offset += len(item)
39
+ tail_offsets.append(total_offset)
40
+
39
41
  head_chunks = tuple(
40
42
  encode_uint_256(head_length + offset) if chunk is None else chunk
41
43
  for chunk, offset in zip(raw_head_chunks, tail_offsets)
@@ -77,7 +79,12 @@ def encode_elements(item_encoder: "BaseEncoder", value: Sequence[Any]) -> bytes:
77
79
  return b"".join(tail_chunks)
78
80
 
79
81
  head_length = 32 * len(value)
80
- tail_offsets = (0, *accumulate(len(item) for item in tail_chunks[:-1]))
82
+ tail_offsets = [0]
83
+ total_offset = 0
84
+ for item in tail_chunks[:-1]:
85
+ total_offset += len(item)
86
+ tail_offsets.append(total_offset)
87
+
81
88
  head_chunks = tuple(
82
89
  encode_uint_256(head_length + offset) for offset in tail_offsets
83
90
  )
@@ -1,22 +1,22 @@
1
- import functools
2
1
  import re
3
2
  from typing import (
4
3
  Any,
5
4
  Final,
5
+ NewType,
6
6
  NoReturn,
7
7
  Optional,
8
8
  Sequence,
9
9
  Tuple,
10
10
  TypeVar,
11
+ Union,
11
12
  final,
12
13
  )
13
14
 
14
- from eth_typing import (
15
+ from eth_typing.abi import (
15
16
  TypeStr,
16
17
  )
17
- import parsimonious
18
- from parsimonious import (
19
- expressions,
18
+ from mypy_extensions import (
19
+ mypyc_attr,
20
20
  )
21
21
  from parsimonious.nodes import (
22
22
  Node,
@@ -27,136 +27,29 @@ from typing_extensions import (
27
27
 
28
28
  from faster_eth_abi.exceptions import (
29
29
  ABITypeError,
30
- ParseError,
31
30
  )
32
31
 
33
- grammar: Final = parsimonious.Grammar(
34
- r"""
35
- type = tuple_type / basic_type
36
32
 
37
- tuple_type = components arrlist?
38
- components = non_zero_tuple
39
-
40
- non_zero_tuple = "(" type next_type* ")"
41
- next_type = "," type
42
-
43
- basic_type = base sub? arrlist?
44
-
45
- base = alphas
46
-
47
- sub = two_size / digits
48
- two_size = (digits "x" digits)
49
-
50
- arrlist = (const_arr / dynam_arr)+
51
- const_arr = "[" digits "]"
52
- dynam_arr = "[]"
33
+ TYPE_ALIASES: Final = {
34
+ "int": "int256",
35
+ "uint": "uint256",
36
+ "fixed": "fixed128x18",
37
+ "ufixed": "ufixed128x18",
38
+ "function": "bytes24",
39
+ "byte": "bytes1",
40
+ }
53
41
 
54
- alphas = ~"[A-Za-z]+"
55
- digits = ~"[1-9][0-9]*"
56
- """
42
+ TYPE_ALIAS_RE: Final = re.compile(
43
+ rf"\b({'|'.join(map(re.escape, TYPE_ALIASES.keys()))})\b"
57
44
  )
58
45
 
59
46
 
60
- @final
61
- class NodeVisitor(parsimonious.NodeVisitor): # type: ignore [misc]
62
- """
63
- Parsimonious node visitor which performs both parsing of type strings and
64
- post-processing of parse trees. Parsing operations are cached.
65
- """
66
-
67
- def __init__(self):
68
- self.parse = functools.lru_cache(maxsize=None)(self._parse_uncached)
69
-
70
- grammar = grammar
71
-
72
- def visit_non_zero_tuple(self, node, visited_children):
73
- # Ignore left and right parens
74
- _, first, rest, _ = visited_children
75
-
76
- return (first,) + rest
77
-
78
- def visit_tuple_type(self, node, visited_children):
79
- components, arrlist = visited_children
80
-
81
- return TupleType(components, arrlist, node=node)
82
-
83
- def visit_next_type(self, node, visited_children):
84
- # Ignore comma
85
- _, abi_type = visited_children
86
-
87
- return abi_type
88
-
89
- def visit_basic_type(self, node, visited_children):
90
- base, sub, arrlist = visited_children
91
-
92
- return BasicType(base, sub, arrlist, node=node)
93
-
94
- def visit_two_size(self, node, visited_children):
95
- # Ignore "x"
96
- first, _, second = visited_children
97
-
98
- return first, second
99
-
100
- def visit_const_arr(self, node, visited_children):
101
- # Ignore left and right brackets
102
- _, int_value, _ = visited_children
103
-
104
- return (int_value,)
105
-
106
- def visit_dynam_arr(self, node, visited_children):
107
- return ()
108
-
109
- def visit_alphas(self, node, visited_children):
110
- return node.text
111
-
112
- def visit_digits(self, node, visited_children):
113
- return int(node.text)
114
-
115
- def generic_visit(self, node, visited_children):
116
- expr = node.expr
117
- if isinstance(expr, expressions.OneOf):
118
- # Unwrap value chosen from alternatives
119
- return visited_children[0]
120
-
121
- if isinstance(expr, expressions.Quantifier) and expr.min == 0 and expr.max == 1:
122
- # Unwrap optional value or return `None`
123
- if len(visited_children) != 0:
124
- return visited_children[0]
125
-
126
- return None
127
-
128
- return tuple(visited_children)
129
-
130
- def _parse_uncached(self, type_str, **kwargs):
131
- """
132
- Parses a type string into an appropriate instance of
133
- :class:`~faster_eth_abi.grammar.ABIType`. If a type string cannot be parsed,
134
- throws :class:`~faster_eth_abi.exceptions.ParseError`.
135
-
136
- :param type_str: The type string to be parsed.
137
- :returns: An instance of :class:`~faster_eth_abi.grammar.ABIType` containing
138
- information about the parsed type string.
139
- """
140
- if not isinstance(type_str, str):
141
- raise TypeError(f"Can only parse string values: got {type(type_str)}")
142
-
143
- try:
144
- return super().parse(type_str, **kwargs)
145
- except parsimonious.ParseError as e:
146
- # This is a good place to add some better messaging around the type string.
147
- # If this logic grows any bigger, we should abstract it to its own function.
148
- if "()" in type_str:
149
- # validate against zero-sized tuple types
150
- raise ValueError(
151
- 'Zero-sized tuple types "()" are not supported.'
152
- ) from None
153
-
154
- raise ParseError(e.text, e.pos, e.expr) from e
155
-
156
-
157
- visitor: Final = NodeVisitor()
47
+ IntSubtype = NewType("IntSubtype", int)
48
+ FixedSubtype = NewType("FixedSubtype", Tuple[int, int])
49
+ Subtype = Union[IntSubtype, FixedSubtype]
158
50
 
159
51
 
52
+ @mypyc_attr(allow_interpreted_subclasses=True)
160
53
  class ABIType:
161
54
  """
162
55
  Base class for results of type string parsing operations.
@@ -165,7 +58,7 @@ class ABIType:
165
58
  __slots__ = ("arrlist", "node")
166
59
 
167
60
  def __init__(
168
- self, arrlist: Optional[Sequence] = None, node: Optional[Node] = None
61
+ self, arrlist: Optional[Sequence[str]] = None, node: Optional[Node] = None
169
62
  ) -> None:
170
63
  self.arrlist: Final = arrlist
171
64
  """
@@ -211,6 +104,7 @@ class ABIType:
211
104
  """
212
105
  raise NotImplementedError("Must implement `validate`")
213
106
 
107
+ @final
214
108
  def invalidate(self, error_msg: str) -> NoReturn:
215
109
  # Invalidates an ABI type with the given error message. Expects that a
216
110
  # parsimonious node was provided from the original parsing operation
@@ -222,6 +116,7 @@ class ABIType:
222
116
  f"in '{node.full_text}': {error_msg}"
223
117
  )
224
118
 
119
+ @final
225
120
  @property
226
121
  def is_array(self) -> bool:
227
122
  """
@@ -238,6 +133,7 @@ class ABIType:
238
133
  """
239
134
  raise NotImplementedError("Must implement `is_dynamic`")
240
135
 
136
+ @final
241
137
  @property
242
138
  def _has_dynamic_arrlist(self) -> bool:
243
139
  return self.is_array and any(len(dim) == 0 for dim in self.arrlist)
@@ -246,7 +142,7 @@ class ABIType:
246
142
  TComp = TypeVar("TComp", bound=ABIType)
247
143
 
248
144
 
249
- @final
145
+ @mypyc_attr(allow_interpreted_subclasses=True)
250
146
  class TupleType(ABIType):
251
147
  """
252
148
  Represents the result of parsing a tuple type string e.g. "(int,bool)".
@@ -257,7 +153,7 @@ class TupleType(ABIType):
257
153
  def __init__(
258
154
  self,
259
155
  components: Tuple[TComp, ...],
260
- arrlist: Optional[Sequence] = None,
156
+ arrlist: Optional[Sequence[str]] = None,
261
157
  *,
262
158
  node: Optional[Node] = None,
263
159
  ) -> None:
@@ -273,7 +169,7 @@ class TupleType(ABIType):
273
169
  arrlist = self.arrlist
274
170
 
275
171
  if isinstance(arrlist, tuple):
276
- arrlist = "".join(repr(list(a)) for a in arrlist)
172
+ arrlist = "".join(map(repr, map(list, arrlist)))
277
173
  else:
278
174
  arrlist = ""
279
175
 
@@ -286,11 +182,12 @@ class TupleType(ABIType):
286
182
  f"Cannot determine item type for non-array type '{self.to_type_str()}'"
287
183
  )
288
184
 
289
- return type(self)(
290
- self.components,
291
- self.arrlist[:-1] or None, # type: ignore [index]
292
- node=self.node,
293
- )
185
+ arrlist = self.arrlist[:-1] or None # type: ignore [index]
186
+ cls = type(self)
187
+ if cls is TupleType:
188
+ return TupleType(self.components, arrlist, node=self.node) # type: ignore [return-value]
189
+ else:
190
+ return cls(self.components, arrlist, node=self.node)
294
191
 
295
192
  def validate(self) -> None:
296
193
  for c in self.components:
@@ -304,7 +201,7 @@ class TupleType(ABIType):
304
201
  return any(c.is_dynamic for c in self.components)
305
202
 
306
203
 
307
- @final
204
+ @mypyc_attr(allow_interpreted_subclasses=True)
308
205
  class BasicType(ABIType):
309
206
  """
310
207
  Represents the result of parsing a basic type string e.g. "uint", "address",
@@ -316,7 +213,7 @@ class BasicType(ABIType):
316
213
  def __init__(
317
214
  self,
318
215
  base: str,
319
- sub: Any = None,
216
+ sub: Optional[Subtype] = None,
320
217
  arrlist: Optional[Sequence] = None,
321
218
  *,
322
219
  node: Optional[Node] = None,
@@ -339,12 +236,12 @@ class BasicType(ABIType):
339
236
  if isinstance(sub, int):
340
237
  substr = str(sub)
341
238
  elif isinstance(sub, tuple):
342
- substr = "x".join(str(s) for s in sub)
239
+ substr = "x".join(map(str, sub))
343
240
  else:
344
241
  substr = ""
345
242
 
346
243
  if isinstance(arrlist, tuple):
347
- return self.base + substr + "".join(repr(list(a)) for a in arrlist)
244
+ return self.base + substr + "".join(map(repr, map(list, arrlist)))
348
245
  else:
349
246
  return self.base + substr
350
247
 
@@ -355,22 +252,23 @@ class BasicType(ABIType):
355
252
  f"Cannot determine item type for non-array type '{self.to_type_str()}'"
356
253
  )
357
254
 
358
- return type(self)(
359
- self.base,
360
- self.sub,
361
- self.arrlist[:-1] or None, # type: ignore [index]
362
- node=self.node,
363
- )
255
+ cls = type(self)
256
+ arrlist = self.arrlist[:-1] or None # type: ignore [index]
257
+ if cls is BasicType:
258
+ return BasicType(self.base, self.sub, arrlist, node=self.node) # type: ignore [return-value]
259
+ else:
260
+ return cls(self.base, self.sub, arrlist, node=self.node)
364
261
 
365
262
  @property
366
263
  def is_dynamic(self) -> bool:
367
264
  if self._has_dynamic_arrlist:
368
265
  return True
369
266
 
370
- if self.base == "string":
267
+ base = self.base
268
+ if base == "string":
371
269
  return True
372
270
 
373
- if self.base == "bytes" and self.sub is None:
271
+ if base == "bytes" and self.sub is None:
374
272
  return True
375
273
 
376
274
  return False
@@ -436,20 +334,6 @@ class BasicType(ABIType):
436
334
  self.invalidate("address cannot have suffix")
437
335
 
438
336
 
439
- TYPE_ALIASES: Final = {
440
- "int": "int256",
441
- "uint": "uint256",
442
- "fixed": "fixed128x18",
443
- "ufixed": "ufixed128x18",
444
- "function": "bytes24",
445
- "byte": "bytes1",
446
- }
447
-
448
- TYPE_ALIAS_RE: Final = re.compile(
449
- rf"\b({'|'.join(re.escape(a) for a in TYPE_ALIASES.keys())})\b"
450
- )
451
-
452
-
453
337
  def normalize(type_str: TypeStr) -> TypeStr:
454
338
  """
455
339
  Normalizes a type string into its canonical version e.g. the type string
@@ -463,6 +347,3 @@ def normalize(type_str: TypeStr) -> TypeStr:
463
347
 
464
348
  def __normalize(match: "re.Match[str]") -> str:
465
349
  return TYPE_ALIASES[match.group(0)]
466
-
467
-
468
- parse: Final = visitor.parse
@@ -18,6 +18,7 @@ from faster_eth_abi.decoding import (
18
18
  )
19
19
  from faster_eth_abi.exceptions import (
20
20
  EncodingError,
21
+ MultipleEntriesFound,
21
22
  )
22
23
  from faster_eth_abi.registry import (
23
24
  ABIRegistry,
@@ -74,20 +75,18 @@ class ABIEncoder(BaseABICoder):
74
75
  :returns: ``True`` if ``arg`` is encodable as a value of the ABI type
75
76
  ``typ``. Otherwise, ``False``.
76
77
  """
77
- if not self.is_encodable_type(typ):
78
+ try:
79
+ encoder = self._registry.get_encoder(typ)
80
+ except MultipleEntriesFound:
81
+ raise
82
+ except:
78
83
  return False
79
84
 
80
- encoder = self._registry.get_encoder(typ)
81
-
85
+ validate = getattr(encoder, "validate_value", encoder)
82
86
  try:
83
- encoder.validate_value(arg)
87
+ validate(arg)
84
88
  except EncodingError:
85
89
  return False
86
- except AttributeError:
87
- try:
88
- encoder(arg)
89
- except EncodingError:
90
- return False
91
90
 
92
91
  return True
93
92
 
@@ -19,7 +19,11 @@ from faster_eth_abi._decoding import (
19
19
  decode_head_tail,
20
20
  decode_sized_array,
21
21
  decode_tuple,
22
+ decoder_fn_boolean,
23
+ get_value_byte_size,
22
24
  read_fixed_byte_size_data_from_stream,
25
+ split_data_and_padding_fixed_byte_size,
26
+ validate_padding_bytes_fixed_byte_size,
23
27
  )
24
28
  from faster_eth_abi.base import (
25
29
  BaseCoder,
@@ -303,29 +307,14 @@ class FixedByteSizeDecoder(SingleDecoder):
303
307
  return read_fixed_byte_size_data_from_stream(self, stream)
304
308
 
305
309
  def split_data_and_padding(self, raw_data: bytes) -> Tuple[bytes, bytes]:
306
- value_byte_size = self._get_value_byte_size()
307
- padding_size = self.data_byte_size - value_byte_size
308
-
309
- if self.is_big_endian:
310
- padding_bytes = raw_data[:padding_size]
311
- data = raw_data[padding_size:]
312
- else:
313
- data = raw_data[:value_byte_size]
314
- padding_bytes = raw_data[value_byte_size:]
315
-
316
- return data, padding_bytes
310
+ return split_data_and_padding_fixed_byte_size(self, raw_data)
317
311
 
318
312
  def validate_padding_bytes(self, value: Any, padding_bytes: bytes) -> None:
319
- value_byte_size = self._get_value_byte_size()
320
- padding_size = self.data_byte_size - value_byte_size
321
-
322
- if padding_bytes != b"\x00" * padding_size:
323
- raise NonEmptyPaddingBytes(
324
- f"Padding bytes were not empty: {padding_bytes!r}"
325
- )
313
+ validate_padding_bytes_fixed_byte_size(self, value, padding_bytes)
326
314
 
327
315
  def _get_value_byte_size(self) -> int:
328
- return self.value_bit_size // 8
316
+ # This is unused, but it is kept in to preserve the eth-abi api
317
+ return get_value_byte_size(self)
329
318
 
330
319
 
331
320
  class Fixed32ByteSizeDecoder(FixedByteSizeDecoder):
@@ -336,16 +325,7 @@ class BooleanDecoder(Fixed32ByteSizeDecoder):
336
325
  value_bit_size = 8
337
326
  is_big_endian = True
338
327
 
339
- @staticmethod
340
- def decoder_fn(data: bytes) -> bool:
341
- if data == b"\x00":
342
- return False
343
- elif data == b"\x01":
344
- return True
345
- else:
346
- raise NonEmptyPaddingBytes(
347
- f"Boolean must be either 0x0 or 0x1. Got: {data!r}"
348
- )
328
+ decoder_fn = staticmethod(decoder_fn_boolean)
349
329
 
350
330
  @parse_type_str("bool")
351
331
  def from_type_str(cls, abi_type, registry):
@@ -392,7 +372,7 @@ class SignedIntegerDecoder(Fixed32ByteSizeDecoder):
392
372
  return value
393
373
 
394
374
  def validate_padding_bytes(self, value: Any, padding_bytes: bytes) -> None:
395
- value_byte_size = self._get_value_byte_size()
375
+ value_byte_size = get_value_byte_size(self)
396
376
  padding_size = self.data_byte_size - value_byte_size
397
377
 
398
378
  if value >= 0:
@@ -471,7 +451,7 @@ class SignedFixedDecoder(BaseFixedDecoder):
471
451
  return decimal_value
472
452
 
473
453
  def validate_padding_bytes(self, value: Any, padding_bytes: bytes) -> None:
474
- value_byte_size = self._get_value_byte_size()
454
+ value_byte_size = get_value_byte_size(self)
475
455
  padding_size = self.data_byte_size - value_byte_size
476
456
 
477
457
  if value >= 0:
@@ -12,11 +12,13 @@ from eth_typing import (
12
12
  TypeStr,
13
13
  )
14
14
 
15
- from .grammar import (
15
+ from ._grammar import (
16
16
  ABIType,
17
17
  BasicType,
18
18
  TupleType,
19
19
  normalize,
20
+ )
21
+ from .grammar import (
20
22
  parse,
21
23
  )
22
24