Closed jingw closed 4 years ago
I see your point and we actually were on the fence about this when we added the unreachable code feature. I think it's best to leave things as they are, because that keeps the code simple and is easiest to document and understand. In cases like these, I'd recommend to use a Boolean flag and I added a corresponding note to the README:
Unreachable code
If Vulture complains about code like if False:
, you can use a Boolean flag debug = False
and write if debug:
instead. This makes the code more readable and silences Vulture.
How would you feel about loosening
_handle_conditional_node
to ignore cases where the unreachable branch is obviously intentional? When running vulture on my giant codebase, I found that most of the unreachable code flagged by vulture was of the formif False
orif False and other_conditions
, though it did also flag buggy code of the formif x == 1 or 2
.Concretely, I propose ignoring the following patterns at the top level in _handle_conditional_node
Less obvious cases where the True/False is somewhere in the middle would continue to be reported, as done currently.
I can throw up a PR if you like the idea.