generate 'return' before super method call in Override Methods if appropriate (PY-1537)

This commit is contained in:
Dmitry Jemerov
2010-08-17 21:35:47 +04:00
parent a42cb20de0
commit 7233c2b714
4 changed files with 23 additions and 0 deletions
@@ -24,6 +24,7 @@ import com.jetbrains.python.PyNames;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.impl.PyFunctionBuilder;
import com.jetbrains.python.psi.impl.PyPsiUtils;
import com.jetbrains.python.psi.types.PyNoneType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -163,6 +164,9 @@ public class PyOverrideImplementUtil {
}, ArrayUtil.EMPTY_STRING_ARRAY);
int startIndex = 0;
if (baseFunction.getReturnType() != PyNoneType.INSTANCE) {
statementBody.append("return ");
}
if (baseClass.isNewStyleClass()) {
statementBody.append(PyNames.SUPER);
statementBody.append("(");
+6
View File
@@ -0,0 +1,6 @@
class A:
def doStuff(self, foo=True): return True
class B(A):
def otherMethod(self, foo, bar):
print foo, bar
@@ -0,0 +1,9 @@
class A:
def doStuff(self, foo=True): return True
class B(A):
def doStuff(self, foo=True):
<selection>return A.doStuff(self, foo)</selection>
def otherMethod(self, foo, bar):
print foo, bar
@@ -38,6 +38,10 @@ public class PyOverrideTest extends PyLightFixtureTestCase {
doTest();
}
public void testReturnValue() { // PY-1537
doTest();
}
public void testPy3k() {
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), LanguageLevel.PYTHON31);
try {