Skip to content

Conversation

ntBre
Copy link
Contributor

@ntBre ntBre commented Jun 23, 2025

Summary

This PR resolves the easiest part of #18502 by adding an autofix that just adds
from __future__ import annotations at the top of the file, in the same way
as FA102, which already has an identical unsafe fix.

Test Plan

Existing snapshots, updated to add the fixes.

ntBre added 2 commits June 23, 2025 16:09
Summary
--

This PR resolves the easiest part of #18502 by adding an autofix that just adds
`from __future__ import annotations` at the top of the file. We couldn't use any
of the usual, existing `Importer` methods because the import must be at the very
beginning of the file, so I factored out `Importer::add_import_at_start_of_file`
from `Importer::add_import`.

I think this is technically an unsafe fix because it changes a lot of behavior,
but that's also the point of the rule, so I made it a safe fix for now. I'm
happy to change it to unsafe, though.

I also expected the fix only to be available sometimes, but `add_import` and
`add_import_at_start_of_file` are actually infallible.

Test Plan
--

Existing snapshots, updated to add the fixes.
@ntBre ntBre added the fixes Related to suggested fixes for violations label Jun 23, 2025
@ntBre ntBre requested a review from MichaReiser June 23, 2025 20:12
@ntBre ntBre marked this pull request as ready for review June 23, 2025 20:21
Copy link
Contributor

github-actions bot commented Jun 23, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre ntBre marked this pull request as draft June 23, 2025 20:34
@ntBre ntBre merged commit 7783cea into main Jun 25, 2025
35 checks passed
@ntBre ntBre deleted the brent/fa100-autofix branch June 25, 2025 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixes Related to suggested fixes for violations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants