Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions isort/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,15 @@ def _build_arg_parser() -> argparse.ArgumentParser:
action="store_true",
help="Combines as imports on the same line.",
)
output_group.add_argument(
"--fsai",
"--force-separate-as-imports",
dest="force_separate_as_imports",
action="store_true",
help="Forces as imports to be emitted after the plain imports of the same "
"module, keeping the plain imports grouped in a single statement. "
"Has no effect when combine-as is enabled.",
)
output_group.add_argument(
"--cs",
"--combine-star",
Expand Down
7 changes: 7 additions & 0 deletions isort/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@ def _with_from_imports(
for from_import, sub_module in zip(from_imports, sub_modules, strict=False)
if sub_module in parsed.as_map["from"]
}
# when force_separate_as_imports (and not combine_as_imports), move aliased
# imports to the end so that non-aliased imports stay grouped together in a
# single block
if config.force_separate_as_imports and not config.combine_as_imports and as_imports:
non_aliased = [imp for imp in from_imports if imp not in as_imports]
aliased = [imp for imp in from_imports if imp in as_imports]
from_imports = non_aliased + aliased
if config.combine_as_imports and not ("*" in from_imports and config.combine_star):
if not config.no_inline_sort:
for as_import in as_imports:
Expand Down
1 change: 1 addition & 0 deletions isort/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class _Config:
lines_between_sections: int = 1
lines_between_types: int = 0
combine_as_imports: bool = False
force_separate_as_imports: bool = False
combine_star: bool = False
include_trailing_comma: bool = False
from_first: bool = False
Expand Down