Skip to main content
add assertion message
Source Link
mkrieger1
  • 1.7k
  • 1
  • 14
  • 26
if x % i == 0:
    if (x/i) in dp:
        return dp[x/i]
    return ishumble(x / i) #i don't believe this ever get's called

[...] because we are guaranteed that if x % i == 0, then (x/i) is in dp! So I believe that the return ishumble(x / i) line is actually never called.

If you believe that some condition is always fulfilled, but you don't want to or are not able to prove it, you could let Python verify it for you by using an assertion:

if x % i == 0:
    assert x/i in dp, "x/i is not in dp: {}/{}".format(x, i)
    return dp[x/i]

This way, you don't have dead code, but will still be notified when your assumptions should turn out wrong.

if x % i == 0:
    if (x/i) in dp:
        return dp[x/i]
    return ishumble(x / i) #i don't believe this ever get's called

[...] because we are guaranteed that if x % i == 0, then (x/i) is in dp! So I believe that the return ishumble(x / i) line is actually never called.

If you believe that some condition is always fulfilled, but you don't want to or are not able to prove it, you could let Python verify it for you by using an assertion:

if x % i == 0:
    assert x/i in dp
    return dp[x/i]

This way, you don't have dead code, but will still be notified when your assumptions should turn out wrong.

if x % i == 0:
    if (x/i) in dp:
        return dp[x/i]
    return ishumble(x / i) #i don't believe this ever get's called

[...] because we are guaranteed that if x % i == 0, then (x/i) is in dp! So I believe that the return ishumble(x / i) line is actually never called.

If you believe that some condition is always fulfilled, but you don't want to or are not able to prove it, you could let Python verify it for you by using an assertion:

if x % i == 0:
    assert x/i in dp, "x/i is not in dp: {}/{}".format(x, i)
    return dp[x/i]

This way, you don't have dead code, but will still be notified when your assumptions should turn out wrong.

Source Link
mkrieger1
  • 1.7k
  • 1
  • 14
  • 26

if x % i == 0:
    if (x/i) in dp:
        return dp[x/i]
    return ishumble(x / i) #i don't believe this ever get's called

[...] because we are guaranteed that if x % i == 0, then (x/i) is in dp! So I believe that the return ishumble(x / i) line is actually never called.

If you believe that some condition is always fulfilled, but you don't want to or are not able to prove it, you could let Python verify it for you by using an assertion:

if x % i == 0:
    assert x/i in dp
    return dp[x/i]

This way, you don't have dead code, but will still be notified when your assumptions should turn out wrong.