Repository navigation
[flake8-tidy-imports] Prevent fix loop between TID254 and TID255 - #28262
Merged
Merged
Conversation
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
|
charliermarsh
approved these changes
Sep 3, 2026
charliermarsh
left a comment
Member
There was a problem hiding this comment.
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.)
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
I initially wanted to avoid emitting
TID254when an import that was required to be lazy wasimmediately resolved. However, it became clear that that approach was much more complicated while
reviewing #26027. This PR implements the easier fix of skipping
TID255for imports that arerequired 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
TID255diagnostic and only suppressing the fix. Idon'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