-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Wrapping lines of a function signature that uses the new python 3.12 generic type parameter syntax #4071
Copy link
Copy link
Closed
Labels
F: linebreakHow should we split up lines?How should we split up lines?S: acceptedThe changes in this design / enhancement issue have been accepted and can be implementedThe changes in this design / enhancement issue have been accepted and can be implementedT: styleWhat do we want Blackened code to look like?What do we want Blackened code to look like?
Description
Context:
- When a function has many parameters, it's more readable when on multiple lines, enforcing black to wrap lines adding a comma after the last parameter.
- See https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#how-black-wraps-lines
def func(a: int, b: int) -> int:
return a + b
def func(
a: int,
b: int,
) -> int:
return a + bpython 3.12 new feature:
- https://docs.python.org/3/whatsnew/3.12.html#summary-release-highlights
- A generic function can now have type parameters used by the static type checker.
- See PEP 695, type parameter syntax and the type statement
- See https://peps.python.org/pep-0695/#summary-examples
def func[T](a: T, b: T) -> T:
return aExample in the current Black style:
Enforcing black to wrap lines gives the ugly:
def func[
T
](a: T, b: T,) -> T:
return aDesired style:
def func[T](
a: T,
b: T,
) -> T:
return a + bAdditional context
python==3.12
black==23.11.0
Windows==11
VScode==1.84.2
VScode extension! Black Formatter==v2023.6.0
Credits:
Thank you for your great tool.
Patrick, Paris, France.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
F: linebreakHow should we split up lines?How should we split up lines?S: acceptedThe changes in this design / enhancement issue have been accepted and can be implementedThe changes in this design / enhancement issue have been accepted and can be implementedT: styleWhat do we want Blackened code to look like?What do we want Blackened code to look like?