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

Python 3.12 def f[T: Generics](...) #4355

Closed
leaver2000 opened this issue May 9, 2024 · 2 comments
Closed

Python 3.12 def f[T: Generics](...) #4355

leaver2000 opened this issue May 9, 2024 · 2 comments
Labels
T: style What do we want Blackened code to look like?

Comments

@leaver2000
Copy link

Describe the style change

I have found the way black is handling inline generics ie def f[T](...) a little unexpected and less consistent with prior style.

Examples in the current Black style

[tool.black]
line-length = 119
target-version = ['py312']

Using non inline generics, the function is split along the arguments, this is expected.

T = TypeVar("T", bound=float)

def function_name(
    x1: datetime.datetime, x2: datetime.datetime, x3: datetime.datetime, dtype: type[T] = float
) -> None: ...

Using python312 inline generics, the function is split within the generics declaration. If you consider the git diff this is a much more substantial change vs the Desired style.

def function_name[
    T: float
](x1: datetime.datetime, x2: datetime.datetime, x3: datetime.datetime, dtype: type[T] = float) -> None: ...

Desired style

Retain the prior style and keep the inline generics inline with the function name

def function_name[T: float](
    x1: datetime.datetime, x2: datetime.datetime, x3: datetime.datetime, dtype: type[T] = float
) -> None: ...

Additional context

There appears to be a bug with trailing comma's?

def function_name[
    T: float
](x1: datetime.datetime, x2: datetime.datetime, x3: datetime.datetime, dtype: type[T] = float,) -> None: ...
# -------------------------------------------------------------------------------------------------^ what about my trailing comma
# would have expected....
def function_name[T: float](
    x1: datetime.datetime, 
    x2: datetime.datetime, 
    x3: datetime.datetime, 
    dtype: type[T] = float,
) -> None: ...
@leaver2000 leaver2000 added the T: style What do we want Blackened code to look like? label May 9, 2024
@leaver2000
Copy link
Author

# this is case that prompted the Issue
def get[
    T: np.generic
](
    name: Vars = "VIL", *, file: str = "latest", datetime: datetime.datetime | None = None, dtype: type[T] = np.float64
) -> Array[Nd[Y, X], T]:

# save 2 lines of code
def get[T: np.generic](
    name: Vars = "VIL", *, file: str = "latest", datetime: datetime.datetime | None = None, dtype: type[T] = np.float64
) -> Array[Nd[Y, X], T]:

@cobaltt7
Copy link
Contributor

cobaltt7 commented May 9, 2024

Duplicate of #4254

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

3 participants