-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[ruff
] Fix false positive on global keyword (RUF052
)
#15235
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Correct | ||
##################### Correct ##################### | ||
|
||
for _ in range(5): | ||
pass | ||
|
@@ -37,6 +37,17 @@ def fun(): | |
_x = "reassigned global" | ||
return _x | ||
|
||
# (we had a false positive when a global var is used like this in 2 functions) | ||
_num: int | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (am I overcommenting? I was just worried that it might not be clear that this is a single "test" spread across 2 functions, but happy to remove) |
||
|
||
def set_num(): | ||
global _num | ||
_num = 1 | ||
|
||
def print_num(): | ||
print(_num) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: I inserted the test here into the But given it's not being at the end of this file, it means I got some large diffs in the fixture files. I reviewed the diffs and there's no "real" changes to them, as expected. |
||
|
||
class _ValidClass: | ||
pass | ||
|
||
|
@@ -70,7 +81,7 @@ def fun(x): | |
return ___ | ||
return x | ||
|
||
# Incorrect | ||
##################### Incorrect ##################### | ||
|
||
class Class_: | ||
def fun(self): | ||
|
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.
This might be just personal taste, so happy to remove!
But when I saw just
# Correct
, I wasn't sure if that was demarcating a section of code. I personally find this more clear.EDIT: should probably use blocker header format (otherwise conflicts with E266).