mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 06:39:38 +07:00
PY-75760 - allow reference to another ParamSpec be default of ParamSpec type, simplify logic of generic substitution for TypeVars
GitOrigin-RevId: 9ca5d7f3529513c683424d2f4d6da75f40d58e4a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d29d55476e
commit
783bbde096
@@ -5644,6 +5644,60 @@ public class PyTypingTest extends PyTestCase {
|
||||
""");
|
||||
}
|
||||
|
||||
// PY-71002
|
||||
public void testParamSpecDefaultTypeRefersToAnotherParamSpecNewStyle() {
|
||||
doTest("Clazz[[str], [str], [str]]", """
|
||||
class Clazz[**P1, **P2 = P1, **P3 = P2]: ...
|
||||
expr = Clazz[[str]]()
|
||||
""");
|
||||
}
|
||||
|
||||
// PY-71002
|
||||
public void testParamSpecDefaultTypeRefersToAnotherParamSpecOldStyle() {
|
||||
doTest("Clazz[[str], [str], [str]]", """
|
||||
from typing import Generic, ParamSpec
|
||||
P1 = ParamSpec("P1")
|
||||
P2 = ParamSpec("P2", default=P1)
|
||||
P3 = ParamSpec("P3", default=P2)
|
||||
class Clazz(Generic[P1, P2, P3]): ...
|
||||
expr = Clazz[[str]]()
|
||||
""");
|
||||
}
|
||||
|
||||
// PY-71002
|
||||
public void testParamSpecDefaultTypeRefersToAnotherParamSpecOldStyleNoExplicit() {
|
||||
doTest("Clazz[[str], [str], [bool, bool], [bool, bool]]", """
|
||||
from typing import Generic, ParamSpec
|
||||
P1 = ParamSpec("P1", default=[str])
|
||||
P2 = ParamSpec("P2", default=P1)
|
||||
P3 = ParamSpec("P3", default=[bool, bool])
|
||||
P4 = ParamSpec("P4", default=P3)
|
||||
class Clazz(Generic[P1, P2, P3, P4]): ...
|
||||
expr = Clazz()
|
||||
""");
|
||||
}
|
||||
|
||||
// PY-71002
|
||||
public void testParamSpecWithDefaultInConstructor() {
|
||||
doTest("(int, str, str) -> None | None", """
|
||||
from typing import Generic, ParamSpec, Callable
|
||||
P = ParamSpec("P", default=[int, str, str])
|
||||
class ClassA(Generic[P]):
|
||||
def __init__(self, x: Callable[P, None] = None) -> None:
|
||||
self.x = x
|
||||
...
|
||||
expr = ClassA().x
|
||||
""");
|
||||
}
|
||||
|
||||
// PY-71002
|
||||
public void testParamSpecDefaultTypeRefersToAnotherParamSpecWithEllipsis() {
|
||||
doTest("Clazz[Any, [float], [float]]", """
|
||||
class Clazz[**P1, **P2 = P1, **P3 = P2]: ...
|
||||
expr = Clazz[..., [float]]()
|
||||
""");
|
||||
}
|
||||
|
||||
public void testDataclassTransformConstructorSignature() {
|
||||
doTestExpressionUnderCaret("(id: int, name: str) -> MyClass", """
|
||||
from typing import dataclass_transform
|
||||
|
||||
Reference in New Issue
Block a user