Skip to content

Conversation

@danparizher
Copy link
Contributor

Summary

Fixes #20380

The fix changes the includes_import function in I002 to recognize equivalent imports based on bound name and qualified name rather than exact syntax matching.

This allows the function to correctly identify that from concurrent import futures satisfies the requirement for import concurrent.futures as futures.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 15, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dylwil3 dylwil3 self-requested a review September 15, 2025 13:28
@dylwil3
Copy link
Collaborator

dylwil3 commented Sep 19, 2025

Hmmm... I'm a bit conflicted here about whether I002 or PLR0402 should take precedence to resolve the infinite loop. Generally it feels like the more "customized" or "manually entered" choice should take precedence. Since a user enters required imports exactly as they'd like them to appear, whereas PLR0402 is a "general" rule, I'm tempted to say that it's PLR0402 that should be modified here.

Would it be possible to have PLR0402 skip if it's triggering on a required import instead? I would also be open to adding either a warning or a debug message explaining why the rule is being skipped in this case. (Probably a debug message since we wouldn't have a good way to override the warning).

What do you think?

@ntBre
Copy link
Contributor

ntBre commented Sep 19, 2025

I agree with Dylan, that seems closer to how we've handled the other I002 conflicts recently (#20327, #19413). Possibly we can even reuse the helper method you added in #19413 :)

Copy link
Collaborator

@dylwil3 dylwil3 left a comment

Choose a reason for hiding this comment

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

Thanks! One nit

@danparizher danparizher requested a review from dylwil3 September 22, 2025 19:46
@dylwil3 dylwil3 merged commit 589a674 into astral-sh:main Sep 25, 2025
59 of 60 checks passed
@dylwil3 dylwil3 added bug Something isn't working rule Implementing or modifying a lint rule labels Sep 25, 2025
@dylwil3 dylwil3 changed the title [isort] Fix infinite loop when checking equivalent imports (I002, PLR0402) [pylint] Exempt required imports from PLR0402 Sep 25, 2025
@danparizher danparizher deleted the fix-20380 branch September 25, 2025 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Infinite loop] I002 and PLR0402

3 participants