Fix sort_reexports code mangling#2283
Merged
DanielNoord merged 4 commits intoPyCQA:mainfrom Jan 9, 2025
Merged
Conversation
2 tasks
Contributor
Author
|
It seems a bit unfair that DeepSource blocks this PR for cyclomatic complexity while it was already this high :) |
|
👋 This is great, thanks for the fix! Any chance this could be released in any of the next versions? I agree that it's a bit mad to hold this off on the basis of complexity given how complex the original function is. |
Contributor
Author
|
We'd have to find an active maintainer to ping or something, given that there's 50 open pull requests |
Contributor
Author
|
@hugovk @timothycrosley sorry for the noise, I'd like to get some traction on this since it's been pending quite some time. |
Contributor
|
@Helveg I don't have merge rights here, perhaps @staticdev can help. |
DanielNoord
approved these changes
Jan 9, 2025
Member
|
Thanks! Going to merge this :) |
Merged
Merged
736-c41-2c1-e464fc974
added a commit
to Swiss-Armed-Forces/Loom
that referenced
this pull request
Feb 20, 2026
This MR contains the following updates: | Package | Type | Update | Change | OpenSSF | |---|---|---|---|---| | [isort](https://github.com/PyCQA/isort) ([changelog](https://github.com/PyCQA/isort/releases)) | dev | major | `^5.13.2` → `^7.0.0` | [](https://securityscorecards.dev/viewer/?uri=github.com/PyCQA/isort) | --- ### Release Notes <details> <summary>PyCQA/isort (isort)</summary> ### [`v7.0.0`](https://github.com/PyCQA/isort/releases/tag/7.0.0) [Compare Source](PyCQA/isort@6.1.0...7.0.0) #### Changes #### 💥 Breaking Changes - Drop support for Python 3.9 ([#​2430](PyCQA/isort#2430)) [@​DanielNoord](https://github.com/DanielNoord) #### 🚀 Features - Show absolute paths in skipped file messages ([#​2416](PyCQA/isort#2416)) [@​pranlawate](https://github.com/pranlawate) #### 🪲 Fixes - Some fixes for Python 3.14 ([#​2433](PyCQA/isort#2433)) [@​DanielNoord](https://github.com/DanielNoord) - Test on `3.14` and fix any bugs ([#​2425](PyCQA/isort#2425)) [@​DanielNoord](https://github.com/DanielNoord) - Update CHANGELOG.md + Fix Formatting and Grammar ([#​2419](PyCQA/isort#2419)) [@​lukbrew25](https://github.com/lukbrew25) - Fix output of hanging indent for long lines with noqa ([#​2407](PyCQA/isort#2407)) [@​matan1008](https://github.com/matan1008) #### :construction\_worker: Continuous Integration - Format with `ruff` instead of `black` ([#​2432](PyCQA/isort#2432)) [@​DanielNoord](https://github.com/DanielNoord) - Target 3.10 for `ruff` ([#​2431](PyCQA/isort#2431)) [@​DanielNoord](https://github.com/DanielNoord) - Update development dependencies to latest version ([#​2426](PyCQA/isort#2426)) [@​DanielNoord](https://github.com/DanielNoord) - docs: update pre-commit examples to version 6.1.0 ([#​2413](PyCQA/isort#2413)) [@​pranlawate](https://github.com/pranlawate) - Small cleanup for developer environment ([#​2418](PyCQA/isort#2418)) [@​DanielNoord](https://github.com/DanielNoord) #### 📦 Dependencies - Bump actions/setup-python from 5 to 6 in the github-actions group ([#​2411](PyCQA/isort#2411)) @​[dependabot\[bot\]](https://github.com/apps/dependabot) ### [`v6.1.0`](https://github.com/PyCQA/isort/blob/HEAD/CHANGELOG.md#610-October-1-2025) [Compare Source](PyCQA/isort@6.0.1...6.1.0) - Add python 3.14 classifier and badge ([#​2409](PyCQA/isort#2409)) [@​staticdev](https://github.com/staticdev) - Drop use of non-standard pkg\_resources API ([#​2405](PyCQA/isort#2405)) [@​dvarrazzo](https://github.com/dvarrazzo) ### [`v6.0.1`](https://github.com/PyCQA/isort/blob/HEAD/CHANGELOG.md#601-Febuary-26-2025) [Compare Source](PyCQA/isort@6.0.0...6.0.1) - Add OSError handling in find\_imports\_in\_file ([#​2331](PyCQA/isort#2331)) [@​kobarity](https://github.com/kobarity) ### [`v6.0.0`](https://github.com/PyCQA/isort/blob/HEAD/CHANGELOG.md#600-January-27-2025) [Compare Source](PyCQA/isort@5.13.2...6.0.0) - Remove support for Python 3.8 ([#​2327](PyCQA/isort#2327)) [@​DanielNoord](https://github.com/DanielNoord) - Python 3.13 support ([#​2306](PyCQA/isort#2306)) [@​mayty](https://github.com/mayty) - Speed up exists\_case\_sensitive calls ([#​2264](PyCQA/isort#2264)) [@​correctmost](https://github.com/correctmost) - Ensure that split\_on\_trailing\_comma works with as imports ([#​2340](PyCQA/isort#2340)) [@​DanielNoord](https://github.com/DanielNoord) - Black profile: enable magic comma ([#​2236](PyCQA/isort#2236)) [@​MrMino](https://github.com/MrMino) - Update line\_length and single\_line\_exclusions in google profile ([#​2149](PyCQA/isort#2149)) [@​jagapiou](https://github.com/jagapiou) - Allow --diff to be used with --jobs ([#​2302](PyCQA/isort#2302)) [@​mnakama](https://github.com/mnakama) - Fix wemake profile to have correct character limit ([#​2241](PyCQA/isort#2241)) [@​sobolevn](https://github.com/sobolevn) - Fix sort\_reexports code mangling ([#​2283](PyCQA/isort#2283)) [@​Helveg](https://github.com/Helveg) - Fix correct group by package tokenization ([#​2136](PyCQA/isort#2136)) [@​glasnt](https://github.com/glasnt) </details> --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yLjQiLCJ1cGRhdGVkSW5WZXIiOiI0My4yNS43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==--> See merge request swiss-armed-forces/cyber-command/cea/loom!284 Co-authored-by: Loom MR Pipeline Trigger <group_103951964_bot_9504bb8dead6d4e406ad817a607f24be@noreply.gitlab.com> Co-authored-by: shrewd-laidback palace <shrewd-laidback-palace-736-c41-2c1-e464fc974@swiss-armed-forces-open-source.ch>
736-c41-2c1-e464fc974
added a commit
to Swiss-Armed-Forces/Loom
that referenced
this pull request
Feb 20, 2026
chore(deps): update isort (major) This MR contains the following updates: | Package | Type | Update | Change | OpenSSF | |---|---|---|---|---| | [isort](https://github.com/PyCQA/isort) ([changelog](https://github.com/PyCQA/isort/releases)) | dev | major | `^5.13.2` → `^7.0.0` | [](https://securityscorecards.dev/viewer/?uri=github.com/PyCQA/isort) | --- ### Release Notes <details> <summary>PyCQA/isort (isort)</summary> ### [`v7.0.0`](https://github.com/PyCQA/isort/releases/tag/7.0.0) [Compare Source](PyCQA/isort@6.1.0...7.0.0) #### Changes #### 💥 Breaking Changes - Drop support for Python 3.9 ([#​2430](PyCQA/isort#2430)) [@​DanielNoord](https://github.com/DanielNoord) #### 🚀 Features - Show absolute paths in skipped file messages ([#​2416](PyCQA/isort#2416)) [@​pranlawate](https://github.com/pranlawate) #### 🪲 Fixes - Some fixes for Python 3.14 ([#​2433](PyCQA/isort#2433)) [@​DanielNoord](https://github.com/DanielNoord) - Test on `3.14` and fix any bugs ([#​2425](PyCQA/isort#2425)) [@​DanielNoord](https://github.com/DanielNoord) - Update CHANGELOG.md + Fix Formatting and Grammar ([#​2419](PyCQA/isort#2419)) [@​lukbrew25](https://github.com/lukbrew25) - Fix output of hanging indent for long lines with noqa ([#​2407](PyCQA/isort#2407)) [@​matan1008](https://github.com/matan1008) #### :construction\_worker: Continuous Integration - Format with `ruff` instead of `black` ([#​2432](PyCQA/isort#2432)) [@​DanielNoord](https://github.com/DanielNoord) - Target 3.10 for `ruff` ([#​2431](PyCQA/isort#2431)) [@​DanielNoord](https://github.com/DanielNoord) - Update development dependencies to latest version ([#​2426](PyCQA/isort#2426)) [@​DanielNoord](https://github.com/DanielNoord) - docs: update pre-commit examples to version 6.1.0 ([#​2413](PyCQA/isort#2413)) [@​pranlawate](https://github.com/pranlawate) - Small cleanup for developer environment ([#​2418](PyCQA/isort#2418)) [@​DanielNoord](https://github.com/DanielNoord) #### 📦 Dependencies - Bump actions/setup-python from 5 to 6 in the github-actions group ([#​2411](PyCQA/isort#2411)) @​[dependabot\[bot\]](https://github.com/apps/dependabot) ### [`v6.1.0`](https://github.com/PyCQA/isort/blob/HEAD/CHANGELOG.md#610-October-1-2025) [Compare Source](PyCQA/isort@6.0.1...6.1.0) - Add python 3.14 classifier and badge ([#​2409](PyCQA/isort#2409)) [@​staticdev](https://github.com/staticdev) - Drop use of non-standard pkg\_resources API ([#​2405](PyCQA/isort#2405)) [@​dvarrazzo](https://github.com/dvarrazzo) ### [`v6.0.1`](https://github.com/PyCQA/isort/blob/HEAD/CHANGELOG.md#601-Febuary-26-2025) [Compare Source](PyCQA/isort@6.0.0...6.0.1) - Add OSError handling in find\_imports\_in\_file ([#​2331](PyCQA/isort#2331)) [@​kobarity](https://github.com/kobarity) ### [`v6.0.0`](https://github.com/PyCQA/isort/blob/HEAD/CHANGELOG.md#600-January-27-2025) [Compare Source](PyCQA/isort@5.13.2...6.0.0) - Remove support for Python 3.8 ([#​2327](PyCQA/isort#2327)) [@​DanielNoord](https://github.com/DanielNoord) - Python 3.13 support ([#​2306](PyCQA/isort#2306)) [@​mayty](https://github.com/mayty) - Speed up exists\_case\_sensitive calls ([#​2264](PyCQA/isort#2264)) [@​correctmost](https://github.com/correctmost) - Ensure that split\_on\_trailing\_comma works with as imports ([#​2340](PyCQA/isort#2340)) [@​DanielNoord](https://github.com/DanielNoord) - Black profile: enable magic comma ([#​2236](PyCQA/isort#2236)) [@​MrMino](https://github.com/MrMino) - Update line\_length and single\_line\_exclusions in google profile ([#​2149](PyCQA/isort#2149)) [@​jagapiou](https://github.com/jagapiou) - Allow --diff to be used with --jobs ([#​2302](PyCQA/isort#2302)) [@​mnakama](https://github.com/mnakama) - Fix wemake profile to have correct character limit ([#​2241](PyCQA/isort#2241)) [@​sobolevn](https://github.com/sobolevn) - Fix sort\_reexports code mangling ([#​2283](PyCQA/isort#2283)) [@​Helveg](https://github.com/Helveg) - Fix correct group by package tokenization ([#​2136](PyCQA/isort#2136)) [@​glasnt](https://github.com/glasnt) </details> --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yLjQiLCJ1cGRhdGVkSW5WZXIiOiI0My4yNS43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==--> See merge request swiss-armed-forces/cyber-command/cea/loom!284 Co-authored-by: Loom MR Pipeline Trigger <group_103951964_bot_9504bb8dead6d4e406ad817a607f24be@noreply.gitlab.com> Co-authored-by: open-source Pipeline <group_90701827_bot_ed04ae348bc5f40af9966fb8b6867e99@noreply.gitlab.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2193 and fixes #2252,
The logic behind
sort_reexportswas keeping track of a point in theoutput_stream, and seeked to that point before writing the sorted reexports back in, in order to compensate for the first line of this code sorting section being written into the stream already.The original code tried to track the position of the point with every iteration, but since the code is very branched, and contains ~10
.writestatements, this fails, and this approach would never be easily maintained. So I opted to simplify the approach by instead rolling back the write position in the stream by the length of the segment that was written too much.Additionally, when the input code sort section is longer than the sorted output (e.g., when there is a lot of trimmed whitespace), some previously written garbage remained, which I fixed by truncating the stream after writing to it during
sort_reexportoperations.