How to prevent Black from adding a line break after union(`|`) type annotations

128 Views Asked by At

Black formats my code to:

operators: list[str]
| None = Query(
    default=None,
    description="operators",
),

but I want it to be formatted as:

operators: list[str] | None = Query(
    default=None,
    description="operators",
),

Black formatter adds a line break after the | None part in the code above. I'm curious why a line break occurs after the | operator. I'd like to know how to control or prevent such line breaks after the | operator in Black.

Additionally, I'm wondering if there are any options to change or rewrite the code so that Black doesn't introduce line breaks after the | operator in type hints.

I checked the black docs, but couldn't find it.

0

There are 0 best solutions below