-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix a crash when nonlocal is defined at module level #8737
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
Fix a crash when nonlocal is defined at module level #8737
Conversation
Add a new checker ``nonlocal-defined-at-module-level`` when a ``nonlocal`` is defined at module-level. Closes pylint-dev#8735
Thanks for picking this up! When I apply the crash fix, but without applying the new checker, I get this from linting the bug report:
Is that enough, without needing a new checker? |
This comment has been minimized.
This comment has been minimized.
Yeah we could also do that @jacobtylerwalls. My rationale is that the new checker correspond to a different Python output when running the code. But I understand if we want to keep things lean and just stick to the fix without the new checker. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked, and when doing this:
class A:
nonlocal X
python still gives a SyntaxError, like so:
SyntaxError: no binding for nonlocal 'X' found
So I think we can just let the original message do the work.
The rationale for the new checker was to distinguish the module-level definition from the function/class definition. Python gives different messages for these 2 distinct situations and I tried to reflect that here. That said, we donβt necessarily need to mirror the Python messages if Pylint output is accurate enough. |
Ah, I didn't realize you were targeting the different wording in the two SyntaxErrors. (But yes, I think that's too subtle to justify adding a new check.) |
π€ According to the primer, this change has no effect on the checked open source code. π€π This comment was generated for commit 82c31e5 |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #8737 +/- ##
=======================================
Coverage 95.82% 95.82%
=======================================
Files 173 173
Lines 18381 18381
=======================================
Hits 17613 17613
Misses 768 768
|
* Fix a crash when a ``nonlocal`` is defined at module-level. Closes #8735 (cherry picked from commit 33d3f22) Co-authored-by: Mark Byrne <[email protected]>
Type of Changes
Description
Defining nonlocal at the module level is a SyntaxError.
Closes #8735