don't try to append any import elements to a star import (PY-6302)

This commit is contained in:
Dmitry Jemerov
2012-04-25 19:41:11 +02:00
parent 2b64b8d52e
commit 0a7e0a6063
5 changed files with 28 additions and 1 deletions
@@ -191,6 +191,9 @@ public class AddImportHelper {
if (target != null && existingImport.getTextRange().getStartOffset() > target.getTextRange().getStartOffset()) {
continue;
}
if (existingImport.isStarImport()) {
continue;
}
final PyQualifiedName qName = existingImport.getImportSourceQName();
if (qName != null && qName.toString().equals(path)) {
for (PyImportElement el : existingImport.getImportElements()) {
@@ -220,7 +223,7 @@ public class AddImportHelper {
else if (useQualified) {
addImportStatement(file, path, null, priority);
final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(file.getProject());
element.replace(elementGenerator.createExpressionFromText(qName + "." + target.getName()));
element.replace(elementGenerator.createExpressionFromText(LanguageLevel.forElement(target), qName + "." + target.getName()));
}
else {
addImportFrom(file, null, path, target.getName(), null, priority);
@@ -0,0 +1,4 @@
from target import *
<warning descr="Unresolved reference 'xyzzy'">x<caret>yzzy</warning>
shazam()
@@ -0,0 +1,5 @@
from target import *
from target import xyzzy
x<caret>yzzy
shazam()
@@ -0,0 +1,4 @@
__all__ = ['shazam']
def shazam(): pass
def xyzzy(): pass
@@ -36,6 +36,17 @@ public class PyQuickFixTest extends PyTestCase {
PyUnresolvedReferencesInspection.class, PyBundle.message("ACT.NAME.use.import"), true, true);
}
public void testImportFromModuleStar() { // PY-6302
myFixture.enableInspections(PyUnresolvedReferencesInspection.class);
myFixture.copyDirectoryToProject("importFromModuleStar", "");
myFixture.configureFromTempProjectFile("source.py");
myFixture.checkHighlighting(true, false, false);
final IntentionAction intentionAction = myFixture.findSingleIntention(PyBundle.message("ACT.NAME.use.import"));
assertNotNull(intentionAction);
myFixture.launchAction(intentionAction);
myFixture.checkResultByFile("importFromModuleStar/source_after.py");
}
public void testQualifyByImport() {
final PyCodeInsightSettings settings = PyCodeInsightSettings.getInstance();
boolean oldPreferFrom = settings.PREFER_FROM_IMPORT;