-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
The codebase I work on uses code like this for explicit re-exports in many __init__.py files:
from .utils import (
test_directory as test_directory,
test_id as test_id
)
It's useful to have code like this have exactly one import per line-- it's easier to tell at a glance what is being exported.
It's possible I've missed something but I don't think either isort or ruff offers a way to reliably achieve this formatting. By default, both formatters produce (1) below. If you turn on Isort's combine-as or ruff's combine-as-imports and you are under the line length limit, then you get (2).
# (1) One aliased import per line in separate import statements
from .utils import test_directory as test_directory
from .utils import test_id as test_id
# (2) Multiple imports per line if under line limit
from .utils import test_directory as test_directory, test_id as test_id
To get around this, we currently disable isort using # isort: off comments when we use this pattern. The lack of ability to do something similar in ruff is preventing us adopting ruff in place of isort.
I propose an option that forces aliased imports to a single line, but still groups them together in a single import statement-- then we wouldn't even need to turn off the import sorter.