fixed PY-12500 Instance attribute defined outside init: generate python 3 super call without arguments for python 3 interpreters

This commit is contained in:
Ekaterina Tuzova
2014-04-09 15:54:53 +04:00
parent 10e91a9319
commit 5baf0cd4f8
5 changed files with 42 additions and 4 deletions
@@ -194,11 +194,14 @@ public class AddFieldQuickFix implements LocalQuickFix {
if (cls.isNewStyleClass()) {
// form the super() call
sb.append("super(");
sb.append(cls.getName());
if (!LanguageLevel.forElement(cls).isPy3K()) {
sb.append(cls.getName());
// NOTE: assume that we have at least the first param
String self_name = params[0].getName();
sb.append(", ").append(self_name).append(").").append(PyNames.INIT).append("(");
// NOTE: assume that we have at least the first param
String self_name = params[0].getName();
sb.append(", ").append(self_name);
}
sb.append(").").append(PyNames.INIT).append("(");
}
else {
sb.append(ancestorClass.getName());
@@ -0,0 +1,7 @@
class Base():
def __init__(self):
self.param = 2
class Child(Base):
def f(self):
sel<caret>f.my = 1
@@ -0,0 +1,11 @@
class Base():
def __init__(self):
self.param = 2
class Child(Base):
def __init__(self):
super().__init__()
self.my = 1
def f(self):
pass
@@ -17,6 +17,8 @@ package com.jetbrains.python;
import com.intellij.codeInsight.intention.IntentionAction;
import com.jetbrains.python.fixtures.PyTestCase;
import com.jetbrains.python.psi.LanguageLevel;
import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -32,6 +34,16 @@ public abstract class PyQuickFixTestCase extends PyTestCase {
return PythonTestUtil.getTestDataPath() + "/quickFixes/" + getClass().getSimpleName();
}
protected void doQuickFixTest(final Class inspectionClass, final String hint, LanguageLevel languageLevel) {
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), languageLevel);
try {
doQuickFixTest(inspectionClass, hint);
}
finally {
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), null);
}
}
protected void doQuickFixTest(final Class inspectionClass, final String hint) {
final String testFileName = getTestName(true);
myFixture.enableInspections(inspectionClass);
@@ -19,6 +19,7 @@ import com.intellij.testFramework.TestDataPath;
import com.jetbrains.python.PyBundle;
import com.jetbrains.python.PyQuickFixTestCase;
import com.jetbrains.python.inspections.PyAttributeOutsideInitInspection;
import com.jetbrains.python.psi.LanguageLevel;
/**
* User: ktisha
@@ -58,4 +59,8 @@ public class PyMoveAttributeToInitQuickFixTest extends PyQuickFixTestCase {
doInspectionTest(PyAttributeOutsideInitInspection.class);
}
public void testPy3K() {
doQuickFixTest(PyAttributeOutsideInitInspection.class, PyBundle.message("QFIX.move.attribute"), LanguageLevel.PYTHON33);
}
}