Unreachable code is never executed, so it has no effect on the behaviour of the program. If it is not executed because it no longer serves a
purpose, then it adds unnecessary complexity. Otherwise, it indicates that there is a logical error in the condition.
What is the potential impact?
Unreachable code affects maintainability. It is harder for programmers to read, understand and modify the code when some parts are unreachable. If
the code should be reachable instead, then the program may not always behave as intended.
Exceptions
This rule will not raise an issue when
- The condition to reach the dead code is a boolean literal.
- The unreachable code is a simple statement, such as
pass
.