Skip to content

fix: sort_reexports should respect isort: skip comment (#2569)#2570

Open
muhamedfazalps wants to merge 2 commits into
PyCQA:mainfrom
muhamedfazalps:fix/sort-reexports-skip
Open

fix: sort_reexports should respect isort: skip comment (#2569)#2570
muhamedfazalps wants to merge 2 commits into
PyCQA:mainfrom
muhamedfazalps:fix/sort-reexports-skip

Conversation

@muhamedfazalps

Copy link
Copy Markdown

Fixes #2569

When sort_reexports is enabled, all assignments with # isort: skip comments were still being sorted because the skip comment was not checked before processing.

Comment thread isort/core.py
code_sorting_indent = line[: -len(line.lstrip())]
not_imports = True
elif config.sort_reexports and stripped_line.startswith("__all__"):
elif config.sort_reexports and stripped_line.startswith("__all__") and "isort: skip" not in stripped_line:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a test to reproduce the issue?

@BD103

BD103 commented Jun 30, 2026

Copy link
Copy Markdown

Thanks for working on this! I tested this PR on my original reproduction in #2569 and it no longer errors!

When sort_reexports is enabled, __all__ assignments with
# isort: skip were still being sorted. Added check for
isort: skip comment before processing re-exports.

Signed-off-by: Muhamed Fazal PS <fazaleee123cr7@gmail.com>
@staticdev staticdev force-pushed the fix/sort-reexports-skip branch from 790b63f to ef581df Compare July 2, 2026 18:37
@staticdev

Copy link
Copy Markdown
Collaborator

@BD103 I will merge it as soon as we have test coverage.

Add 3 tests covering:
- Non-literal __all__ with isort: skip (the reported issue)
- Literal __all__ with isort: skip
- Literal __all__ without skip still sorts

All tests pass. Maintainer requested test coverage before merge.
@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.32%. Comparing base (01adac1) to head (b5c3f0c).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2570      +/-   ##
==========================================
+ Coverage   99.16%   99.32%   +0.16%     
==========================================
  Files          41       41              
  Lines        3101     3111      +10     
  Branches      671      674       +3     
==========================================
+ Hits         3075     3090      +15     
+ Misses         14       11       -3     
+ Partials       12       10       -2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DanielNoord DanielNoord left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you fix the failing CI check? Deepsource can be ignored. Otherwise this LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sort_reexports does not respect isort: skip

4 participants