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

Warn about unreachable code #7568

Closed
bje- opened this issue Oct 4, 2022 · 4 comments
Closed

Warn about unreachable code #7568

bje- opened this issue Oct 4, 2022 · 4 comments
Labels
Invalid Not a bug, already exists or already fixed

Comments

@bje-
Copy link

bje- commented Oct 4, 2022

Current problem

It would be good if Pylint could warn about unreachable code like the raise below:

"""Example"""

for t in ['a', 'b', 'c', 'd']:
    if t in ['a', 'b', 'c', 'd']:
        pass
    else:
        raise ValueError

Desired solution

I would like a warning that the else is unreachable.

Additional context

No response

@bje- bje- added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Oct 4, 2022
@DanielNoord
Copy link
Collaborator

This is likely never possible for pylint as there are too many moving parts.
I would suggest using something like coverage to track unused branches.

@Pierre-Sassoulas
Copy link
Member

Blocked by #4795

@bje-
Copy link
Author

bje- commented Oct 4, 2022

Thanks -- I suspected as much. The issue is that I have an else raise ValueError branch to catch myself if I add a new list entry but no if case to match it. I don't really want to remove the else, so have no option but to mark it as 'no cover'.

@DanielNoord
Copy link
Collaborator

Thanks -- I suspected as much. The issue is that I have an else raise ValueError branch to catch myself if I add a new list entry but no if case to match it. I don't really want to remove the else, so have no option but to mark it as 'no cover'.

In personal projects I use raise AssertionError() and have that pattern be auto no cover in my coverage settings. That works quite well for such patterns.

@Pierre-Sassoulas Pierre-Sassoulas added Invalid Not a bug, already exists or already fixed and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Invalid Not a bug, already exists or already fixed
Projects
None yet
Development

No branches or pull requests

3 participants