Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatter undocumented deviation: extra unnecessary wrapping of arguments and extra parenthesis for long return types #14143

Open
Avasam opened this issue Nov 6, 2024 · 2 comments
Labels
formatter Related to the formatter

Comments

@Avasam
Copy link
Contributor

Avasam commented Nov 6, 2024

  • List of keywords you searched for before creating this issue. Write them down here so that others can find this issue more easily and help provide feedback.
    undocumented deviation black return

This is similar to #11791, but for return type annotations rather than variable annotations.

  • A minimal code snippet that reproduces the bug.

With preview = True:

Black:

class Polygon:
    def cut_section(self, line) -> tuple[
        RegularPolygon | Polygon | Triangle | Point | Point2D | Point3D | Segment2D | Segment3D | Segment | None,
        RegularPolygon | Polygon | Triangle | Point | Point2D | Point3D | Segment2D | Segment3D | Segment | None,
    ]: ...

Ruff:

class Polygon:
    def cut_section(
        self, line
    ) -> tuple[
        RegularPolygon | Polygon | Triangle | Point | Point2D | Point3D | Segment2D | Segment3D | Segment | None,
        RegularPolygon | Polygon | Triangle | Point | Point2D | Point3D | Segment2D | Segment3D | Segment | None,
    ]: ...

See microsoft/python-type-stubs@9eb6bb5 for a lot more examples

As an added note, with preview = False, I also get the following deviation:

Black:

def get_basis_vectors() -> tuple[
    tuple[Literal[1], Literal[0], Literal[0]],
    tuple[Literal[0], Literal[1], Literal[0]],
    tuple[Literal[0], Literal[0], Literal[1]],
]: ...

Ruff:

def get_basis_vectors() -> (
    tuple[
        tuple[Literal[1], Literal[0], Literal[0]],
        tuple[Literal[0], Literal[1], Literal[0]],
        tuple[Literal[0], Literal[0], Literal[1]],
    ]
): ...
  • The command you invoked (e.g., ruff /path/to/file.py --fix), ideally including the --isolated flag.
    ruff format

  • The current Ruff settings (any relevant sections from your pyproject.toml).

[tool.ruff]
line-length = 130
# Target oldest supported Python version
target-version = "py39"
preview = true
  • The current Ruff version (ruff --version).
    ruff 0.7.2
@MichaReiser
Copy link
Member

Thanks. We're aware of the deviation with preview=False but the way this gets formatted with preview=True is rather bad

class Polygon:
    def cut_section(
        self, line
    ) -> tuple[
        RegularPolygon
        | Polygon
        | Triangle
        | Point
        | Point2D
        | Point3D
        | Segment2D
        | Segment3D
        | Segment
        | None,
        RegularPolygon
        | Polygon
        | Triangle
        | Point
        | Point2D
        | Point3D
        | Segment2D
        | Segment3D
        | Segment
        | None,
    ]: ...

@MichaReiser
Copy link
Member

Interestingly, prettier does the exact same playground

mirecheck added a commit to ClusterLabs/pcs that referenced this issue Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants