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

Improve function declaration wrapping when it contains generic type definitions #4553

Merged
Prev Previous commit
Next Next commit
cosmetic fixes
hauntsaninja committed Jan 24, 2025
commit 22d78217632a32cecb8a6a1d06fcc9e1a40ad22d
8 changes: 4 additions & 4 deletions src/black/linegen.py
Original file line number Diff line number Diff line change
@@ -808,9 +808,9 @@ def left_hand_split(
if leaf.type in OPENING_BRACKETS:
if (
Preview.generic_type_def_wrapping in mode
and leaf.type
== token.LSQB # '[' indicates a generic type declaration
and not _should_generic_type_def_in_func_be_splitted(leaf, mode)
# '[' indicates a generic type declaration
and leaf.type == token.LSQB
and not _should_split_generic_type_def(leaf, mode)
):
continue

@@ -834,7 +834,7 @@ def left_hand_split(
yield result


def _should_generic_type_def_in_func_be_splitted(
def _should_split_generic_type_def(
opening_square_bracket: Leaf, mode: Mode
) -> bool:
"""
8 changes: 4 additions & 4 deletions tests/data/cases/generics_wrapping.py
Original file line number Diff line number Diff line change
@@ -3,14 +3,14 @@ def func[T](a: T, b: T,) -> T:
return a


def with_magic_trailling_comma[
def with_magic_trailing_comma[
T,
B,
](a: T, b: T,) -> T:
return a


def without_magic_trailling_comma[
def without_magic_trailing_comma[
T,
B
](a: T, b: T,) -> T:
@@ -45,14 +45,14 @@ def func[T](
return a


def with_magic_trailling_comma[
def with_magic_trailing_comma[
T,
B,
](a: T, b: T,) -> T:
return a


def without_magic_trailling_comma[T, B](
def without_magic_trailing_comma[T, B](
a: T,
b: T,
) -> T: