You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was running ruff on Sympy, applied the experimental ruff PERF rules and hit a bug. When running it on this file at this commit: https://github.com/sympy/sympy/blob/b3d060459054d0cbd925a06fc7719a6f3b498a91/sympy/polys/galoistools.py#L1812 it recommends removing the list cast, but one can't do that because the inner while loop modifies the list that it is iterating over leading to an error. I tried to extract a smaller reproducer out of this, but was unable to.
version used: ruff 0.2.0 ruff --select PERF --show-source --fix file.py leads to the invalid fix.
sympy/polys/galoistools.py:1812:18: PERF101 [*] Do not cast an iterable to `list` before iterating over it
|
1811 | for k in range(1, len(V)):
1812 | for f in list(factors):
| ^^^^^^^^^^^^^ PERF101
1813 | s = K.zero
|
= help: Remove `list()` cast
worse, this is a safe fix and it makes the file invalid.
The text was updated successfully, but these errors were encountered:
## Summary
This PR ensures that if a list `x` is modified within a `for` loop, we
avoid flagging `list(x)` as unnecessary. Previously, we only detected
calls to exactly `.append`, and they couldn't be nested within other
statements.
Closes#9925.
nkxxll
pushed a commit
to nkxxll/ruff
that referenced
this issue
Mar 10, 2024
…#9955)
## Summary
This PR ensures that if a list `x` is modified within a `for` loop, we
avoid flagging `list(x)` as unnecessary. Previously, we only detected
calls to exactly `.append`, and they couldn't be nested within other
statements.
Closesastral-sh#9925.
I was running ruff on Sympy, applied the experimental ruff PERF rules and hit a bug. When running it on this file at this commit:
https://github.com/sympy/sympy/blob/b3d060459054d0cbd925a06fc7719a6f3b498a91/sympy/polys/galoistools.py#L1812 it recommends removing the list cast, but one can't do that because the inner while loop modifies the list that it is iterating over leading to an error. I tried to extract a smaller reproducer out of this, but was unable to.
version used: ruff 0.2.0
ruff --select PERF --show-source --fix file.py
leads to the invalid fix.worse, this is a safe fix and it makes the file invalid.
The text was updated successfully, but these errors were encountered: