-
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 triggers based on renaming imports #7303
Comments
We allow Some related discussion at #5697 |
To me, this looks correct and intended. Whilst both import examples lead to unused symbol in the current module, both also lead to symbols that exist and can be imported by other modules. |
That being said, mixing explicit re-exports and |
Okay, I see why it happens, then, but the code that someone originally was confused about: from .config import config as config
from .config_training import config as config_training still seems surprising - you can't "reexport" the second I'll just suggest that they use |
Thanks, by the way! |
I was thinking the best solution would be to not do the explicit reexports, but move entirely to I wouldn't mind having a rule that enforced all files (that don't start with an underscore, anyway) have an |
Ruff's F401 triggers if you import something and rename it, but not if you rename it but keep the name the same.
For example, this file doesn't use any of it's imports:
Which I'm running in VI via ALE using the LSP to get the comments, but I can also run it manually:
Notice that the error doesn't trigger if you
from a import b as b
, but only if you usefrom a import b as c
. This was from an__init__.py
file that didn't set__all__
, which isn't a good pattern, and it goes away as it should if you set__all__
). But I think it should be consistent. I'm pretty sure the problem is thatfrom a import b as b
is being treated asfrom a import b; b = b
which "uses"b
, making it not unused. That's a guess.The text was updated successfully, but these errors were encountered: