New type parameter syntax: parameters should be broken up before type parameters
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 41.8k
- Forks
- 2.9k
- Avg merge
- 5d 6h
- Merged PRs (30d)
- 9
Description
Describe the style change
In functions with the new type parameter syntax, the type parameter bracket should only be made multi-line if it itself does not fit on one line. (Sorry, this is best explained with an example; see below.)
Examples in the current Black style
def f[
T
](a_long_param_name: list[T] | tuple[T, ...], another_long_param_name: T) -> list[T]:
pass
def g[
T
](
a_long_param_name: list[T] | tuple[T, ...],
another_long_param_name: T,
a_boolean_flag: bool,
) -> list[T]:
pass
Desired style
def f[T](
a_long_param_name: list[T] | tuple[T, ...], another_long_param_name: T
) -> list[T]:
pass
def g[T](
a_long_param_name: list[T] | tuple[T, ...],
another_long_param_name: T,
a_boolean_flag: bool,
) -> list[T]:
pass
Additional context
Tested on latest commit: https://github.com/psf/black/commit/e1036119f264a846bb049fad8404df318bc2f455
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two Python examples from the issue with Black and trace the formatter entry point that handles function definitions with type parameters. The change is done when the examples match the desired style without changing unrelated formatting, and the relevant formatting checks pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100