mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 17:20:55 +07:00
PY-61877, PY-61878 PEP 695 Type Parameter Syntax: Control flow for type parameters and type aliases
GitOrigin-RevId: 2db381cbb97891296bae09e48c17b46eefa57a04
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1c5b0c5ac3
commit
65cc3ddfd0
@@ -88,6 +88,7 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
|
||||
public void visitPyFunction(final @NotNull PyFunction node) {
|
||||
// Create node and stop here
|
||||
myBuilder.startNode(node);
|
||||
|
||||
visitParameterListExpressions(node.getParameterList());
|
||||
visitDecorators(node.getDecoratorList());
|
||||
final PyAnnotation annotation = node.getAnnotation();
|
||||
@@ -132,6 +133,7 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
|
||||
public void visitPyClass(final @NotNull PyClass node) {
|
||||
// Create node and stop here
|
||||
myBuilder.startNode(node);
|
||||
|
||||
for (PsiElement element : node.getSuperClassExpressions()) {
|
||||
element.accept(this);
|
||||
}
|
||||
@@ -1026,6 +1028,20 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
|
||||
if (target != null) target.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyTypeAliasStatement(@NotNull PyTypeAliasStatement node) {
|
||||
myBuilder.startNode(node);
|
||||
|
||||
PyExpression typeExpression = node.getTypeExpression();
|
||||
if (typeExpression != null) {
|
||||
typeExpression.accept(this);
|
||||
}
|
||||
|
||||
final ReadWriteInstruction instruction = ReadWriteInstruction.write(myBuilder, node, node.getName());
|
||||
myBuilder.addNode(instruction);
|
||||
myBuilder.checkPending(instruction);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static CallTypeKind getCalleeNodeType(@Nullable PyExpression callee) {
|
||||
if (callee instanceof PyReferenceExpression expression) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
type myType = str
|
||||
@@ -0,0 +1,5 @@
|
||||
0(1) element: null
|
||||
1(2) element: PyTypeAliasStatement
|
||||
2(3) READ ACCESS: str
|
||||
3(4) WRITE ACCESS: myType
|
||||
4() element: null
|
||||
@@ -0,0 +1 @@
|
||||
type myType[T: str, U: int] = Union[T, U]
|
||||
@@ -0,0 +1,12 @@
|
||||
0(1) element: null
|
||||
1(2) element: PyTypeParameter
|
||||
2(3) WRITE ACCESS: T
|
||||
3(4) READ ACCESS: str
|
||||
4(5) element: PyTypeParameter
|
||||
5(6) WRITE ACCESS: U
|
||||
6(7) READ ACCESS: int
|
||||
7(8) element: PySubscriptionExpression
|
||||
8(9) READ ACCESS: Union
|
||||
9(10) READ ACCESS: T
|
||||
10(11) READ ACCESS: U
|
||||
11() element: null
|
||||
@@ -0,0 +1,2 @@
|
||||
class Clazz[T, U](BaseClass[T]):
|
||||
pass
|
||||
@@ -0,0 +1,9 @@
|
||||
0(1) element: null
|
||||
1(2) element: PyTypeParameter
|
||||
2(3) WRITE ACCESS: T
|
||||
3(4) element: PyTypeParameter
|
||||
4(5) WRITE ACCESS: U
|
||||
5(6) element: PySubscriptionExpression
|
||||
6(7) READ ACCESS: BaseClass
|
||||
7(8) READ ACCESS: T
|
||||
8() element: null
|
||||
@@ -0,0 +1,2 @@
|
||||
def foo[T, U](a: T, b: U):
|
||||
pass
|
||||
@@ -0,0 +1,8 @@
|
||||
0(1) element: null
|
||||
1(2) element: PyTypeParameter
|
||||
2(3) WRITE ACCESS: T
|
||||
3(4) element: PyTypeParameter
|
||||
4(5) WRITE ACCESS: U
|
||||
5(6) WRITE ACCESS: a
|
||||
6(7) WRITE ACCESS: b
|
||||
7() element: null
|
||||
@@ -521,6 +521,26 @@ public class PyControlFlowBuilderTest extends LightMarkedTestCase {
|
||||
// doTest();
|
||||
//}
|
||||
|
||||
// PY-61878
|
||||
public void testTypeAliasStatement() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-61878
|
||||
public void testTypeAliasStatementWithTypeParameterList() {
|
||||
doTestFirstStatement();
|
||||
}
|
||||
|
||||
// PY-61877
|
||||
public void testTypeParameterListInFunctionDeclaration() {
|
||||
doTestFirstStatement();
|
||||
}
|
||||
|
||||
// PY-61877
|
||||
public void testTypeParameterListInClassDeclaration() {
|
||||
doTestFirstStatement();
|
||||
}
|
||||
|
||||
private void doTestFirstStatement() {
|
||||
final String testName = getTestName(false);
|
||||
configureByFile(testName + ".py");
|
||||
|
||||
Reference in New Issue
Block a user