Skip to content

Unintentional formatter deviation: strange spacing around TypeAlias declarations #8188

@stinodego

Description

@stinodego

Reproducible example:

from typing import TypeAlias

MultiColSelector: TypeAlias = (
    "slice | range | list[int] | list[str] | list[bool] | Series"
)

black leaves this alone, while ruff formats it as follows:

- MultiColSelector: TypeAlias = (
-     "slice | range | list[int] | list[str] | list[bool] | Series"
- )
+ MultiColSelector: (
+     TypeAlias
+ ) = "slice | range | list[int] | list[str] | list[bool] | Series"

This looks like an undesirable change to me.

In our code base, I worked around this by rewriting the string as a Union of types.

Command: ruff format .
Formatter settings: None
Version: ruff 0.1.2

P.S.: Other than the two minor issues I just reported, the new ruff formatter is working excellently. It has improved formatting in quite a few cases. Thank you for the amazing work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    formatterRelated to the formatterneeds-decisionAwaiting a decision from a maintainer

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions