diff --git a/python/src/com/jetbrains/python/codeInsight/imports/PythonReferenceImporter.java b/python/src/com/jetbrains/python/codeInsight/imports/PythonReferenceImporter.java index dd61fddb6454..26b92595b6ce 100644 --- a/python/src/com/jetbrains/python/codeInsight/imports/PythonReferenceImporter.java +++ b/python/src/com/jetbrains/python/codeInsight/imports/PythonReferenceImporter.java @@ -112,7 +112,7 @@ public class PythonReferenceImporter implements ReferenceImporter { if (isTopLevel(symbol)) { // we only want top-level symbols PsiFileSystemItem srcfile = symbol instanceof PsiFileSystemItem ? ((PsiFileSystemItem)symbol).getParent() : symbol.getContainingFile(); if (srcfile != null && srcfile != existing_import_file && srcfile != node.getContainingFile()) { - PyQualifiedName import_path = ResolveImportUtil.findCanonicalImportPath(symbol, node); + PyQualifiedName import_path = ResolveImportUtil.findCanonicalImportPath(srcfile, node); if (import_path != null && !seen_file_names.contains(import_path.toString())) { // a new, valid hit fix.addImport(symbol, srcfile, import_path, proposeAsName(node.getContainingFile(), ref_text, import_path)); diff --git a/python/testData/inspections/importFromModule/foo/__init__.py b/python/testData/inspections/importFromModule/foo/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/python/testData/inspections/importFromModule/foo/bar.py b/python/testData/inspections/importFromModule/foo/bar.py new file mode 100644 index 000000000000..f4d60fbb0289 --- /dev/null +++ b/python/testData/inspections/importFromModule/foo/bar.py @@ -0,0 +1 @@ +baz.quux() \ No newline at end of file diff --git a/python/testData/inspections/importFromModule/foo/bar_after.py b/python/testData/inspections/importFromModule/foo/bar_after.py new file mode 100644 index 000000000000..49fe9fa735e3 --- /dev/null +++ b/python/testData/inspections/importFromModule/foo/bar_after.py @@ -0,0 +1,3 @@ +from importFromModule.foo import baz + +baz.quux() \ No newline at end of file diff --git a/python/testData/inspections/importFromModule/foo/baz.py b/python/testData/inspections/importFromModule/foo/baz.py new file mode 100644 index 000000000000..c23aa322c214 --- /dev/null +++ b/python/testData/inspections/importFromModule/foo/baz.py @@ -0,0 +1 @@ +def quux(): pass \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyQuickFixTest.java b/python/testSrc/com/jetbrains/python/PyQuickFixTest.java index b865bb6c38c1..4ed71475b2c9 100644 --- a/python/testSrc/com/jetbrains/python/PyQuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/PyQuickFixTest.java @@ -31,6 +31,11 @@ public class PyQuickFixTest extends PyLightFixtureTestCase { doInspectionTest(new String[] { "AddImportDocComment.py", "ImportTarget.py" }, PyUnresolvedReferencesInspection.class, PyBundle.message("ACT.NAME.use.import"), true, true); } + public void testImportFromModule() { + doInspectionTest(new String[] { "importFromModule/foo/bar.py", "importFromModule/foo/baz.py", "importFromModule/foo/__init__.py" }, + PyUnresolvedReferencesInspection.class, PyBundle.message("ACT.NAME.use.import"), true, true); + } + public void testQualifyByImport() { final PyCodeInsightSettings settings = PyCodeInsightSettings.getInstance(); boolean oldPreferFrom = settings.PREFER_FROM_IMPORT;