-
Notifications
You must be signed in to change notification settings - Fork 1k
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
F823 (undefined local) triggered by a double import #6029
Comments
Thanks! Looks like a bug. |
Or, this may actually be correct? I'm not 100% sure. Python does error with an early unbound access:
So in that case, F823 feels correct to me. |
Ha, you're right 😅 ! I could have seen it either way since it does feel wrong and worth yelling about one way or the other. My first thought was looking at double_import.py:11:8: W0621: Redefining name 'sys' from outer scope (line 1) (redefined-outer-name)
double_import.py:6:10: E0601: Using variable 'sys' before assignment (used-before-assignment)
double_import.py:11:8: W0404: Reimport 'sys' (imported line 1) (reimported)
double_import.py:11:8: C0415: Import outside toplevel (sys) (import-outside-toplevel)
double_import.py:1:0: W0611: Unused import sys (unused-import) This is also a good reminder to not just lint your minimal example but also try, you know... running it 😆 . Thanks for the follow-up! |
I had the same reaction as you, I actually thought that code was fine! I'm gonna add some test cases so that we're at least explicit about this. |
First, thanks for ruff! It rocks and I love it 😍 .
I ran across a minor issue recently and wanted to document it here in case other folks do too. I'm not sure if it's an intentional change or not...
Moving from version
0.0.278
to0.0.279
I noticedF823 Local variable 'sys' referenced before assignment
occurring in a new situation. If you import a module twice, this rule flags references in between the two imports. For example:It does feel right to call out the double
import sys
as unnecessary here, but F823 seems misleading. Is this change intentional?I didn't see an obvious answer in the
0.0.279
changelog though there are a couple changes that seem possibly relevant. Will update here if I find anything useful. The change that seems most relevant at a glance (to my untrained eye anyway) is bcec2f0.The text was updated successfully, but these errors were encountered: