Skip to content

Commit

Permalink
feat: optimize uint.__new__ (#34)
Browse files Browse the repository at this point in the history
* feat: optimize `uint.__new__`

* chore: `black .`

* Update uints.py

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
BobTheBuidler and github-actions[bot] authored Dec 16, 2024
1 parent 5e5ab9e commit ebbbef1
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 @@ -54,7 +54,7 @@ def __new__(cls, v: HexBytes):
>>> uint256(HexBytes('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'))
uint256(115792089237316195423570985008687907853269984665640564039457584007913129639935)
"""
new = super().__new__(cls, v.hex() if v else "0x0", 16)
new = __int_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 Expand Up @@ -140,3 +140,5 @@ class uint256(_UintData):
setattr(sys.modules[__name__], cls_name, new_cls)

__all__ = [f"uint{bytes*8}" for bytes in range(1, 32)]

__int_new__ = int.__new__

0 comments on commit ebbbef1

Please sign in to comment.