diff --git a/python/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java b/python/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java
index b6286650f5f2..478725344be9 100644
--- a/python/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java
+++ b/python/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java
@@ -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) {
diff --git a/python/testData/codeInsight/controlflow/import.py b/python/testData/codeInsight/controlflow/import.py
index cc8a44a46009..ede0b5d3ffe3 100644
--- a/python/testData/codeInsight/controlflow/import.py
+++ b/python/testData/codeInsight/controlflow/import.py
@@ -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
diff --git a/python/testData/codeInsight/controlflow/import.txt b/python/testData/codeInsight/controlflow/import.txt
index b15eee7ad48a..e357a8fd4b52 100644
--- a/python/testData/codeInsight/controlflow/import.txt
+++ b/python/testData/codeInsight/controlflow/import.txt
@@ -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
\ No newline at end of file
diff --git a/python/testData/inspections/PyUnboundLocalVariableInspection/expected.xml b/python/testData/inspections/PyUnboundLocalVariableInspection/expected.xml
index c095eb859828..97f9c54bd2e6 100644
--- a/python/testData/inspections/PyUnboundLocalVariableInspection/expected.xml
+++ b/python/testData/inspections/PyUnboundLocalVariableInspection/expected.xml
@@ -35,4 +35,9 @@
132
"Local variable 'g' might be referenced before assignment"
+
+ test.py
+ 140
+ "Local variable 'os' might be referenced before assignment"
+
\ No newline at end of file