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

Fix false-positive in RET504 when referencing globals #1358

Merged
merged 1 commit into from Dec 24, 2022

Conversation

squiddy
Copy link
Contributor

@squiddy squiddy commented Dec 24, 2022

Closes #1310

|| self.settings.enabled.contains(&CheckCode::RET508)
{
flake8_return::plugins::function(self, body);
}
Copy link
Member

Choose a reason for hiding this comment

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

Could we pass in the list of globals, rather than relying on current_scope? That would remove the implicit dependence on the state of the scope stack when this is called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking of just passing &globals here, but I'm having some borrow-checker issues, because the globals are moved into the new scope which is taken by push_scope.

That said, I was just thinking that this example should also not trigger a RET504.

def nonlocal_assignment():
    X = 1
    def inner():
        nonlocal X
        X = 1
        return X

So I'm wondering whether I even need to look into globals for this. Need to check the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have taken a different approach now.

@charliermarsh charliermarsh merged commit 7f4ff1e into astral-sh:main Dec 24, 2022
@squiddy squiddy deleted the flake8-return-globals branch December 24, 2022 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

false positive for RET504 in case of globals
2 participants