Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Infinite loop] PLC0414 conflicts with I002 if a useless alias is required #14283

Closed
dscorbett opened this issue Nov 11, 2024 · 1 comment · Fixed by #14287
Closed

[Infinite loop] PLC0414 conflicts with I002 if a useless alias is required #14283

dscorbett opened this issue Nov 11, 2024 · 1 comment · Fixed by #14287
Labels
bug Something isn't working

Comments

@dscorbett
Copy link

useless-import-alias (PLC0414) conflicts with missing-required-import (I002) in Ruff 0.7.3 if the latter rule is configured to require an alias that the former rule considers useless.

$ echo 1 | ruff check --isolated --select I002,PLC0414 --config 'lint.isort.required-imports = ["import numpy as numpy"]' - --unsafe-fixes --fix

error: Failed to converge after 100 iterations.

This indicates a bug in Ruff. If you could open an issue at:

    https://github.com/astral-sh/ruff/issues/new?title=%5BInfinite%20loop%5D

...quoting the contents of `-`, the rule codes I002, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
import numpy
1
-:1:1: I002 Missing required import: `import numpy as numpy`
Found 101 errors (100 fixed, 1 remaining).
[*] 1 fixable with the --fix option.
@AlexWaygood AlexWaygood added bug Something isn't working help wanted Contributions especially welcome labels Nov 11, 2024
@dylwil3
Copy link
Collaborator

dylwil3 commented Nov 11, 2024

Thanks for this!

I think the simplest-to-implement fix is to let the user-specified config win and use I002 (that's what I do in the linked PR).

But it feels a little awkward because surely they wouldn't have meant to put that as the required import... Maybe in some future iteration a warning could be emitted in this case. At the moment, such a warning isn't quite precedented since it involves actually checking that the supplied config has a useless alias (as opposed to just reporting that two rules are known to always conflict, say). So I imagine some thought would have to go into it.

@dylwil3 dylwil3 removed the help wanted Contributions especially welcome label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants