Skip to content

I002 inserts required imports before future imports #20674

@dscorbett

Description

@dscorbett

Summary

The fix for missing-required-import (I002) inserts required imports before future imports, which introduces a syntax error. Example:

$ cat >i002.py <<'# EOF'
from __future__ import annotations
# EOF

$ ruff --isolated check i002.py --select I002 --unsafe-fixes --fix --config 'lint.isort.required-imports = ["import this"]'
Found 1 error (1 fixed, 0 remaining).

$ cat i002.py
import this
from __future__ import annotations

$ python i002.py 2>&1 | tail -n 1
SyntaxError: from __future__ imports must occur at the beginning of the file

Version

ruff 0.13.2 (b0bdf03 2025-09-25)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions