From e99f820181e92bb8f11917ad56dc9622f32d72af Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Mon, 17 Feb 2020 16:40:23 -0800 Subject: Fix issue #1038: Adding support for combining sort within sections with length_sort --- isort/output.py | 1 + isort/sorting.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/isort/output.py b/isort/output.py index 8b753bcd..1efbe4ed 100644 --- a/isort/output.py +++ b/isort/output.py @@ -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, ), ) diff --git a/isort/sorting.py b/isort/sorting.py index 34f88699..ea5cafc8 100644 --- a/isort/sorting.py +++ b/isort/sorting.py @@ -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" @@ -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]: -- cgit v1.2.1