diff --git a/python/python-common-tests/com/jetbrains/python/PythonCommonFormatterTest.java b/python/python-common-tests/com/jetbrains/python/PythonCommonFormatterTest.java index 3488b2800771..7a4b25683506 100644 --- a/python/python-common-tests/com/jetbrains/python/PythonCommonFormatterTest.java +++ b/python/python-common-tests/com/jetbrains/python/PythonCommonFormatterTest.java @@ -1361,4 +1361,9 @@ public abstract class PythonCommonFormatterTest extends PythonCommonTestCase { public void testAlignmentInMultilineTypeParameterListInClassDefinition() { doTest(); } + + // PY-77060 + public void testSpaceAfterStarInTypeParameterList() { + doTest(); + } } diff --git a/python/python-syntax-core/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java b/python/python-syntax-core/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java index aa0bfd865ddf..1d5a1b1b2824 100644 --- a/python/python-syntax-core/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java +++ b/python/python-syntax-core/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java @@ -137,6 +137,7 @@ public class PythonFormattingModelBuilder implements FormattingModelBuilder, Cus .aroundInside(ADDITIVE_OPERATIONS, BINARY_EXPRESSION).spaceIf(commonSettings.SPACE_AROUND_ADDITIVE_OPERATORS) .aroundInside(STAR_OPERATORS, STAR_PARAMETERS).none() .aroundInside(STAR_OPERATORS, STAR_PATTERNS).none() + .aroundInside(STAR_OPERATORS, TYPE_PARAMETER).none() .between(EXCEPT_KEYWORD, MULT).none() .between(PERC, TokenSet.create(PERC, IDENTIFIER, EXPRESSION_STATEMENT)).none() .around(MULTIPLICATIVE_OPERATIONS).spaceIf(commonSettings.SPACE_AROUND_MULTIPLICATIVE_OPERATORS) diff --git a/python/testData/formatter/spaceAfterStarInTypeParameterList.py b/python/testData/formatter/spaceAfterStarInTypeParameterList.py new file mode 100644 index 000000000000..051d1d7dd1e8 --- /dev/null +++ b/python/testData/formatter/spaceAfterStarInTypeParameterList.py @@ -0,0 +1,12 @@ +from typing import Callable + +type A[T, * Ts, ** P] = Callable[P, tuple[*Ts, T]] + + +def f[T, * Ts, ** P]() -> Callable[P, tuple[*Ts, T]]: + ... + + +class C[T, * Ts, ** P]: + def m(self) -> Callable[P, tuple[*Ts, T]]: + ... \ No newline at end of file diff --git a/python/testData/formatter/spaceAfterStarInTypeParameterList_after.py b/python/testData/formatter/spaceAfterStarInTypeParameterList_after.py new file mode 100644 index 000000000000..f0fa89280566 --- /dev/null +++ b/python/testData/formatter/spaceAfterStarInTypeParameterList_after.py @@ -0,0 +1,12 @@ +from typing import Callable + +type A[T, *Ts, **P] = Callable[P, tuple[*Ts, T]] + + +def f[T, *Ts, **P]() -> Callable[P, tuple[*Ts, T]]: + ... + + +class C[T, *Ts, **P]: + def m(self) -> Callable[P, tuple[*Ts, T]]: + ...