Skip to content

Commit

Permalink
refactor: remove assert statement from non-test files
Browse files Browse the repository at this point in the history
Usage of `assert` statement in application logic is discouraged. `assert` is removed with compiling to optimized byte code. Consider raising an exception instead. Ideally, `assert` statement should be used only in tests.
  • Loading branch information
deepsource-autofix[bot] authored Sep 10, 2024
1 parent 492d956 commit 9a97e45
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions staking_deposit/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ def validate_int_range(num: Any, low: int, high: int) -> int:
"""
try:
num_int = int(num) # Try cast to int
assert num_int == float(num) # Check num is not float
assert low <= num_int < high # Check num in range
if num_int != float(num):
raise AssertionError
if not low <= num_int < high:
raise AssertionError
return num_int
except (ValueError, AssertionError):
raise ValidationError(load_text(["err_not_positive_integer"]))
Expand Down Expand Up @@ -276,7 +278,8 @@ def validate_bls_withdrawal_credentials(bls_withdrawal_credentials: str) -> byte

try:
assert len(bls_withdrawal_credentials_bytes) == 32
assert bls_withdrawal_credentials_bytes[:1] == BLS_WITHDRAWAL_PREFIX
if bls_withdrawal_credentials_bytes[:1] != BLS_WITHDRAWAL_PREFIX:
raise AssertionError
except (ValueError, AssertionError):
raise ValidationError(load_text(["err_not_bls_form"]) + "\n")

Expand Down

0 comments on commit 9a97e45

Please sign in to comment.