Skip to content

[flake8-tidy-imports] Prevent fix loop between TID254 and TID255 - #28262

Merged
ntBre merged 2 commits into
mainfrom
brent/fix-lazy-import-conflict
Sep 3, 2026
Merged

ntBre merged 2 commits into
mainfrom
brent/fix-lazy-import-conflict

Conversation

@ntBre

@ntBre ntBre commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

I initially wanted to avoid emitting TID254 when an import that was required to be lazy was
immediately resolved. However, it became clear that that approach was much more complicated while
reviewing #26027. This PR implements the easier fix of skipping TID255 for imports that are
required to be lazy by the user's configuration, even if those imports are immediately resolved. I
think this is also a sensible route.

A close alternative would be still emitting the TID255 diagnostic and only suppressing the fix. I
don't really feel strongly one way or the other. The diagnostic is possibly still helpful to let you
know that you're defeating your desired lazy import, but especially in an example like the one from
the issue, it would be pretty hard to avoid. This would just require moving the new check down a few
lines to implement, though.

Fixes #25418

Test Plan

New mdtest based on the issue

Summary
--

I initially wanted to avoid emitting `TID254` when an import that was required to be lazy was
immediately resolved. However, it became clear that that approach was much more complicated while
reviewing #26027. This PR implements the easier fix of skipping `TID255` for imports that are
required to be lazy by the user's configuration, even if those imports are immediately resolved. I
think this is also a sensible route.

A close alternative would be still emitting the `TID255` diagnostic and only suppressing the fix. I
don't really feel strongly one way or the other. The diagnostic is possibly still helpful to let you
know that you're defeating your desired lazy import, but especially in an example like the one from
the issue, it would be pretty hard to avoid. This would just require moving the new check down a few
lines to implement, though.

Fixes #25418

Test Plan
--

New mdtest based on the issue
@ntBre ntBre added bug An issue describing something that isn't working, or a PR that fixes a bug rule Implementing or modifying a lint rule preview Related to preview-mode features python315 Related to Python 3.15 labels Sep 2, 2026
@astral-sh-bot

astral-sh-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

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 ready for review September 2, 2026 21:43
@ntBre
ntBre requested a review from charliermarsh September 2, 2026 21:43
@ntBre ntBre mentioned this pull request Sep 2, 2026
27 of 32 tasks

@charliermarsh charliermarsh 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.

This makes sense.

I initially wanted to avoid emitting TID254 when an import that was required to be lazy was immediately resolved.

(I agree that this would be a bit better, but that this is the right tradeoff.)

@ntBre
ntBre merged commit 3f7a54d into main Sep 3, 2026
49 checks passed
@ntBre
ntBre deleted the brent/fix-lazy-import-conflict branch September 3, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue describing something that isn't working, or a PR that fixes a bug preview Related to preview-mode features python315 Related to Python 3.15 rule Implementing or modifying a lint rule

Projects

None yet

2 participants