diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2021-07-27 22:48:53 -0700 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2021-07-27 22:48:53 -0700 |
commit | 915aa6814cc7eef2305b336f4457c667e8f9fc38 (patch) | |
tree | b76b3d0a30f329b496cad02f796d9a46d864052b | |
parent | 8ae8d5045bcc4b80850d22fc4191dc36552d4e5b (diff) | |
download | isort-915aa6814cc7eef2305b336f4457c667e8f9fc38.tar.gz |
Fixed #1792: Sorting literals sometimes ignored when placed on first few lines of file.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | isort/core.py | 5 | ||||
-rw-r--r-- | tests/unit/test_regressions.py | 41 |
3 files changed, 46 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index c8085c36..f271a3c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Find out more about isort's release policy [here](https://pycqa.github.io/isort/ - Made all exceptions pickleable. - Fixed #1779: Pylama integration ignores pylama specific isort config overrides. - Fixed #1781: `--from-first` CLI flag shouldn't take any arguments. + - Fixed #1792: Sorting literals sometimes ignored when placed on first few lines of file. ### 5.9.2 July 8th 2021 - Improved behavior of `isort --check --atomic` against Cython files. diff --git a/isort/core.py b/isort/core.py index 4b24e45c..4d0a46eb 100644 --- a/isort/core.py +++ b/isort/core.py @@ -176,10 +176,13 @@ def process( (index == 0 or (index in (1, 2) and not contains_imports)) and stripped_line.startswith("#") and stripped_line not in config.section_comments + and stripped_line not in CODE_SORT_COMMENTS ): in_top_comment = True elif in_top_comment and ( - not line.startswith("#") or stripped_line in config.section_comments + not line.startswith("#") + or stripped_line in config.section_comments + or stripped_line in CODE_SORT_COMMENTS ): in_top_comment = False first_comment_index_end = index - 1 diff --git a/tests/unit/test_regressions.py b/tests/unit/test_regressions.py index 449f83d5..1853893e 100644 --- a/tests/unit/test_regressions.py +++ b/tests/unit/test_regressions.py @@ -1828,3 +1828,44 @@ v = """ v="""""" ''' ) + + +def test_literal_sort_at_top_of_file_issue_1792(): + assert ( + isort.code( + '''"""I'm a docstring! Look at me!""" + +# isort: unique-list +__all__ = ["Foo", "Foo", "Bar"] + +from typing import final # arbitrary + + +@final +class Foo: + ... + + +@final +class Bar: + ... +''' + ) + == '''"""I'm a docstring! Look at me!""" + +# isort: unique-list +__all__ = ['Bar', 'Foo'] + +from typing import final # arbitrary + + +@final +class Foo: + ... + + +@final +class Bar: + ... +''' + ) |