Black: Disable formatting for certain expressions only.

Created on 8 Apr 2019  路  3Comments  路  Source: psf/black

Hi there,

yapf has a feature which I'm missing a lot in black. In yapf you can disable formatting for single expressions, e.g.:

def bar():

    query, values = sql( # yapf: disable
        SELECT, "*",
        FROM, records,
        WHERE,
            records.intcol.eq(1), OR,
            records.jsonbcol.foo[0].eq(2),
        )

    # Here yapf is enabled again.
    # ...

    d = { # yapf: disable
        "name": "peter",
        "item1": "foo", "item2": "bar", "item3": "baz",
    }

    # Here yapf is enabled again.
    # ...

This helps a lot in various situations.

Any love for this? :)

design

Most helpful comment

Do you know about the # fmt: off / # fmt: on feature?

All 3 comments

Do you know about the # fmt: off / # fmt: on feature?

Yes :)

I would really love this, primarily for the following case:

import pdb; pdb.set_trace()  # fmt: off-line

Update, I see https://github.com/psf/black/issues/790 addresses my specific use case:

__import__("pdb").set_trace()  # FIXME
Was this page helpful?
0 / 5 - 0 ratings