mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-14365 Do not show object and __Classobj in AutoImportQuickFix
Excluded them from the list of base classes that may be shown in description and list items in the quick fix UI.
This commit is contained in:
@@ -25,10 +25,14 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileSystemItem;
|
||||
import com.intellij.psi.util.QualifiedName;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An immutable holder of information for one auto-import candidate.
|
||||
* <p/>
|
||||
@@ -131,15 +135,15 @@ class ImportCandidateHolder implements Comparable<ImportCandidateHolder> {
|
||||
sb.append(((PyFunction)myImportable).getParameterList().getPresentableText(false));
|
||||
}
|
||||
else if (myImportable instanceof PyClass) {
|
||||
final PyClass[] supers = ((PyClass)myImportable).getSuperClasses();
|
||||
if (supers.length > 0) {
|
||||
final List<String> supers = ContainerUtil.mapNotNull(((PyClass)myImportable).getSuperClasses(), new Function<PyClass, String>() {
|
||||
@Override
|
||||
public String fun(PyClass cls) {
|
||||
return PyUtil.isObjectClass(cls) ? null : cls.getName();
|
||||
}
|
||||
});
|
||||
if (!supers.isEmpty()) {
|
||||
sb.append("(");
|
||||
// ", ".join(x.getName() for x in getSuperClasses())
|
||||
final String[] superNames = new String[supers.length];
|
||||
for (int i = 0; i < supers.length; i += 1) {
|
||||
superNames[i] = supers[i].getName();
|
||||
}
|
||||
sb.append(StringUtil.join(superNames, ", "));
|
||||
StringUtil.join(supers, ", ", sb);
|
||||
sb.append(")");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<error descr="Unresolved reference 'MyOldStyleClass'">MyOldStyleCl<caret>ass</error>
|
||||
@@ -0,0 +1,2 @@
|
||||
class MyOldStyleClass:
|
||||
pass
|
||||
@@ -50,6 +50,16 @@ public class PyQuickFixTest extends PyTestCase {
|
||||
PyUnresolvedReferencesInspection.class, "Import 'importFromModule.foo.baz'", true, true);
|
||||
}
|
||||
|
||||
// PY-14365
|
||||
public void testObjectBaseIsNotShownInAutoImportQuickfix() {
|
||||
myFixture.copyDirectoryToProject("objectBaseIsNotShownInAutoImportQuickfix", "");
|
||||
myFixture.configureByFile("main.py");
|
||||
myFixture.enableInspections(PyUnresolvedReferencesInspection.class);
|
||||
final IntentionAction intention = myFixture.findSingleIntention("Import");
|
||||
assertNotNull(intention);
|
||||
assertEquals("Import 'module.MyOldStyleClass'", intention.getText());
|
||||
}
|
||||
|
||||
public void testImportFromModuleStar() { // PY-6302
|
||||
myFixture.enableInspections(PyUnresolvedReferencesInspection.class);
|
||||
myFixture.copyDirectoryToProject("importFromModuleStar", "");
|
||||
|
||||
Reference in New Issue
Block a user