mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
PY-42389 Delete annoying object inheritance
(cherry picked from commit 6db21da1efd2fdaba1e3dbc217bb619453a50cbc) IJ-MR-4788 GitOrigin-RevId: 7887f0ee01bc5d0e61e5279f8f5c20bb74696b9c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4aa56c1bf7
commit
331e8c02c7
@@ -66,8 +66,10 @@ public class CreateClassQuickFix implements LocalQuickFix {
|
||||
assert anchor != null;
|
||||
}
|
||||
|
||||
final boolean isPy3K = LanguageLevel.forElement(anchor).isPy3K();
|
||||
String superClass = isPy3K ? "" : "(object)";
|
||||
PyClass pyClass = PyElementGenerator.getInstance(project).createFromText(LanguageLevel.getDefault(), PyClass.class,
|
||||
"class " + myClassName + "(object):\n pass");
|
||||
"class " + myClassName + superClass + ":\n pass");
|
||||
if (anchor instanceof PyFile) {
|
||||
pyClass = (PyClass) anchor.add(pyClass);
|
||||
}
|
||||
@@ -76,7 +78,9 @@ public class CreateClassQuickFix implements LocalQuickFix {
|
||||
}
|
||||
pyClass = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(pyClass);
|
||||
final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(pyClass);
|
||||
builder.replaceElement(pyClass.getSuperClassExpressions() [0], "object");
|
||||
if (!isPy3K) {
|
||||
builder.replaceElement(pyClass.getSuperClassExpressions() [0], "object");
|
||||
}
|
||||
builder.replaceElement(pyClass.getStatementList(), PyNames.PASS);
|
||||
|
||||
PythonTemplateRunner.runTemplate(pyClass.getContainingFile(), builder);
|
||||
|
||||
3
python/testData/inspections/AddClassFixPython3.py
Normal file
3
python/testData/inspections/AddClassFixPython3.py
Normal file
@@ -0,0 +1,3 @@
|
||||
class XyzzyTest:
|
||||
def testSimple(self):
|
||||
c = <caret><error descr="Unresolved reference 'Xyzzy'">Xyzzy</error>()
|
||||
7
python/testData/inspections/AddClassFixPython3_after.py
Normal file
7
python/testData/inspections/AddClassFixPython3_after.py
Normal file
@@ -0,0 +1,7 @@
|
||||
class Xyzzy:
|
||||
pass
|
||||
|
||||
|
||||
class XyzzyTest:
|
||||
def testSimple(self):
|
||||
c = Xyzzy()
|
||||
@@ -1,4 +1,4 @@
|
||||
class MyClass(object):
|
||||
class MyClass:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -211,6 +211,12 @@ public class PyQuickFixTest extends PyTestCase {
|
||||
doInspectionTest("AddClass.py", PyUnresolvedReferencesInspection.class, "Create class 'Xyzzy'", true, true);
|
||||
}
|
||||
|
||||
// PY-42389
|
||||
public void testAddClassFixPython3() {
|
||||
runWithLanguageLevel(LanguageLevel.getLatest(), () ->
|
||||
doInspectionTest(PyUnresolvedReferencesInspection.class, "Create class 'Xyzzy'", true, true));
|
||||
}
|
||||
|
||||
// PY-21204
|
||||
public void testAddClassFromTypeComment() {
|
||||
doInspectionTest(PyUnresolvedReferencesInspection.class, "Create class 'MyClass'", true, true);
|
||||
|
||||
Reference in New Issue
Block a user