Fixed bug in CFG for qualified imports (PY-3665)

This commit is contained in:
Andrey Vlasovskikh
2011-05-25 16:51:33 +04:00
parent 3536f5f3ea
commit 5cd4809c1a
4 changed files with 33 additions and 6 deletions
@@ -15,6 +15,7 @@ import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.impl.PyAugAssignmentStatementNavigator;
import com.jetbrains.python.psi.impl.PyConstantExpressionEvaluator;
import com.jetbrains.python.psi.impl.PyImportStatementNavigator;
import com.jetbrains.python.psi.impl.PyQualifiedName;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -187,9 +188,9 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
instruction = ReadWriteInstruction.write(myBuilder, importElement, asNameElement.getName());
}
else {
final PyReferenceExpression importReference = importElement.getImportReference();
if (importReference != null) {
instruction = ReadWriteInstruction.write(myBuilder, importElement, importReference.getReferencedName());
final PyQualifiedName name = importElement.getImportedQName();
if (name != null && name.getComponentCount() > 0) {
instruction = ReadWriteInstruction.write(myBuilder, importElement, name.getComponents().get(0));
}
}
if (instruction != null) {
@@ -1,2 +1,9 @@
foo = 123
import foo
import a
import b.c
import d.e.f
import g as h
import i.j as k
from l import m
from n import o as p
from q.r import s as t
@@ -2,5 +2,19 @@
1(2) element: PyAssignmentStatement
2(3) WRITE ACCESS: foo
3(4) element: PyImportStatement
4(5) WRITE ACCESS: foo
5() element: null
4(5) WRITE ACCESS: a
5(6) element: PyImportStatement
6(7) WRITE ACCESS: b
7(8) element: PyImportStatement
8(9) WRITE ACCESS: d
9(10) element: PyImportStatement
10(11) WRITE ACCESS: h
11(12) element: PyImportStatement
12(13) WRITE ACCESS: k
13(14) element: PyFromImportStatement
14(15) WRITE ACCESS: m
15(16) element: PyFromImportStatement
16(17) WRITE ACCESS: p
17(18) element: PyFromImportStatement
18(19) WRITE ACCESS: t
19() element: null
@@ -35,4 +35,9 @@
<line>132</line>
<description>"Local variable 'g' might be referenced before assignment"</description>
</problem>
<problem>
<file>test.py</file>
<line>140</line>
<description>"Local variable 'os' might be referenced before assignment"</description>
</problem>
</problems>