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: parenthesize_long_type_hints preview style #8894

Closed
Tracked by #8678
MichaReiser opened this issue Nov 29, 2023 · 3 comments
Closed
Tracked by #8678

Formatter: parenthesize_long_type_hints preview style #8894

MichaReiser opened this issue Nov 29, 2023 · 3 comments
Assignees
Labels
formatter Related to the formatter preview Related to preview mode features

Comments

@MichaReiser
Copy link
Member

Implement Black's parenthesize_long_type_hints as a preview style in Ruff.

def foo(
    i: int,
    x: Loooooooooooooooooooooooong
    | Looooooooooooooooong
    | Looooooooooooooooooooong
    | Looooooong,
    *,
    s: str,
) -> None:
    pass

# Formats now to 

def foo(
    i: int,
    x: (
        Loooooooooooooooooooooooong
        | Looooooooooooooooong
        | Looooooooooooooooooooong
        | Looooooong
    ),
    *,
    s: str,
) -> None:
    pass

This seems to be similar to what Ruff used to have but we reverted in #8233. We should investigate why Black isn't breaking the list on the left for

tags: List[str] = [],  # noqa: B006 - ignored by automatic migration, but should be fixed

Which people found ugly. Maybe it's because of #6975?

@MichaReiser MichaReiser added formatter Related to the formatter preview Related to preview mode features labels Nov 29, 2023
@MichaReiser MichaReiser added this to the Formatter: Stable milestone Nov 29, 2023
@jakkdl
Copy link

jakkdl commented Dec 6, 2023

heya, author of the PRs that added the feature in black. Lemme know if you encounter anything weird or wonder something about my implementation choices.

@charliermarsh
Copy link
Member

Thanks @jakkdl that's very kind of you :)

@MichaReiser
Copy link
Member Author

We've implemented the changes for parenthesizing type hints in annotated assignments but are holding off on implementing the proposed layout for type hints in parameters. See psf/black#4123 for the rational.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter preview Related to preview mode features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants