Skip to content

Commit

Permalink
Fixed #1792: Sorting literals sometimes ignored when placed on first …
Browse files Browse the repository at this point in the history
…few lines of file.
  • Loading branch information
timothycrosley committed Jul 28, 2021
1 parent 8ae8d50 commit 915aa68
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion isort/core.py
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/test_regressions.py
Expand Up @@ -1828,3 +1828,44 @@ def test_isort_should_only_add_imports_to_valid_location_issue_1769():
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:
...
'''
)

0 comments on commit 915aa68

Please sign in to comment.