mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
star import elements correctly resolve source of from import statement (PY-7204)
This commit is contained in:
@@ -7,7 +7,6 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.resolve.PyResolveUtil;
|
||||
import com.jetbrains.python.psi.resolve.ResolveImportUtil;
|
||||
import com.jetbrains.python.toolbox.ChainIterable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -29,8 +28,7 @@ public class PyStarImportElementImpl extends PyElementImpl implements PyStarImpo
|
||||
public Iterable<PyElement> iterateNames() {
|
||||
if (getParent() instanceof PyFromImportStatement) {
|
||||
PyFromImportStatement fromImportStatement = (PyFromImportStatement)getParent();
|
||||
final List<PsiElement> importedFiles =
|
||||
ResolveImportUtil.resolveFromImportStatementSource(fromImportStatement, fromImportStatement.getImportSourceQName());
|
||||
final List<PsiElement> importedFiles = fromImportStatement.resolveImportSourceCandidates();
|
||||
ChainIterable<PyElement> chain = new ChainIterable<PyElement>();
|
||||
for (PsiElement importedFile : new HashSet<PsiElement>(importedFiles)) { // resolver gives lots of duplicates
|
||||
final PsiElement source = PyUtil.turnDirIntoInit(importedFile);
|
||||
@@ -50,8 +48,7 @@ public class PyStarImportElementImpl extends PyElementImpl implements PyStarImpo
|
||||
}
|
||||
if (getParent() instanceof PyFromImportStatement) {
|
||||
PyFromImportStatement fromImportStatement = (PyFromImportStatement)getParent();
|
||||
final List<PsiElement> importedFiles =
|
||||
ResolveImportUtil.resolveFromImportStatementSource(fromImportStatement, fromImportStatement.getImportSourceQName());
|
||||
final List<PsiElement> importedFiles = fromImportStatement.resolveImportSourceCandidates();
|
||||
for (PsiElement importedFile : new HashSet<PsiElement>(importedFiles)) { // resolver gives lots of duplicates
|
||||
final PsiElement source = PyUtil.turnDirIntoInit(importedFile);
|
||||
if (source instanceof PyFile) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
def foo(): pass
|
||||
@@ -0,0 +1,3 @@
|
||||
from .. import *
|
||||
foo()
|
||||
#<ref>
|
||||
@@ -258,6 +258,16 @@ public class PyMultiFileResolveTest extends PyResolveTestCase {
|
||||
assertResolvesTo(PyFunction.class, "foo");
|
||||
}
|
||||
|
||||
public void testRelativePackageStarImport() { // PY-7204
|
||||
myTestFileName = "b/c/__init__.py";
|
||||
try {
|
||||
assertResolvesTo(PyFunction.class, "foo", "/src/b/__init__.py");
|
||||
}
|
||||
finally {
|
||||
myTestFileName = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void testCythonFromModuleCImport() {
|
||||
assertResolvesTo(CythonFunction.class, "foo");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user