Skip to content

Commit

Permalink
Fix issue #1038: Adding support for combining sort within sections wi…
Browse files Browse the repository at this point in the history
…th length_sort
  • Loading branch information
timothycrosley committed Feb 18, 2020
1 parent b9e9258 commit e99f820
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions isort/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def sorted_imports(
order_by_type=config.order_by_type,
force_to_top=config.force_to_top,
lexicographical=config.lexicographical,
length_sort=config.length_sort,
),
)

Expand Down
9 changes: 7 additions & 2 deletions isort/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def module_key(


def section_key(
line: str, order_by_type: bool, force_to_top: List[str], lexicographical: bool = False
line: str,
order_by_type: bool,
force_to_top: List[str],
lexicographical: bool = False,
length_sort: bool = False,
) -> str:
section = "B"

Expand All @@ -54,7 +58,8 @@ def section_key(
section = "A"
if not order_by_type:
line = line.lower()
return f"{section}{line}"

return f"{section}{len(line) if length_sort else ''}{line}"


def naturally(to_sort: Iterable[str], key: Optional[Callable[[str], Any]] = None) -> List[str]:
Expand Down

0 comments on commit e99f820

Please sign in to comment.