PY3.R1720
No else raise
Used in order to highlight an unnecessary block of code following an if containing a raise statement. As such, it will warn when it encounters an else following a chain of if s, all of them containing a raise statement.
Noncompliant Code:
Copy
def integer_sum(a: int, b: int) -> int:
if not (isinstance(a, int) and isinstance(b, int)):
raise ValueError('Function supports only integer parameters.')
else:
return a + b
Compliant Code:
Copy
def integer_sum(a: int, b: int) -> int:
if not (isinstance(a, int) and isinstance(b, int)):
raise ValueError('Function supports only integer parameters.')
return a + b