Repository navigation
Conversation
…sing scope The exemption for an imported ``exit`` only inspected the current scope and the module scope, so ``from sys import exit`` in an outer function was ignored when ``exit()`` was called from a nested function. It also only looked up ``exit``, so importing ``exit`` hid calls to the builtin ``quit``. Resolve the called name with a scope lookup and only emit when it resolves to the builtins module. Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
udsy19
force-pushed
the
fix/consider-using-sys-exit-enclosing-scope
branch
from
October 29, 2026 00:28
9680d9d to
fa2edcf
Compare
Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #11752 +/- ##
==========================================
- Coverage 94.53% 94.52% -0.01%
==========================================
Files 187 187
Lines 21174 21169 -5
Branches 4698 4698
==========================================
- Hits 20016 20011 -5
Misses 690 690
Partials 468 468
🚀 New features to boost your workflow:
|
Contributor
|
🤖 Effect of this PR on checked open source code: 🤖 Effect on astropy: Changed messages: Details
Removed messages: Details
Effect on django: New messages: Details
Effect on music21: New messages: Details
Removed messages: Details
This comment was generated for commit cd058cc |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Steps to reproduce
Current behavior
That
exitalready issys.exit. The same happens forquit = sys.exitor a localdef exit(...)in an enclosing function.Conversely,
from sys import exitin a function also silences a call to the real builtinquit()in that function (false negative).Cause
_check_quit_exit_callonly exempted anexitthat was anImport/ImportFrominnode.scope()ornode.root(), so it never looked at enclosing function scopes. It also always looked up"exit", whatever name was being called.Fix
Resolve the called name with
lookup()and emit only when it resolves to the builtins (utils.is_builtin_object), so any binding in an enclosing scope exempts it, for the name actually called._has_exit_in_scopehad no other callers and is removed.Note: any non-builtin binding now exempts the call, not only an import, e.g. a user-defined
def exit(): .... The message is about the site builtin, so that seems right to me, but happy to narrow it to imports/assignments fromsysif you prefer.Tests
New functional test
consider_using_sys_exit_enclosing_scope(three exempt cases, two still-flagged cases including thequit()false negative). Onmainit fails with unexpected messages and one missing message; with the fix it passes, as do the existingconsider_using_sys_exit*tests.tests/test_functional.py+tests/checkers/pass locally.