-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
F401 unused-import for star-imports: false negative? #2407
Comments
I filed an upstream bug: PyCQA/pyflakes#766 |
So they think that if
$ python3 -m pyflakes <<< $'from foo import *; __all__ = ("a",)'
<stdin>:1:1: 'from foo import *' used; unable to detect undefined names
<stdin>:1:20: 'a' may be undefined, or defined from star imports: foo
$ python3 -m pyflakes <<< $'from foo import *; a'
<stdin>:1:1: 'from foo import *' used; unable to detect undefined names
<stdin>:1:20: 'a' may be undefined, or defined from star imports: foo |
I think I'm okay with Ruff's behavior here but open to being convinced otherwise. What do you think? |
I am unsure. I like ruffs behavior more. Will think what I can do for the time I need to support both flake8 and ruff (aka: until #2402 is fixed). |
For a file containing just the following (which is often seen in from math import * ❯ flake8 bug.py
bug.py:1:1: F403 'from math import *' used; unable to detect undefined names
bug.py:1:1: F401 'math.*' imported but unused
❯ ruff bug.py
bug.py:1:1: F403 `from math import *` used; unable to detect undefined names
Found 1 error. Using something from the from math import *
pi ❯ flake8 bug.py
bug.py:1:1: F403 'from math import *' used; unable to detect undefined names
bug.py:2:1: F405 'pi' may be undefined, or defined from star imports: math
❯ ruff bug.py
bug.py:1:1: F403 `from math import *` used; unable to detect undefined names
bug.py:2:1: F405 `pi` may be undefined, or defined from star imports: `math`
Found 2 errors. Using something that is not in the from math import *
invalid_name ❯ flake8 bug.py
bug.py:1:1: F403 'from math import *' used; unable to detect undefined names
bug.py:2:1: F405 'invalid_name' may be undefined, or defined from star imports: math
❯ ruff bug.py
bug.py:1:1: F403 `from math import *` used; unable to detect undefined names
bug.py:2:1: F405 `invalid_name` may be undefined, or defined from star imports: `math`
Found 2 errors. It has always bugged me getting |
Going to close for now because I'm comfortable with our current behavior. |
I think if all is defined it should recognize the star import, only throw if all is also undefined. |
I think I agree with this, but it would be good to hear if someone thinks there is a reason why this is bad practice for
|
flake8
andruff
differ for*
imports:I detected this as prior it had a
# noqa: F401
comment which was removed byRUF100
when I compared any leftovers withflake8
.The text was updated successfully, but these errors were encountered: