Open kretes opened 2 years ago
Thanks for the report! Put a little more generally, Vulture should detect that code is unreachable if it occurs after an if-else block or a try-except block where all cases exit the function (with return
or raise
).
Here is another test case that Vulture currently misses:
def test2(a) -> int:
if a:
return 1
else:
return 2
return 3
test2(5)
I'm happy to review a PR for this :-)
Mypy has good unreachable code detection, and it can work for such cases even if you don’t use type hints. https://adamj.eu/tech/2021/05/19/python-type-hints-mypy-unreachable-code-detection/
I am not sure it’s worth duplicating this kind of functionality in vulture.
I disagree, mostly because this is dead-code and users of vulture are expecting it to find dead-code 🤷
For a following file:
vulture dead_return.py
doesn't report anything, while it should report code on line 6, as this one is unreachable.vulture 2.3, python 3.9