enforce required imports even with useless alias#14287
enforce required imports even with useless alias#14287dylwil3 merged 10 commits intoastral-sh:mainfrom
Conversation
|
Not so happy about the big diff in such a simple rule for an edge case... I welcome alternative suggestions! |
|
MichaReiser
left a comment
There was a problem hiding this comment.
Could you expand the PR summary with details about what was causing the infinite loop or panic? It would help me review this PR and possibly suggest alternatives.
|
Done! It also occurred to me that it might be better to keep the diagnostic but elide the fix for useless-import-alias. That would serve the purpose of warning the user that something was amiss, and they could override the warning by ignoring the rule. Edit: Made this change. I did not change the "Fix availability" or documentation because it seems like this is a very rare (nonexistent?) exception, but let me know what you think. |
|
Do you mind adding a dedicated test for this? Sorry! |
crates/ruff_linter/src/rules/pylint/rules/useless_import_alias.rs
Outdated
Show resolved
Hide resolved
Added! |
This PR handles a panic that occurs when applying unsafe fixes if a user inserts a required import (I002) that has a "useless alias" in it, like
import numpy as numpy, and also selects PLC0414 (useless-import-alias)In this case, the fixes alternate between adding the required import statement, then removing the alias, until the recursion limit is reached. See linked issue for an example.
Tests to confirm panic resolved:
Closes #14283