Skip to content

Commit

Permalink
Merge pull request #1727 from PyCQA/issue/1726
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley authored May 12, 2021
2 parents a4c9719 + fb36ca3 commit 2894768
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
"""
)

0 comments on commit 2894768

Please sign in to comment.