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
Better messaging for useless-import-alias and from imports #2309
Comments
You might as well do |
True, but the message's documentation says: Used when an import alias is same as original package. e.g using import numpy as numpy instead of import numpy as np To me at least this isn't the same use case. From that it seemed like it was designed to catch
import a.b.x as x though it seems less likely to have been an error on the user's part and it I'd argue it's not "useless". It seems more a candidate for a consider-import-from check, |
I agree. The warning here should indeed be 'consider-import-from'. |
I also think this was closed prematurely. The error messages should be as clear as possible, which this one isn't. The import is not useless, it has a purpose (like the @heoga noted). There is also a different way to do it (like @PCManticore noted). Even if Pylint somehow decrees that @PCManticore 's way of doing it is the preferred one, the message should note it, so that people won't need to google and find this thread. I'd at least change the message in cases like this bug is about to be clearer. |
Hey @Sveder I totally agree that the import is not useless, it has a purpose, just that it can be rewritten in a simpler way, which is what this check is supposed to be recommending anyway. Pylint is definitely not decreeing that the only way to write Python code is my way, not exactly sure how you got to that impression. We're all trying to be helpful here, to make the linter a good tool for recommending good and safe practices, and there's no hidden agenda behind our actions. |
@PCManticore Sorry, I think I was misunderstood, I definitely don't think there is some hidden agenda. I just meant that even if that is indeed a best practice (which it seems like, and I changed our code to be And now it seems like it is going to which I'm happy about :) |
@sushobhit27 @yushao2 implemented a fix for this in #4491, you can check it if you want as I see you assigned yourself to this issue :) |
I have a file in which I define an import of the format:
Which when run through pylint triggers the "useless-import-alias" warning. However, models != django.db.models so I don't believe this should be triggering the warning.
The text was updated successfully, but these errors were encountered: