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

N816 considers generator/list comprehensions to be globally scoped #233

Open
ember91 opened this issue Sep 12, 2024 · 7 comments
Open

N816 considers generator/list comprehensions to be globally scoped #233

ember91 opened this issue Sep 12, 2024 · 7 comments

Comments

@ember91
Copy link

ember91 commented Sep 12, 2024

The following will trigger N816 twice:

(someVar1 == 8 for someVar1 in [])
[someVar2 == 8 for someVar2 in []]

N816 is explained as "mixedCase variable in global scope".

But are they really globals? Should there not be a new error code Nxyz for this? Or is it a limitation or shortcut in pep8-naming that leads to this behavior?

Version: 0.14.1

@ember91 ember91 changed the title N816 considers generator/list comprehensions to be globals N816 considers generator/list comprehensions to be globally scoped Sep 12, 2024
@sigmavirus24
Copy link
Member

So on some versions of Python (I think this was fixed ~recently) leaked the variable from the list comprehension outside of the comprehension. That may no longer be correct, but if your example is what you're checking, you would (on those versions) be leaking someVar1 or someVar2 into the global context.

@ember91
Copy link
Author

ember91 commented Sep 12, 2024

I tested this with Python 3.11.5.

But which rule is supposed to catch this then if not N816?

@sigmavirus24
Copy link
Member

It would be N816 but I suspect we need to put a version cap on that , I just can't remember when the language changed such that comprehension bindings weren't leaked

@sigmavirus24
Copy link
Member

I suspect we could eliminate this behavior of the check since we no longer support the buggy versions of Python https://stackoverflow.com/a/29907448

@ember91
Copy link
Author

ember91 commented Sep 12, 2024

I'm a bit lost here. Eliminate what behavior of the check? That it identifies mixed case variables in comprehensions?

@dhruvmanila
Copy link

So on some versions of Python (I think this was fixed ~recently) leaked the variable from the list comprehension outside of the comprehension. That may no longer be correct, but if your example is what you're checking, you would (on those versions) be leaking someVar1 or someVar2 into the global context.

Can you say more about this? I'm not sure if this was ever the case unless it's a named assignment (x := 1) which is a special case that's mentioned in the PEP as well.

@ember91
Copy link
Author

ember91 commented Sep 26, 2024

Any more input here? @sigmavirus24 @dhruvmanila

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

No branches or pull requests

3 participants