PyCQA / PyCQA/isort

Possibility to locally turn off `remove_redundent_aliases`

Open
#2,189 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7k
Forks
687
Avg merge
4h 56m
Merged PRs (30d)
2

Description

In general remove_redundent_aliases is a nice setting, and it makes sense to have it enabled across a large code base in general.

However, type checkers use redundant module or redundant symbol aliases (see second bullet point) to communicate information about whether a symbol should be considered private or public by the type checker. This feature is quite convenient, because it can avoid having to double-maintain the good old __all__ list.

This means that turning off remove_redundent_aliases is valuable for package-level __init__.py that deal with symbol forwarding to the outside. But turning of remove_redundent_aliases globally just for the usages in __init__.py's would allow truely redundant aliases to sneak in where they aren't meaningful. Alternatively, using # isort: off ... # isort: on wrapping fails to leverage isort for the its main purpose of sorting all the imports. So for a large __init__.py turning off isort entirely is also not ideal.

For these reasons it would be great if the redundant alias feature could be turned off locally via an action, e.g.:

# isort: remove-redundent-aliases-off
from . import PublicThingA as PublicThingA
from . import PublicThingB as PublicThingB
from . import PrivateThing
# isort: remove-redundent-aliases-on

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating isort's handling of action comments and the remove_redundent_aliases setting, then inspect nearby tests for local directives. Implement the proposed off/on actions so imports remain sorted while redundant aliases are preserved only within the scoped region, and add coverage for the example behavior.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.