mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-20864 Python control flow builder considers variable annotations
This commit is contained in:
@@ -164,6 +164,16 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
|
||||
myBuilder.checkPending(readWriteInstruction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyTypeDeclarationStatement(PyTypeDeclarationStatement node) {
|
||||
myBuilder.startNode(node);
|
||||
final PyAnnotation annotation = node.getAnnotation();
|
||||
if (annotation != null) {
|
||||
annotation.accept(this);
|
||||
}
|
||||
node.getTarget().accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyAssignmentStatement(final PyAssignmentStatement node) {
|
||||
myBuilder.startNode(node);
|
||||
@@ -171,6 +181,10 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
|
||||
if (value != null) {
|
||||
value.accept(this);
|
||||
}
|
||||
final PyAnnotation annotation = node.getAnnotation();
|
||||
if (annotation != null) {
|
||||
annotation.accept(this);
|
||||
}
|
||||
for (PyExpression expression : node.getRawTargets()) {
|
||||
expression.accept(this);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
x: int
|
||||
xs: List = []
|
||||
@@ -0,0 +1,8 @@
|
||||
0(1) element: null
|
||||
1(2) element: PyTypeDeclarationStatement
|
||||
2(3) READ ACCESS: int
|
||||
3(4) WRITE ACCESS: x
|
||||
4(5) element: PyAssignmentStatement
|
||||
5(6) READ ACCESS: List
|
||||
6(7) WRITE ACCESS: xs
|
||||
7() element: null
|
||||
@@ -0,0 +1,6 @@
|
||||
def f():
|
||||
class MyType:
|
||||
pass
|
||||
|
||||
xs: MyType = None
|
||||
<ref>
|
||||
@@ -0,0 +1,4 @@
|
||||
from typing import List
|
||||
|
||||
xs: List = []
|
||||
<ref>
|
||||
@@ -354,4 +354,15 @@ public class Py3ResolveTest extends PyResolveTestCase {
|
||||
public void testDunderClassInDeclarationInsideFunction() {
|
||||
assertUnresolved();
|
||||
}
|
||||
|
||||
// PY-20864
|
||||
public void testTopLevelVariableAnnotationFromTyping() {
|
||||
myFixture.copyDirectoryToProject("typing", "");
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON36, () -> assertResolvesTo(PyClass.class, "List"));
|
||||
}
|
||||
|
||||
// PY-20864
|
||||
public void testLocalVariableAnnotationWithInnerClass() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON36, () -> assertResolvesTo(PyClass.class, "MyType"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,6 +239,11 @@ public class PyControlFlowBuilderTest extends LightMarkedTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-20744, PY-20864
|
||||
public void testVariableAnnotations() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest);
|
||||
}
|
||||
|
||||
private void doTestFirstStatement() {
|
||||
final String testName = getTestName(false).toLowerCase();
|
||||
configureByFile(testName + ".py");
|
||||
|
||||
Reference in New Issue
Block a user