Fix opening-line comment moving to alias attribute line on wrapped imports#2491
Merged
DanielNoord merged 8 commits intomainfrom Mar 12, 2026
Merged
Fix opening-line comment moving to alias attribute line on wrapped imports#2491DanielNoord merged 8 commits intomainfrom
DanielNoord merged 8 commits intomainfrom
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2491 +/- ##
==========================================
- Coverage 99.18% 99.16% -0.03%
==========================================
Files 40 40
Lines 3085 3096 +11
Branches 672 674 +2
==========================================
+ Hits 3060 3070 +10
Misses 14 14
- Partials 11 12 +1 🚀 New features to boost your workflow:
|
Copilot
AI
changed the title
[WIP] Fix comments moving bug when using import aliases
Fix comment on opening Mar 12, 2026
import ( line moving to alias attribute line
Co-authored-by: DanielNoord <13665637+DanielNoord@users.noreply.github.com>
…erability Co-authored-by: DanielNoord <13665637+DanielNoord@users.noreply.github.com>
…trary file write vulnerability Co-authored-by: DanielNoord <13665637+DanielNoord@users.noreply.github.com>
98377d5 to
d06b02b
Compare
…r issue #2392 Co-authored-by: DanielNoord <13665637+DanielNoord@users.noreply.github.com>
Copilot
AI
changed the title
Fix comment on opening
Fix opening-line comment moving to alias attribute line on wrapped imports
Mar 12, 2026
import ( line moving to alias attribute line
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 a
from … importwith an alias is too long for one line and the openingimport (line carries a comment (e.g.# type: ignore[attr-defined]), isort was incorrectly moving that comment inside the parentheses onto the alias line — breaking mypy and similar tools that require the comment on the statement's first physical line.Root cause
In
output.py, the alias loop passed allfrom_comments(opening-line comments fromcategorized_comments["straight"]) throughwith_comments()into the attribute import string, then calledwrap.line(). Becausewrap.line()places comments at the end of the last continuation line, the comment ended up inside the parentheses on the alias attribute line.Changes
isort/output.py— In the alias import loop, snapshotopening_line_comments(fromcategorized_comments["straight"]) before the attribute-levelspecific_comment(fromcategorized_comments["nested"]) is appended. Whenuse_parentheses=Trueand wrapping produces multiple lines, inject the opening-line comments onto the firstimport (line instead of embedding them in the attribute string. Attribute-line comments are unaffected. Added detailed inline documentation explaining the two comment categories and the placement strategy.tests/unit/test_regressions.py— Expanded the regression test to cover: attribute-line comment staying on the alias line, both comment types coexisting, non-alias opening-line comments, short imports collapsing to one line, and non-Black wrap modes (multi_line_output=3,use_parentheses=True).pyproject.toml/example_isort_formatting_plugin/pyproject.toml— Reverted unnecessaryblackminimum-version bumps back to their original upstream values (>=25.9.0and>=24.3.0respectively).Original prompt
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.