Unreachable code¶
ID: py/unreachable-statement
Kind: problem
Security severity:
Severity: warning
Precision: very-high
Tags:
- maintainability
- useless-code
- external/cwe/cwe-561
Query suites:
- python-security-and-quality.qls
Click to see the query in the CodeQL repository
Unreachable code makes the code more difficult to understand and may slow down loading of modules.
Recommendation¶
Deleting the unreachable code will make the code clearer and preserve the meaning of the code. However, it is possible that the original intention was that the code should execute and that it is unreachable signifies some other error.
Example¶
In this example the assignment to remainder
is never reached because there is a return
statement on the previous line.
import math
def my_div(x, y):
return math.floor(x / y)
remainder = x - math.floor(x / y) * y
References¶
Wikipedia: Unreachable Code.
Common Weakness Enumeration: CWE-561.