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

false positive for RET504 in case of globals #1310

Closed
tlambert03 opened this issue Dec 21, 2022 · 3 comments · Fixed by #1358
Closed

false positive for RET504 in case of globals #1310

tlambert03 opened this issue Dec 21, 2022 · 3 comments · Fixed by #1358
Labels
bug Something isn't working

Comments

@tlambert03
Copy link

The following code results in RET504 Unnecessary variable assignment before return statement

X: int | None = None

def get_x() -> int:
    global X
    if X is None:
        X = 1
    return X

however, as it's modifying a global, it's not unnecessary assignment. (naturally, whether this is a good pattern is a separate discussion 😂 ... but it's not syntactically unnecessary).

(Haven't checked the behavior of flake8-return)

@charliermarsh
Copy link
Member

Hah! Yeah, globals should probably be omitted from this check, since assignments are themselves side-effects.

@charliermarsh charliermarsh added the bug Something isn't working label Dec 21, 2022
squiddy added a commit to squiddy/ruff that referenced this issue Dec 24, 2022
squiddy added a commit to squiddy/ruff that referenced this issue Dec 24, 2022
@tlambert03
Copy link
Author

Thank you! 🙏

@charliermarsh
Copy link
Member

All @squiddy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants