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

F401 (imported but not used) in __init__.py #471

Closed
crusaderky opened this issue Sep 23, 2019 · 3 comments
Closed

F401 (imported but not used) in __init__.py #471

crusaderky opened this issue Sep 23, 2019 · 3 comments

Comments

@crusaderky
Copy link

crusaderky commented Sep 23, 2019

Virtually every medium to large library package I've encountered so far is structured as follows:

  • impl.py defines objects
  • __init__.py imports them, so that the library users don't need to know about impl.py.

At the moment, the __init__.py modules of packages that use flake8 are littered with either # noqa: F401 on every single line or # flake8: noqa at the top of the module which blanket disables everything.

This change request is to add a special case in pyflakes that disables F401 (only) when the file name is __init__.py.
An alternative approach would be to add to flake8 the ability to suppress specific errors at module level, e.g. # flake8: noqa: F401.

@asottile
Copy link
Member

If you list the things you export in __all__ (a best practice for __init__.py files which export names) you will not need to disable anything -- that marks the names as used

@crusaderky
Copy link
Author

When you have a large amount of objects, it's convenient to define __all__ programmatically, which pyflakes doesn't figure out:

__all__ = tuple(k for k in locals() if not k.startswith("_"))

@asottile
Copy link
Member

sure, I was just giving the suggestion from the duplicate issue #162

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

2 participants