We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Describe the style change
Black 22.8.0 makes typing hints in Python ≥ 3.10 harder to read by line breaking on the pipe (type union) operator without any apparent reason.
Examples in the current Black style
I'm writing a FastAPI application:
from fastapi import APIRouter, Query router = APIRouter(prefix="/black", tags=["black"]) @router.get("/foo") async def foo( param1: str | None = Query( default=None, title="A parameter", description="A longer description of the parameter." ), param2: str | None = Query( default=None, title="Another parameter", description="A longer description of the other parameter.", ), ) -> str: """Docstring goes here.""" return f"{param1=} {param2=}"
Desired style
from fastapi import APIRouter, Query router = APIRouter(prefix="/pfx", tags=["pfx"]) @router.get("/foo") async def foo( param1: str | None = Query( default=None, title="A parameter", description="A longer description of the parameter." ), param2: str | None = Query( default=None, title="Another parameter", description="A longer description of the other parameter.", ), ) -> str: """Docstring goes here.""" return f"{param1=} {param2=}"
Additional context
If you remove the | None part of the typing hint, a linebreak is not inserted by Black.
| None
str | None for types is syntax introduced in Python 3.10. Python 3.9 and earlier had Union[str, None] which is not susceptible to the problem.
str | None
Union[str, None]
The text was updated successfully, but these errors were encountered:
This seems similar to #3296 which is a duplicate of #2316.
Sorry, something went wrong.
Thanks, I'd tried to search for existing issues but came up blank. Closing as dupe.
No branches or pull requests
Describe the style change
Black 22.8.0 makes typing hints in Python ≥ 3.10 harder to read by line breaking on the pipe (type union) operator without any apparent reason.
Examples in the current Black style
I'm writing a FastAPI application:
Desired style
Additional context
If you remove the
| None
part of the typing hint, a linebreak is not inserted by Black.str | None
for types is syntax introduced in Python 3.10. Python 3.9 and earlier hadUnion[str, None]
which is not susceptible to the problem.The text was updated successfully, but these errors were encountered: