diff --git a/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java b/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java index 030fcfe3d7e5..1040c1620a23 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java @@ -477,9 +477,13 @@ public class PyFileImpl extends PsiFileBase implements PyFile, PyExpression { if (starImportSource != null) { starImportSource = PyUtil.turnDirIntoInit(starImportSource); if (starImportSource instanceof PyFile) { - final PsiElement result = ((PyFile)starImportSource).getElementNamed(name); + final PyFile file = (PyFile)starImportSource; + final PsiElement result = file.getElementNamed(name); if (result != null) { - return result; + final List dunderAll = file.getDunderAll(); + if ((dunderAll == null && !name.startsWith("_")) || (dunderAll != null && dunderAll.contains(name))) { + return result; + } } } } diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/UnusedImportBeforeStarDunderAll/a.py b/python/testData/inspections/PyUnresolvedReferencesInspection/UnusedImportBeforeStarDunderAll/a.py new file mode 100644 index 000000000000..6d444960ee9d --- /dev/null +++ b/python/testData/inspections/PyUnresolvedReferencesInspection/UnusedImportBeforeStarDunderAll/a.py @@ -0,0 +1,3 @@ +import b +from p1 import * +print(b) diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/UnusedImportBeforeStarDunderAll/b.py b/python/testData/inspections/PyUnresolvedReferencesInspection/UnusedImportBeforeStarDunderAll/b.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/UnusedImportBeforeStarDunderAll/p1/__init__.py b/python/testData/inspections/PyUnresolvedReferencesInspection/UnusedImportBeforeStarDunderAll/p1/__init__.py new file mode 100644 index 000000000000..31f7e1aa969c --- /dev/null +++ b/python/testData/inspections/PyUnresolvedReferencesInspection/UnusedImportBeforeStarDunderAll/p1/__init__.py @@ -0,0 +1 @@ +from p1.m1 import * diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/UnusedImportBeforeStarDunderAll/p1/m1.py b/python/testData/inspections/PyUnresolvedReferencesInspection/UnusedImportBeforeStarDunderAll/p1/m1.py new file mode 100644 index 000000000000..3f8018db03f2 --- /dev/null +++ b/python/testData/inspections/PyUnresolvedReferencesInspection/UnusedImportBeforeStarDunderAll/p1/m1.py @@ -0,0 +1,2 @@ +import b +__all__ = [] diff --git a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java index 176708421fcd..a0a2a1232b2e 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java @@ -376,6 +376,11 @@ public class PyUnresolvedReferencesInspectionTest extends PyInspectionTestCase { doMultiFileTest(); } + // PY-13585 + public void testUnusedImportBeforeStarDunderAll() { + doMultiFileTest(); + } + @NotNull @Override protected Class getInspectionClass() {