Lucas Robinson
Lucas Robinson

Reputation: 11

This inspection detects code which can not be normally reached

I have no idea why this is happening. When i try to return false it says all if statements below have the error

This inspection detects code which can not be normally reached

I am using pyCharm and I've heard this is a problem w/ pycharm but i cant corroborate others' problem with my own.

code = raw_input("Enter your code: ").lower()
begmeter = int(raw_input("Enter your beginning meter: "))
endmeter = int(raw_input("Enter your ending meter: "))

def errors():

if type(begmeter and endmeter < 0):
    print("Please use an integer above 0 for beginning and end meter")
    return False
else:
    return True

if type(begmeter and endmeter != int):
    print("Please use integers for beginning and end meter")
    return False
else:
    return True


if len(begmeter) > 9:
    print("Beginning meter and end meter can have a max digit amount of 9 digits")
    return False
else:
    return True

if len(endmeter) > 9:
    print("Beginning meter and end meter can have a max digit amount of 9 digits")
    return False
else:
    return True

Upvotes: 0

Views: 1345

Answers (1)

dtanabe
dtanabe

Reputation: 1661

The if statements at the top look a little fishy to me:

if type(begmeter and endmeter < 0):

That will always be truthy, because you're taking the type of a value.

So your IDE is telling you that the same branch will always be picked, and the rest of your code is unreachable.

And as other commenters mentioned as well, your first if statement is complete, so even if the if statement wasn't fishy, you'd never get past it because you're returning either True or False in the first four lines of your function.

Took a stab at rewriting your errors() function closer to what I think your intent is. Note that raw_input always returns a string, and it's on you to try to make sense of it as an int:

def errors():
    try:
        begmeter_i = int(begmeter)
        endmeter_i = int(begmeter)
    except ValueError:
        print("Please use integers for beginning and end meter")
        return False

    if begmeter_i <= 0 or endmeter_i <= 0:
        print("Please use an integer above 0 for beginning and end meter")
        return False

    if len(begmeter) > 9:
        print("Beginning meter and end meter can have a max digit amount of 9 digits")
        return False

    if len(endmeter) > 9:
        print("Beginning meter and end meter can have a max digit amount of 9 digits")
        return False

    # we got all the way to the end!
    return True

Upvotes: 2

Related Questions