Unreachable code¶
ID: py/unreachable-statementKind: problemSecurity severity: Severity: warningPrecision: very-highTags: - quality - maintainability - useless-code - external/cwe/cwe-561Query 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 toremainder is never reached because there is areturn statement on the previous line.
importmathdefmy_div(x,y):returnmath.floor(x/y)remainder=x-math.floor(x/y)*y
References¶
Wikipedia:Unreachable Code.
Common Weakness Enumeration:CWE-561.