Feature request: Remove superfluous `import a` statements when there is already `import a.b`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7k
- Forks
- 687
- Avg merge
- 4h 56m
- Merged PRs (30d)
- 2
Description
When there is already import a.b then import a is implicitly executed and a is added as a name. Hence, it does not make sense to have both like:
import logging # this is superfluous
import logging.handlers
This is sufficient, isort should remove the superfluous import
import logging.handlers
Reference:
https://docs.python.org/3/reference/simple_stmts.html#the-import-statement ("Examples")
https://docs.python.org/3/reference/import.html#the-module-cache
Note: if there is an import alias, only the last name is bound, hence in that case nothing can be removed:
import logging # not superfluous
import logging.handlers as log_handlers
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the two referenced Python documentation sections and verify the binding behavior for plain and aliased imports. Then locate isort’s import-processing logic and relevant tests; done means removing only redundant plain parent imports while preserving imports needed for aliases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100