Consider standardizing imports from the standard library
See original GitHub issueI love isort and probably run it hundreds of times a day. It standardizes all of my imports so I never have to think about them.
One pain point I have is that I would like to standardize the imports from the standard library where there are aliases. Specifically, in Python 3.10, I believe that typing.Collection is equivalent to collections.abc.Collection. It would be nice to just pick one (ideally the latter, I think).
This may be a complicated feature since in earlier versions of Python, these are not equivalent. Probably the simplest implementation is for the user to present a list of pairs to isort for conversion.
Issue Analytics
- State:
- Created a year ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
The Python Standard Library — Python 3.11.1 documentation
The library contains built-in modules (written in C) that provide access to system functionality such as file I/O that would otherwise be inaccessible...
Read more >Using StandardScaler() Function to Standardize Python Data
Python sklearn library offers us with StandardScaler() function to standardize the data values into a standard format. Syntax:
Read more >Modularizing the Standard Library is a Reorganization ...
That's a lot if all you needed was std :: plus . Lack of Logical Partitioning: It is common for C++ programmers to...
Read more >The standard library — Introduction to Programming with Python
Instead of going through them exhaustively, we will just consider some examples ... We can import a module from the standard library in...
Read more >The Path to Standardization at Thomas J. Watson Library
As the staff considered ways we could speed up the cataloging, ... libraries across the world used a cataloging standard known as the ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I think we agree there.
Yes, I think you understand the restrictions of when
from foo import bar as bazcan be changed toimport foo.bar as baz. But my point is that I’m not sure that isort can understand when this is safe - not without a lot of new code - since it currently doesn’t understand types or verify imports after writing them. But this is probably off-topic unless you are asking for both in this ticket.I agree that the original ask would probably not require any new introspection, just some lookup tables.
Perhaps if there were no tools checking for unused imports now, it would be a great new feature. But there are already several other linting tools that check this, and adding it to isort will probably not have the effect of maintainers dropping those other tools as they check for other smells. In my view, if every tool had a strict single responsibility design, unused imports would be under the same tool as unused variable names and uncalled functions, not an import sorter. But are you actually adding this feature ask to the others already brought up?
Yes, agreed.
Right, I’m not.
I’m not asking for a check though. I’m asking for import rewriting, which I currently do with
So, I disagree that there are “several linting tools that do this”. There is one tool that does this, and it’s not exactly accessible.
Great, we’re on the same page.
No, I only mentioned these in response to an argument about “single responsibility”.