diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2020-02-17 16:40:23 -0800 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2020-02-17 16:40:23 -0800 |
commit | e99f820181e92bb8f11917ad56dc9622f32d72af (patch) | |
tree | 42134d67de6f85dfdc3064105296d2fddf3e9b02 | |
parent | b9e92583e4471fe656e298f4d69b257a909168b9 (diff) | |
download | isort-issue/1038-length-sort-as-aware.tar.gz |
Fix issue #1038: Adding support for combining sort within sections with length_sortissue/1038-length-sort-as-aware
-rw-r--r-- | isort/output.py | 1 | ||||
-rw-r--r-- | 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]: |