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

Redundant local name for modified imports #1281

Closed
scop opened this issue Jul 6, 2020 · 4 comments
Closed

Redundant local name for modified imports #1281

scop opened this issue Jul 6, 2020 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@scop
Copy link
Contributor

scop commented Jul 6, 2020

isort 5.0.4 changes this

import urllib.parse as parse

...to this:

from urllib import parse as parse

I think as parse is redundant and should not be emitted, but just

from urllib import parse

FWIW pylint will issue useless-import-alias for the duplication.

@timothycrosley timothycrosley added the bug Something isn't working label Jul 8, 2020
@timothycrosley timothycrosley added this to the 5.1.0 milestone Jul 8, 2020
@jdufresne
Copy link
Collaborator

More generally, perhaps isort should remove useless aliases whether isort generated them or not:

input:

from datetime import datetime as datetime

print(datetime.now())

current output: unchanged

expected output:

from datetime import datetime

print(datetime.now())

@scop
Copy link
Contributor Author

scop commented Jul 11, 2020

I agree. But for completeness, I've seen documented conventions where those "useless" aliases are actually used to mark an import being part of an API. So e.g. for a module that doesn't use foo itself at all, from bar import foo as foo with the alias serves to note that the import isn't accidental. I can't locate a reference to such a convention at the moment, nor do I actually personally find it a good one, but thought I'd mention it, FWIW.

@timothycrosley
Copy link
Member

This is fixed in develop and will be released in the 5.1.0 minor release slated for release by end of month at the latest. As part of this a new remove_redundent_aliases config option has been added - though no alias will now show up by default either way if there was not one present originally.

Thanks!

~Timothy

@timothycrosley
Copy link
Member

This has now been deployed to PyPI in the 5.1.0 release, thanks again!

~Timothy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants