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

Don't remove imports from __init__.py #35

Closed
NeilGirdhar opened this issue Apr 9, 2018 · 6 comments
Closed

Don't remove imports from __init__.py #35

NeilGirdhar opened this issue Apr 9, 2018 · 6 comments

Comments

@NeilGirdhar
Copy link

A typical way to set up a project is to have the modules specify __all__ variables and then have the __init__.py from .module_name import *. This causes autoflake to remove all of the imports.

Please consider leaving the imports in __init__.py.

@myint
Copy link
Member

myint commented Apr 9, 2018

I think having such an option makes sense. It might be useful to get some metrics on how common this is. That would help us get an idea on whether this new behavior should be an option or the default.

Currently, autoflake can only exclude __init__.py files via --exclude=__init__.py. But that will make autoflake completely ignore it. And --exclude is only relevant to recursive mode.

@NeilGirdhar
Copy link
Author

NeilGirdhar commented Apr 9, 2018

It's pretty standard: e.g., https://github.com/numpy/numpy/blob/master/numpy/linalg/__init__.py

It's better to do it this way than to explicitly list things in the __init__.py otherwise changes to exported names have to be done in two places (__all__ in the module, and the import statement in __init__.py).

Also, I don't think it should be an option, or at least the option should default to true. Things imported by __init__.py are for the importer of that package—not for code within __init__.py.

@myint
Copy link
Member

myint commented Apr 10, 2018

I agree, about the option setting. It makes sense to by default be conservative and not remove things. I'll accept a pull request to make such a change. Otherwise, I'll take a look in a few months when I'm less busy. Thanks!

@NeilGirdhar
Copy link
Author

Thanks!

@CLiu13
Copy link
Contributor

CLiu13 commented Oct 27, 2018

Working on this issue, may I be assigned to it? Thanks!

CLiu13 added a commit to CLiu13/autoflake that referenced this issue Oct 28, 2018
When used, this new CLI argument will cause
autoflake to ignore unused imports when
checking any __init__.py files.

New tests have also been added to
accompany this new feature.

Closes PyCQA#35
CLiu13 added a commit to CLiu13/autoflake that referenced this issue Oct 28, 2018
When used, this new CLI argument will cause
autoflake to ignore unused imports when
checking any __init__.py files.

New tests have also been added to
accompany this new feature.

Closes PyCQA#35
CLiu13 added a commit to CLiu13/autoflake that referenced this issue Oct 28, 2018
When used, this new CLI argument will cause
autoflake to ignore unused imports when
checking any __init__.py files.

New tests have also been added to
accompany this new feature.

Closes PyCQA#35
CLiu13 added a commit to CLiu13/autoflake that referenced this issue Oct 28, 2018
When used, this new CLI argument will cause
autoflake to ignore unused imports when
checking any __init__.py files.

New tests have also been added to
accompany this new feature.

Closes PyCQA#35
CLiu13 added a commit to CLiu13/autoflake that referenced this issue Oct 28, 2018
When used, this new CLI argument will cause
autoflake to ignore unused imports when
checking any __init__.py files.

New tests have also been added to
accompany this new feature.

Closes PyCQA#35
CLiu13 added a commit to CLiu13/autoflake that referenced this issue Oct 28, 2018
When used, this new CLI argument will cause
autoflake to ignore unused imports when
checking any __init__.py files.

New tests have also been added to
accompany this new feature.

Closes PyCQA#35
CLiu13 added a commit to CLiu13/autoflake that referenced this issue Oct 28, 2018
When used, this new CLI argument will cause
autoflake to ignore unused imports when
checking any __init__.py files.

New tests have also been added to
accompany this new feature.

Closes PyCQA#35
CLiu13 added a commit to CLiu13/autoflake that referenced this issue Dec 6, 2018
When used, this new CLI argument will cause
autoflake to ignore unused imports when
checking any __init__.py files.

New tests have also been added to
accompany this new feature.

Closes PyCQA#35
@tiangolo
Copy link
Contributor

Just a note, as I was having a similar issue and came here before but didn't find this info.

You can exclude a single line adding a comment # noqa, like:

from .endpoints import role, token, user, utils  # noqa

I also submitted a PR adding that to the docs: #43

@myint myint closed this as completed in #42 Dec 23, 2018
myint pushed a commit that referenced this issue Dec 23, 2018
When used, this new CLI argument will cause
autoflake to ignore unused imports when
checking any __init__.py files.

New tests have also been added to
accompany this new feature.

Closes #35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants