PY-20864 Python control flow builder considers variable annotations

This commit is contained in:
Mikhail Golubev
2016-09-26 09:09:23 +03:00
parent 654ac30429
commit 8d8c3fb930
7 changed files with 50 additions and 0 deletions
@@ -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");