Skip to content

Commit

Permalink
feat: optimize uint.__new__
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Dec 16, 2024
1 parent 25e131d commit ce66bc9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion evmspec/data/uints.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from evmspec.data._main import uint


_new = int.__new__

class _UintData(uint):
"""
Base class for unsigned integer types with specific byte sizes.
Expand Down Expand Up @@ -54,7 +56,7 @@ def __new__(cls, v: HexBytes):
>>> uint256(HexBytes('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'))
uint256(115792089237316195423570985008687907853269984665640564039457584007913129639935)
"""
new = super().__new__(cls, v.hex() if v else "0x0", 16)
new = _new(cls, v.hex() if v else "0x0", 16)
if new < cls.min_value:
raise ValueError(
f"{v!r} ({new}) is smaller than {cls.__name__} min value {cls.min_value}"
Expand Down

0 comments on commit ce66bc9

Please sign in to comment.