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
In ruff 99a755f, the following snippet causes the autofix RUF005 to introduce a syntax error:
f"{a() + ['b']}"
$ ./ruff --no-cache --select RUF005 --fix code.py
error: Autofix introduced a syntax error. Reverting all changes.
This indicates a bug in `ruff`. If you could open an issue at:
https://github.com/charliermarsh/ruff/issues/new?title=%5BAutofix%20error%5D
...quoting the contents of `code.py`, the rule codes RUF005, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!
code.py:1:4: RUF005 Consider `[*a(), "b"]` instead of concatenation
Found 1 error.
I think we have a few options for addressing this class of issues:
Always skip autofix within f-strings (easiest).
Skip autofix within f-strings on a rule-by-rule basis. This is fine, but we're going to have to omit most rules. Even RUF005 only fails because we go through unparse_expr, which changes the quote style of the 'b' to "b".
Improve unparse_expr to enforce specific quote styles within f-strings. This would require tracking the quote style of the f-string, threading it down to unparse_expr, and respecting it throughout the unparse logic.
One note to add here is that most of these will valid syntax with PEP 701 implemented, currently targeted for python 3.12, i.e. we could very ambitiously allow autofixes in f-strings for projects with minimum python version 3.12.
In ruff 99a755f, the following snippet causes the autofix RUF005 to introduce a syntax error:
f"{a() + ['b']}"
This was originally discovered in https://github.com/Mojino01/hugging_face/blob/3dae0d7b4fb8d7e9383b893e4e1799191bb2ab7b/src/transformers/pipelines/base.py#L1181
The text was updated successfully, but these errors were encountered: