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

[ruff] Fix false positive on global keyword (RUF052) #15235

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions crates/ruff_linter/resources/test/fixtures/ruff/RUF052.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Correct
##################### Correct #####################
Copy link
Author

@Garrett-R Garrett-R Jan 3, 2025

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).


for _ in range(5):
pass
Expand Down Expand Up @@ -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)
Copy link
Author

Choose a reason for hiding this comment

The 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)

_num: int

def set_num():
global _num
_num = 1

def print_num():
print(_num)
Copy link
Author

@Garrett-R Garrett-R Jan 3, 2025

Choose a reason for hiding this comment

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

Note: I inserted the test here into the ############### Correct ############# section, seemed right thing to do.

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

Expand Down Expand Up @@ -70,7 +81,7 @@ def fun(x):
return ___
return x

# Incorrect
##################### Incorrect #####################

class Class_:
def fun(self):
Expand Down
Loading
Loading