Fix inline comment duplication across merged from X import lines#2499
Merged
Conversation
Co-authored-by: DanielNoord <13665637+DanielNoord@users.noreply.github.com> Agent-Logs-Url: https://github.com/PyCQA/isort/sessions/a161028f-48c2-4abc-a92a-c888c96ad5cf
Copilot created this pull request from a session on behalf of
DanielNoord
March 24, 2026 21:47
View session
DanielNoord
approved these changes
Mar 24, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2499 +/- ##
=======================================
Coverage 99.16% 99.16%
=======================================
Files 40 40
Lines 3096 3097 +1
Branches 674 674
=======================================
+ Hits 3070 3071 +1
Misses 14 14
Partials 12 12 🚀 New features to boost your workflow:
|
404c66f to
19570ec
Compare
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.
When multiple
from foo importstatements for the same module are merged and as-imports are present, an inline comment from the first regular-import group leaks into subsequent groups.Root cause
In
_with_from_imports(output.py),commentsis populated once fromcategorized_comments["from"][module]before thewhile from_imports:loop. When as-imports split the loop into multiple iterations,commentswas never cleared after being consumed in the first non-as-import group, causing it to be re-applied to subsequent groups.Changes
isort/output.py: Addcomments = Noneat the end of theelsebranch in thewhile from_imports:loop, after all reformatting logic — mirroring the existing reset already present in theforce_single_linebranch.tests/unit/test_ticketed_features.py: Add regression test for this case, including idempotency check.