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

Line wrapping on generic functions using the type parameter syntax #3929

Closed
PaulWassermann opened this issue Oct 6, 2023 · 4 comments
Closed
Labels
S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: style What do we want Blackened code to look like?

Comments

@PaulWassermann
Copy link

Describe the style change

The suggested style change regards the type parameter syntax introduced in Python 3.12.

When formatting lines too long, I think line-wrapping should occur in the arguments' parenthesis rather than in the type parameters' brackets.

Examples in the current Black style

This would work with any generic function using the new type parameter syntax with a long enough signature (longer than the line-length).

type SupportedDataTypes = float
type Tensor = list

def sum_backward[
T: SupportedDataTypes
](a: Tensor[T], grad: Tensor[T]) -> dict[Tensor[T], Tensor[T]]:
    ...

Desired style

I think this kind of line-wrapping, keeping the type parameters list on a single line when possible, should be preferred over what currently happens as it is more readable.

type SupportedDataTypes = float
type Tensor = list

def sum_backward[T: SupportedDataTypes](
    a: Tensor[T], 
    grad: Tensor[T]
) -> dict[Tensor[T], Tensor[T]]:
    ...
@PaulWassermann PaulWassermann added the T: style What do we want Blackened code to look like? label Oct 6, 2023
@hauntsaninja hauntsaninja added the S: accepted The changes in this design / enhancement issue have been accepted and can be implemented label Oct 6, 2023
@arre-ankit
Copy link

In which section we have to implement this syntax can you give more context about the files where we have to change the syntax ?

@kanugurajesh
Copy link

hi can you assign me this issue?

@JelleZijlstra
Copy link
Collaborator

We don't generally assign issues. However, PRs are welcome!

@hauntsaninja
Copy link
Collaborator

Duplicate of #4071 , PR welcome

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: style What do we want Blackened code to look like?
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants