-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Should black remove unused imports? #86
Comments
+1 |
There is already a tool that does that, btw.: https://github.com/myint/autoflake |
I'm afraid this is scope creep and something that can silently break otherwise valid programs. My intuition is to avoid this in Black. |
Javascript has the same issue and Prettier doesn't seem to have the same qualm in removing unused imports and vars by default. Is there anything special in Python that you can't do with ES modules? |
Imports has some weird side effects sometimes that would probably be really hard to detect statically. See the example here |
I see. I guess |
I agree with you! BTW, I've developed a tool to do this task safely, If you are interested please check it out! Docs: https://hadialqattan.github.io/pycln |
@ambv is there any example the program could silently break because of unused imports? Or at least do it with a specified flag that's disabled by default. In my opinion, it would be really useful. |
An example off the top of my head: readline is a stdlib module commonly used as simply an import. By importing it, history is enabled for
Yes it would be useful, but I don't believe this is in scope for Black. Black's focus is code style, not code optimization or linting. Other tools can and should handle those; I don't want to be in the business of writing an autofixer for linting issues. |
I've noticed that right now Black doesn't do that.
I'm wondering whether it's something that Black should take care of?
The text was updated successfully, but these errors were encountered: