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

Detect unreachable code after sys.exit, quit, exit, and os._exit #7520

Merged
merged 21 commits into from
Nov 13, 2022

Conversation

clavedeluna
Copy link
Contributor

@clavedeluna clavedeluna commented Sep 23, 2022

Type of Changes

Type
✨ New feature

Description

Pylint can now detect unreachable code for any code that follows a sys.exit call

Refs #519

@coveralls
Copy link

coveralls commented Sep 23, 2022

Pull Request Test Coverage Report for Build 3457101611

  • 16 of 16 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 95.408%

Totals Coverage Status
Change from base Build 3456941332: 0.004%
Covered Lines: 17347
Relevant Lines: 18182

💛 - Coveralls

@clavedeluna clavedeluna marked this pull request as ready for review September 23, 2022 15:52
@github-actions

This comment has been minimized.

@mbyrnepr2
Copy link
Member

mbyrnepr2 commented Sep 23, 2022

Thanks for tackling this @clavedeluna!

I think the Django primer result shows that some control flow is needed since the message shouldn't emit in this case in the else block.

@Pierre-Sassoulas Pierre-Sassoulas added Control flow Requires control flow understanding False Negative 🦋 No message is emitted but something is wrong with the code labels Sep 23, 2022
@github-actions

This comment has been minimized.

@clavedeluna
Copy link
Contributor Author

I'm still trying to figure out how to use the primer results, it's confusing because the run hasn't finished but there's an output above in the PR

@Pierre-Sassoulas
Copy link
Member

it's confusing because the run hasn't finished but there's an output above in the PR

There's a new comment each time the primer is run, the new one should appear shortly.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's starting to look pretty good, thank you @clavedeluna :)

"""
if self._is_sys_exit(node):
self._check_unreachable(node)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The confidence need to be INFERENCE in this case, but it should still be HIGH when we don't need inference.

pylint/checkers/base/basic_checker.py Outdated Show resolved Hide resolved
@Pierre-Sassoulas
Copy link
Member

Rebased on upstream/main so the pipeline can run properly.

@github-actions
Copy link
Contributor

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit 6857803

@Pierre-Sassoulas Pierre-Sassoulas merged commit bed42ba into pylint-dev:main Nov 13, 2022
@Pierre-Sassoulas Pierre-Sassoulas changed the title Detect unreachable code after sys.exit call Detect unreachable code after sys.exit, quit, exit, and os._exit Nov 13, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.16.0 milestone Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Control flow Requires control flow understanding False Negative 🦋 No message is emitted but something is wrong with the code Needs decision 🔒 Needs a decision before implemention or rejection
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants