Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should report on unreachable code after try-return-except-raise #270

Open
kretes opened this issue Jan 3, 2022 · 3 comments
Open

Should report on unreachable code after try-return-except-raise #270

kretes opened this issue Jan 3, 2022 · 3 comments

Comments

@kretes
Copy link

kretes commented Jan 3, 2022

For a following file:

def test() -> int:
    try:
        return 2
    except Exception as e:
        raise e
    return 1
test()

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

@jendrikseipp
Copy link
Owner

jendrikseipp commented Jan 3, 2022

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 :-)

@adamchainz
Copy link

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.

@kykyi
Copy link

kykyi commented Jul 3, 2023

I disagree, mostly because this is dead-code and users of vulture are expecting it to find dead-code 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants