Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #1792: Sorting literals sometimes ignored when placed on first … #1793

Merged
merged 1 commit into from Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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:
...
'''
)