Skip to content

Commit

Permalink
feat: flip the evaluation of signed/unsigned range to do true conditi…
Browse files Browse the repository at this point in the history
…on first
  • Loading branch information
bitwise-constructs committed Dec 19, 2024
1 parent 4fe3cfd commit ff72ed7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions eth_pydantic_types/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ def validate_size(value: "__SIZED_T", size: int, coerce: Optional[Callable] = No


def validate_in_range(value: int, size: int, signed: bool = True) -> int:
if not signed:
if value >= 0 and value < 2**size:
if signed:
if value >= -(2**size) / 2 and value < (2**size) / 2:
return value

else:
if value >= -(2**size) / 2 and value < (2**size) / 2:
if value >= 0 and value < 2**size:
return value

raise SizeError(size, value)
Expand Down

0 comments on commit ff72ed7

Please sign in to comment.