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

Ugly line splitting for 3.10+ union type hints #3649

Closed
NiklasRosenstein opened this issue Apr 16, 2023 · 1 comment
Closed

Ugly line splitting for 3.10+ union type hints #3649

NiklasRosenstein opened this issue Apr 16, 2023 · 1 comment
Labels
T: bug Something isn't working

Comments

@NiklasRosenstein
Copy link

Describe the bug

I've run across an issue where the following code gets formatted not very nicely. This particular snippet should IMO already satisfy Black with line_length=120.

def main(
    client: AppRole,
    role_name: str = Option(..., help="The name of the role to generate a secret ID for", metavar="ROLE_NAME"),
    secret_id: str | None = Option(
        None,
        help="A custom secret ID to use. If not specified, one will be generated.",
        metavar="SECRET_ID",
    ),
    metadata: str | None = Option(None, help="JSON-formatted metadata to associate with the secret ID", metavar="JSON"),
    metadata_file: Path | None = Option(
        None,
        help="A file containing JSON-formatted metadata to associate with the secret ID",
    ),
) -> None:
    """Generate a new secret ID for an approle."""

But running Black 23.3.0 over it gives an ugly split before two of the three | None parts:

def main(
    client: AppRole,
    role_name: str = Option(..., help="The name of the role to generate a secret ID for", metavar="ROLE_NAME"),
    secret_id: str
    | None = Option(
        None,
        help="A custom secret ID to use. If not specified, one will be generated.",
        metavar="SECRET_ID",
    ),
    metadata: str | None = Option(None, help="JSON-formatted metadata to associate with the secret ID", metavar="JSON"),
    metadata_file: Path
    | None = Option(
        None,
        help="A file containing JSON-formatted metadata to associate with the secret ID",
    ),
) -> None:
    """Generate a new secret ID for an approle."""

To Reproduce

Run black example.py --line-length 120 on the above snippet.

Expected behavior

Black should not split str | None before the |. There appears to be no reason to do so as the line is not too long.

Environment

  • Black's version: 22.3.0
  • OS and Python version: Python 3.8.10

Additional context

@NiklasRosenstein NiklasRosenstein added the T: bug Something isn't working label Apr 16, 2023
@yilei
Copy link
Contributor

yilei commented Apr 26, 2023

This is a duplicate of #2316

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants