astral-sh / ruff

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

Rule D202 cause autofix error #7172

Open qarmin opened 1 year ago

qarmin commented 1 year ago

Ruff 0.0.287 (latest changes from main branch)

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

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

def check_assert_called_once_with(logical_line, filename):
    """Try to detect unintended calls of nonexistent mock methods like:
    """\

    if 'ovn_octavia_provider/tests/' in filename:
            return

error

/home/rafal/test/tmp_folder/154_IDX_0_RAND_100719810512166459037745.py:2:5: D202 No blank lines allowed after function docstring (found 1)
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/154_IDX_0_RAND_100719810512166459037745.py`, the rule codes D202, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

python_compressed.zip

dhruvmanila commented 1 year ago

It's the line continuation character which is creating this issue. There are 2 visible newlines but the first one is escaped so there's actually only 1 which gets removed. So, the token stream would produce a string and then directly the if token which is an invalid syntax.