google / yapf

A formatter for Python files
Apache License 2.0
13.75k stars 887 forks source link

YAPF breaks noqa for multiline strings in brackets #524

Open adamtheturtle opened 6 years ago

adamtheturtle commented 6 years ago

It is possible to make a file with a # noqa comment which disables a flake8 error, which YAPF will move so that the comment is no longer useful.

Install dependencies:

$ pip install yapf flake8

$ pip freeze
flake8==3.5.0
mccabe==0.6.1
pycodestyle==2.3.1
pyflakes==1.6.0
yapf==0.20.1

Create example.py with the following contents:

foo = (
    """\
    Short
    Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long
    Short
    """  # noqa: E501
)

There is no flake8 error because the E501 error is ignored:

$ flake8 example.py
$

Run YAPF, this changes the file:

$ yapf --in-place example.py
$ cat example.py
foo = (
    """\
    Short
    Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long
    Short
    """

    # noqa: E501
)

flake8 now does not ignore the error:

$ flake8 example.py 
example.py:4:80: E501 line too long (88 > 79 characters)
michaelfresco commented 6 years ago

I my code snippet this also happens

qry = session.query(
    Ping.host_id,
    func.max(Ping.latency).label("max_score"), func.sum(Ping.latency).label("total_score"),  # noqa: E501
)