-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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] Failed to Converge After 100 Iterations When Fixing Imports (e.g., I001, F401, F811) #15182
Comments
That's not quite what's happening here. Ruff can sort the imports without any issue:
It can also remove the unused imports without issue:
The problem is in F811, which only allows for one fix to be applied per iteration, so each import requires its own iteration. |
I think this is sort of the cause: #11173 |
Hey @charliermarsh , thanks for looking to this one! I can confirm like you said on latest origin/main both I001, F401 work ok
but when trying just
As I mentioned earlier, when I tried similar code listings with heavy imports in the past using isort, the execution was quite fast. I also just realized that I forgot to share the pyproject.toml. Apologies for that! However, it seems this issue is fairly easy to reproduce with a simple Ruff one-liner. |
This sounds related to #14563 |
Yeah, it's highly related. In the past, I used to prioritize commands = [
"isort -q -rc -sp config/.isort.cfg",
"autoflake --remove-all-unused-imports --ignore-init-module-imports --in-place",
"black --config config/.black",
"flake8 --config=config/.flake8",
] You mentioned something about the order in the other thread. Now I'm wondering—ideally, the order of the rules shouldn't affect the overall execution time, right? Anyway, I'm glad you all are aware of this one. It's a nasty issue, especially when refactoring large codebases after applying automatic patching or similar tasks. You'd expect Ps. Btw, I probably shouldn't have included the 'feature wish' of making |
Consider this snippet:
mcve.py
When I try to fix the script for the first time with ruff:
As you can see, not only it doesn’t converge quickly enough but it doesn't provide the optimal output in the first pass. For example:
Execution time: 5.506 s
.I've tested with more complex scripts having these type of imports and I’ve observed execution times around ~30s without proper convergence.
Interestingly, if I run the command a second time, it converges properly and successfully fixes the file, leaving an empty output as expected.
Previously, I used isort to handle similar import sorting tasks, and it worked flawlessly. Isort was quick and effective no matter how heavy the imports were, formatting files without breaking a sweat. It’s quite surprising to see ruff struggling with this particular case.
I’ve also tested this against the latest version of
origin/main
.Btw, this is kind of offtopic but I noticed that
uv --version
command provides really helpful information, such as:I was wondering, would it be possible to include similar version information with the commit hash in Ruff? This would be incredibly helpful for tasks like bisecting or checking out specific hashes for testing purposes or opening issues.
Thanks in advance!
The text was updated successfully, but these errors were encountered: