diff --git a/python/src/com/jetbrains/python/inspections/unresolvedReference/PyUnresolvedReferencesInspection.java b/python/src/com/jetbrains/python/inspections/unresolvedReference/PyUnresolvedReferencesInspection.java index 37ff6c0afc0b..5f6961bad551 100644 --- a/python/src/com/jetbrains/python/inspections/unresolvedReference/PyUnresolvedReferencesInspection.java +++ b/python/src/com/jetbrains/python/inspections/unresolvedReference/PyUnresolvedReferencesInspection.java @@ -383,16 +383,7 @@ public class PyUnresolvedReferencesInspection extends PyInspection { } private static boolean isContainingFileImportAllowed(PyElement node, PsiFile target) { - // import resolving to containing file is allowed when we're importing from the current package and the containing file - // is __init__.py (PY-5265) - final boolean insideFromImport = PsiTreeUtil.getParentOfType(node, PyFromImportStatement.class) != null; - if (!insideFromImport) { - return false; - } - if (PyImportStatementNavigator.getImportStatementByElement(node) != null) { - return false; - } - return target.getName().equals(PyNames.INIT_DOT_PY); + return PyImportStatementNavigator.getImportStatementByElement(node) == null && target.getName().equals(PyNames.INIT_DOT_PY); } private void processReferenceInImportGuard(PyElement node, PyExceptPart guard) { diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/ImportToContainingFileInPackage/p1/__init__.py b/python/testData/inspections/PyUnresolvedReferencesInspection/ImportToContainingFileInPackage/p1/__init__.py new file mode 100644 index 000000000000..f72078f20b5c --- /dev/null +++ b/python/testData/inspections/PyUnresolvedReferencesInspection/ImportToContainingFileInPackage/p1/__init__.py @@ -0,0 +1 @@ +import p1.m1 diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/ImportToContainingFileInPackage/p1/m1.py b/python/testData/inspections/PyUnresolvedReferencesInspection/ImportToContainingFileInPackage/p1/m1.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java index 35097e0ea6c3..5367412c133e 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java @@ -435,6 +435,11 @@ public class PyUnresolvedReferencesInspectionTest extends PyInspectionTestCase { doTest(); } + // PY-14398 + public void testImportToContainingFileInPackage() { + doMultiFileTest("p1/__init__.py"); + } + @NotNull @Override protected Class getInspectionClass() {