Skip to content

Commit 96cd466

Browse files
committed
Tighten input of normalize_int
1 parent 482f13a commit 96cd466

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

eth/tools/_utils/normalization.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from eth.typing import (
5858
AccountState,
5959
GeneralState,
60+
IntConvertible,
6061
Normalizer,
6162
TransactionDict,
6263
TransactionNormalizer,
@@ -67,16 +68,17 @@
6768
# Primitives
6869
#
6970
@functools.lru_cache(maxsize=1024)
70-
def normalize_int(value: Any) -> int:
71+
def normalize_int(value: IntConvertible) -> int:
7172
"""
7273
Robust to integer conversion, handling hex values, string representations,
7374
and special cases like `0x`.
7475
"""
7576
if is_integer(value):
76-
return value
77+
return cast(int, value)
7778
elif is_bytes(value):
7879
return big_endian_to_int(value)
7980
elif is_hex(value) and is_0x_prefixed(value):
81+
value = cast(str, value)
8082
if len(value) == 2:
8183
return 0
8284
else:

eth/tools/fixtures/helpers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from typing import (
66
Any,
7-
cast,
87
Dict,
98
Iterable,
109
Tuple,

eth/typing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from eth_typing import (
1313
Address,
14+
HexStr,
1415
)
1516
from mypy_extensions import (
1617
TypedDict,
@@ -49,3 +50,5 @@
4950
TransactionNormalizer = Callable[[TransactionDict], TransactionDict]
5051

5152
VRS = NewType("VRS", Tuple[int, int, int])
53+
54+
IntConvertible = Union[int, bytes, HexStr, str]

0 commit comments

Comments
 (0)