You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.38%. Comparing base (1745766) to head (120f60f). ⚠️ Report is 1 commits behind head on main.
Doesn't this address it? I thought it did but might need to double check. I think the original error is just attributing an underlying problem (not merging/grouping plain from imports) to unrelated configuration options.
By grouping plain imports we necessarily need to handle comments on the import statements we are grouping.
The tests fail because this is a breaking change and both django and habitat don't conform to this style. Note that this is the style that ruff enforces by default.
The reason will be displayed to describe this comment to others. Learn more.
@DanielNoord sorry, I double-checked and the core behavior looks correct: the original multiline reproducer groups all plain imports into one statement, keeps the aliased import separate, and is idempotent with and without --fss.
I would propose to close this:
Add the exact long multiline #2455 reproducer as a regression test.
Add the reverse alias-before-plain case and assert idempotency.
Keep the Django and Habitat skips, but clarify that they reflect incompatibility with the intentional breaking style.
Preserve alias order when combining wildcard imports
isort/output.py:713
With combine_star=True, from foo import *\nfrom foo import b\nfrom foo import b as c\nfrom foo import e as f\n emits e as f before b as c; a second run reverses them. The plain-and-aliased name b is deferred, while alias-only e is emitted immediately. Include only_show_as_imports in this branch so both aliases are emitted in order when the wildcard replaces the plain imports. Add a two-pass regression for this case.
Preserve type-ignore directives when grouping imports
isort/output.py:746
The compatibility check treats type: ignore as an ordinary explanatory comment. For example, from x import a # explanation\nfrom x import b # type: ignore[attr-defined]\n becomes from x import a, b # explanation; type: ignore[attr-defined]. Python no longer recognizes the type-ignore directive, so the suppression for b is lost. Preserve directive ownership and keep these imports separate when comments are incompatible. Add a regression covering this directive and repeated formatting.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Comment handling can broaden diagnostic suppression and produce output that changes on subsequent formatting passes.
No open issues 🎉
3 previously missed issues
In code that hasn't changed since last review
Preserve pragma suppression scope when grouping imports
isort/output.py:760
Pragma checks only run when the incoming import has a comment, so grouping can extend a suppression to previously unannotated imports. For example, from x import a # type: ignore[attr-defined] followed by from x import b becomes from x import a, b # type: ignore[attr-defined]. An unannotated a followed by b # noqa: F401 also merges, suppressing diagnostics for both names. Preserve the original suppression scope when grouping, with regression tests for uncommented imports on either side of a pragma-bearing import.
Ignore comment boundaries when removing comments
isort/output.py:760
These comment boundaries are enforced even with ignore_comments=True, although formatting then removes the comments. For from x import a # explanation followed by from x import b # noqa: F401, the first pass produces two uncommented statements and the second merges them into from x import a, b. Skip comment-based boundaries when removing comments so the first pass produces stable output.
Clear opening comments after formatting import groups
isort/output.py:810
opening_line_comments stays nonempty after the group owning those comments has been formatted. With profile="black", line_length=40, from x import a, b # explanation followed by from x import c # type: ignore[attr-defined] therefore moves the second comment onto an opening-parenthesis line. On the next pass, that comment is parsed as a module-level comment and merged with the explanation, changing its scope and breaking idempotence. Clear the opening-comment state after formatting the group that owns it.
…orts
With combine_as_imports, the comments of an import that has an alias
are kept under module.__combined_as__ and added to the comments of the
grouped statement in _with_from_imports_for_module. Since the grouping
change of PyCQA#2614, preserve_comments_on_statement_line only looks at the
module's own opening-line comments, so a wrapped import of a single
aliased name went through wrap.line() and its comment, often a
type: ignore, moved to the alias line, where mypy no longer applies it.
That is the case PyCQA#1839 reported, now only with combine_as_imports.
Count the combined comments as statement comments too.
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
build-wheelsLabel to apply to pull requests to trigger a build of the wheels
3 participants
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.
Closes #2455
Code is still to be improved. I'm also unsure about some of the changes to expected test output...