mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-30 02:09:59 +07:00
Implicitly imported package members are already processed in PyModuleType instead of PyFile (PY-10819)
This commit is contained in:
@@ -97,28 +97,11 @@ public class PyFileImpl extends PsiFileBase implements PyFile, PyExpression {
|
||||
addImportElementDeclaration(importElement, localDeclarations, ambiguousDeclarations);
|
||||
}
|
||||
}
|
||||
if (PyNames.INIT_DOT_PY.equals(getName())) {
|
||||
final PyQualifiedName qName = fromImportStatement.getImportSourceQName();
|
||||
if (qName != null && !localDeclarations.containsKey(qName.toString())) {
|
||||
localDeclarations.put(qName.getLastComponent(), fromImportStatement);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (child instanceof PyImportStatement) {
|
||||
final PyImportStatement importStatement = (PyImportStatement)child;
|
||||
for (PyImportElement importElement : importStatement.getImportElements()) {
|
||||
addImportElementDeclaration(importElement, localDeclarations, ambiguousDeclarations);
|
||||
if (PyNames.INIT_DOT_PY.equals(getName())) {
|
||||
final PyQualifiedName qName = importElement.getImportedQName();
|
||||
final PsiDirectory containingDirectory = getContainingDirectory();
|
||||
if (qName != null && qName.getComponentCount() > 1 && containingDirectory != null) {
|
||||
String parentPackage = containingDirectory.getName();
|
||||
final List<String> components = qName.getComponents();
|
||||
if (components.get(components.size() - 2).equals(parentPackage)) {
|
||||
localDeclarations.put(components.get(components.size()-1), importElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (child instanceof NameDefiner) {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
from p1 import foo
|
||||
|
||||
foo()
|
||||
#<ref>
|
||||
@@ -0,0 +1 @@
|
||||
from p1.foo import foo
|
||||
@@ -0,0 +1,2 @@
|
||||
def foo():
|
||||
pass
|
||||
@@ -0,0 +1,4 @@
|
||||
from p1 import foo
|
||||
|
||||
foo()
|
||||
#<ref>
|
||||
@@ -0,0 +1 @@
|
||||
from p1.foo import *
|
||||
@@ -0,0 +1,2 @@
|
||||
def foo():
|
||||
pass
|
||||
@@ -437,6 +437,14 @@ public class PyMultiFileResolveTest extends PyResolveTestCase {
|
||||
assertResolvesTo(PyTargetExpression.class, "foo");
|
||||
}
|
||||
|
||||
// PY-10819
|
||||
public void testFromPackageModuleImportElementNamedAsModule() {
|
||||
assertResolvesTo(PyFunction.class, "foo");
|
||||
final PsiManager psiManager = myFixture.getPsiManager();
|
||||
assertNotParsed((PyFile)psiManager.findFile(myFixture.findFileInTempDir("p1/__init__.py")));
|
||||
assertNotParsed((PyFile)psiManager.findFile(myFixture.findFileInTempDir("p1/foo.py")));
|
||||
}
|
||||
|
||||
private void prepareTestDirectory() {
|
||||
final String testName = getTestName(true);
|
||||
myFixture.copyDirectoryToProject(testName, "");
|
||||
|
||||
@@ -286,22 +286,6 @@ public class PyStubsTest extends PyTestCase {
|
||||
assertNotParsed(file);
|
||||
}
|
||||
|
||||
public void testInitPyExportsSubpackageImport() {
|
||||
myFixture.copyDirectoryToProject("../resolve/multiFile/importPackageIntoSelf", "");
|
||||
final PyFileImpl initPy = (PyFileImpl) myFixture.getPsiManager().findFile(myFixture.findFileInTempDir("mygame/__init__.py"));
|
||||
final PsiElement element = initPy.findExportedName("display");
|
||||
assertTrue(element instanceof PyImportElement);
|
||||
assertNotParsed(initPy);
|
||||
}
|
||||
|
||||
public void testInitPyExportsSubpackageFromImport() {
|
||||
myFixture.copyDirectoryToProject("../resolve/multiFile/fromImportPackageIntoSelf", "");
|
||||
final PyFileImpl initPy = (PyFileImpl) myFixture.getPsiManager().findFile(myFixture.findFileInTempDir("mygame/__init__.py"));
|
||||
final PsiElement element = initPy.findExportedName("display");
|
||||
assertInstanceOf(element, PyFile.class);
|
||||
assertNotParsed(initPy);
|
||||
}
|
||||
|
||||
public void testVariableIndex() {
|
||||
getTestFile();
|
||||
GlobalSearchScope scope = GlobalSearchScope.allScope(myFixture.getProject());
|
||||
|
||||
Reference in New Issue
Block a user