Skip to content

Place added future imports before code in append_only mode - #2676

Open
SemTiOne wants to merge 5 commits into
PyCQA:mainfrom
SemTiOne:issue/1970
Open

SemTiOne wants to merge 5 commits into
PyCQA:mainfrom
SemTiOne:issue/1970

Conversation

@SemTiOne

@SemTiOne SemTiOne commented Sep 26, 2026 •

Copy link
Copy Markdown

In append_only mode, added future imports landed in a later import section, producing a SyntaxError. They now take the early insertion path so they precede all code; files without imports stay untouched, and additions are skipped when frozen executable content precedes placement.

Closes #1970.

@codecov

codecov Bot commented Sep 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.45%. Comparing base (c85a44f) to head (81e2779).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2676   +/-   ##
=======================================
  Coverage   99.44%   99.45%           
=======================================
  Files          41       41           
  Lines        3225     3275   +50     
  Branches      692      702   +10     
=======================================
+ Hits         3207     3257   +50     
  Misses         11       11           
  Partials        7        7           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Early insertion can bypass opt-out directives and still place future imports after non-docstring string expressions.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Fixes future-import placement in append_only mode to avoid invalid late imports.

Changes:

  • Detects future additions and inserts them before executable code.
  • Preserves import-free and frozen-content files.
  • Adds regression coverage for issue #1970.
File Description
isort/​core.py Implements early future-import placement.
tests/​unit/​test_regressions.py Adds append-only regression tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread isort/core.py Outdated
Comment thread isort/core.py Outdated

This branch has not been deployed

No deployments
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.

add_imports + append_only inserts future import in illegal position

2 participants