diff --git a/python/python-psi-impl/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java b/python/python-psi-impl/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java index fd1300baf317..0210edc77d8d 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java +++ b/python/python-psi-impl/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java @@ -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) { diff --git a/python/testData/codeInsight/controlflow/TypeAliasStatement.py b/python/testData/codeInsight/controlflow/TypeAliasStatement.py new file mode 100644 index 000000000000..10d4ec38d69b --- /dev/null +++ b/python/testData/codeInsight/controlflow/TypeAliasStatement.py @@ -0,0 +1 @@ +type myType = str \ No newline at end of file diff --git a/python/testData/codeInsight/controlflow/TypeAliasStatement.txt b/python/testData/codeInsight/controlflow/TypeAliasStatement.txt new file mode 100644 index 000000000000..4a8dcdf18167 --- /dev/null +++ b/python/testData/codeInsight/controlflow/TypeAliasStatement.txt @@ -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 \ No newline at end of file diff --git a/python/testData/codeInsight/controlflow/TypeAliasStatementWithTypeParameterList.py b/python/testData/codeInsight/controlflow/TypeAliasStatementWithTypeParameterList.py new file mode 100644 index 000000000000..545adad65c59 --- /dev/null +++ b/python/testData/codeInsight/controlflow/TypeAliasStatementWithTypeParameterList.py @@ -0,0 +1 @@ +type myType[T: str, U: int] = Union[T, U] \ No newline at end of file diff --git a/python/testData/codeInsight/controlflow/TypeAliasStatementWithTypeParameterList.txt b/python/testData/codeInsight/controlflow/TypeAliasStatementWithTypeParameterList.txt new file mode 100644 index 000000000000..83c0d790a166 --- /dev/null +++ b/python/testData/codeInsight/controlflow/TypeAliasStatementWithTypeParameterList.txt @@ -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 \ No newline at end of file diff --git a/python/testData/codeInsight/controlflow/TypeParameterListInClassDeclaration.py b/python/testData/codeInsight/controlflow/TypeParameterListInClassDeclaration.py new file mode 100644 index 000000000000..32359c9bc09a --- /dev/null +++ b/python/testData/codeInsight/controlflow/TypeParameterListInClassDeclaration.py @@ -0,0 +1,2 @@ +class Clazz[T, U](BaseClass[T]): + pass \ No newline at end of file diff --git a/python/testData/codeInsight/controlflow/TypeParameterListInClassDeclaration.txt b/python/testData/codeInsight/controlflow/TypeParameterListInClassDeclaration.txt new file mode 100644 index 000000000000..c6b3eaaaf698 --- /dev/null +++ b/python/testData/codeInsight/controlflow/TypeParameterListInClassDeclaration.txt @@ -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 \ No newline at end of file diff --git a/python/testData/codeInsight/controlflow/TypeParameterListInFunctionDeclaration.py b/python/testData/codeInsight/controlflow/TypeParameterListInFunctionDeclaration.py new file mode 100644 index 000000000000..fc7f0782ae42 --- /dev/null +++ b/python/testData/codeInsight/controlflow/TypeParameterListInFunctionDeclaration.py @@ -0,0 +1,2 @@ +def foo[T, U](a: T, b: U): + pass \ No newline at end of file diff --git a/python/testData/codeInsight/controlflow/TypeParameterListInFunctionDeclaration.txt b/python/testData/codeInsight/controlflow/TypeParameterListInFunctionDeclaration.txt new file mode 100644 index 000000000000..ad6ce0d09355 --- /dev/null +++ b/python/testData/codeInsight/controlflow/TypeParameterListInFunctionDeclaration.txt @@ -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 \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java b/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java index 94f703ecb8c1..68799f3d3344 100644 --- a/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java +++ b/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java @@ -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");