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

Fix issue #1726: isort ignores reverse_sort when force_sort_within_sections is true. #1727

Merged
merged 1 commit into from May 12, 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -6,7 +6,8 @@ Find out more about isort's release policy [here](https://pycqa.github.io/isort/

### 5.9.0 TBD
- Fixed (https://github.com/PyCQA/isort/pull/1695) added imports being added to doc string in some cases.
- Fixed (https://github.com/PyCQA/isort/pull/1714) in rare case line continuation combined with tab can output invalid code.
- Fixed (https://github.com/PyCQA/isort/pull/1714) in rare cases line continuation combined with tabs can output invalid code.
- Fixed (https://github.com/PyCQA/isort/pull/1726) isort ignores reverse_sort when force_sort_within_sections is true.
- Implemented #1697: Provisional support for PEP 582: skip `__pypackages__` directories by default.
- Implemented #1705: More intuitive handling of isort:skip_file comments on streams.

Expand Down
1 change: 1 addition & 0 deletions isort/output.py
Expand Up @@ -108,6 +108,7 @@ def sorted_imports(
new_section_output = sorting.naturally(
new_section_output,
key=partial(sorting.section_key, config=config),
reverse=config.reverse_sort,
)

# uncollapse comments
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/test_ticketed_features.py
Expand Up @@ -1082,3 +1082,36 @@ def test_isort_can_push_star_imports_above_others_issue_1504():
from ._bar import All, Any, Not
"""
)


def test_isort_can_combine_reverse_sort_with_force_sort_within_sections_issue_1726():
"""isort should support reversing import order even with force sort within sections turned on.
See: https://github.com/PyCQA/isort/issues/1726
"""
assert (
isort.code(
"""
import blaaa
from bl4aaaaaaaaaaaaaaaa import r
import blaaaaaaaaaaaa
import bla
import blaaaaaaa
from bl1aaaaaaaaaaaaaa import this_is_1
from bl2aaaaaaa import THIIIIIIIIIIIISS_is_2
from bl3aaaaaa import less
""",
length_sort=True,
reverse_sort=True,
force_sort_within_sections=True,
)
== """
from bl2aaaaaaa import THIIIIIIIIIIIISS_is_2
from bl1aaaaaaaaaaaaaa import this_is_1
from bl4aaaaaaaaaaaaaaaa import r
from bl3aaaaaa import less
import blaaaaaaaaaaaa
import blaaaaaaa
import blaaa
import bla
"""
)