-
Notifications
You must be signed in to change notification settings - Fork 179
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
Don't report unused imports in __init__.py #162
Comments
Original comment by icordasc (@sigmavirus24?) on Launchpad: @asmeurer no it shouldn't. There are people who write actually classes and functions in |
Original comment by icordasc (@sigmavirus24?) on Launchpad: With the same exact example above you can not be certain of that. I could write something that imports a module, refactor and completely forget to remove the import were I to not have pyflakes reporting for it. Why should pyflakes just assume that I'm leaving it there for someone else to import into their library? In short, the best way to really do this is to use from sub_module import (exported, names) etc.all = [exported, names, ...] Then do import sub_module1 etc.import sub_modulen all = [] for i in range(1, n + 1): Obviously that's a bit contrived, but you get the point. You can be guaranteed it will execute only once and it won't cause you other troubles with pyflakes. |
Original comment by asmeurer (@asmeurer?) on Launchpad:
Because you're writing it in By the way, what is the general stance for pyflakes aboud false positives vs. false negatives? |
Original comment by icordasc (@sigmavirus24?) on Launchpad: It's bad style in my opinion too, but is far more common than I like. You're still going to have push back from plenty of people though that there's no checking on |
Original comment by florent.x (@florentx?) on Launchpad: IMHO, the http://docs.python.org/3.4/tutorial/modules.html#importing-from-a-package If you need more flexibility, Flake8 "# noqa" should help. |
Original comment by asmeurer (@asmeurer?) on Launchpad: Today's update to PEP 8 says, "Wildcard imports (from import *) should be avoided, as they make it unclear which names are present in the namespace, confusing both readers and many automated tools. There is one defensible use case for a wildcard import, which is to republish an internal interface as part of a public API (for example, overwriting a pure Python implementation of an interface with the definitions from an optional accelerator module and exactly which definitions will be overwritten isn't known in advance). "When republishing names this way, the guidelines below regarding public and internal interfaces still apply." Is that argument enough to change this behavior? |
Original comment by pierre-sassoulas on Launchpad: Maybe flake could give a different more explicit warning message and not F401, when there is unused import in an |
Original comment by alevis on Launchpad: Still an inconvenience. |
I think that in case |
use |
Original report by asmeurer (@asmeurer?) on Launchpad:
__init__.py
files are full of unused import warnings, because all they are are imports. But this is one instance where it is correct to import something and not "use" it.The text was updated successfully, but these errors were encountered: