astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
29.13k stars 948 forks source link

Rule SIM222 cause autofix error #7127

Open qarmin opened 10 months ago

qarmin commented 10 months ago

Ruff 0.0.287 (latest changes from main branch)

ruff  *.py --select SIM222 --no-cache --fix

file content(at least simple cpython script shows that this is valid python file):

def interpolate_nodes(
    data: "numpy array (n, 3)", mode: "'spline' or 'linear'", interval: float, *, direction: bool = 1
) -> "numpy array (n, 3)":
        return data

error

/home/rafal/test/tmp_folder/8279128.py:2:40: SIM222 Use `"spline"` instead of `"spline" or ...`
Found 1 error.

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/astral-sh/ruff/issues/new?title=%5BAutofix%20error%5D

...quoting the contents of `/home/rafal/test/tmp_folder/8279128.py`, the rule codes SIM222, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

python_compressed.zip

dhruvmanila commented 10 months ago

This seems to be caused because the surrounding quotes aren't being considered while generating the fix. So, "'spline' or 'linear'" is getting replaced with ""spline"".