diff --git a/python/lib/jython.jar b/python/lib/jython.jar new file mode 100644 index 000000000000..04955766ed17 Binary files /dev/null and b/python/lib/jython.jar differ diff --git a/python/python.iml b/python/python.iml index d07cd3e735a9..8e69778bf084 100644 --- a/python/python.iml +++ b/python/python.iml @@ -3,6 +3,8 @@ + + @@ -11,6 +13,15 @@ + + + + + + + + + diff --git a/python/src/META-INF/plugin.xml b/python/src/META-INF/plugin.xml index db61d652cdaa..8280b4ed1656 100644 --- a/python/src/META-INF/plugin.xml +++ b/python/src/META-INF/plugin.xml @@ -8,6 +8,12 @@ Jemerov, Keith Lea Updated for IntelliJ IDEA 7.0 + + + com.jetbrains.python.PyInspectionToolProvider + + + diff --git a/python/src/com/jetbrains/python/psi/PyFunction.java b/python/src/com/jetbrains/python/psi/PyFunction.java index a30a65513e6a..05f700fc7580 100644 --- a/python/src/com/jetbrains/python/psi/PyFunction.java +++ b/python/src/com/jetbrains/python/psi/PyFunction.java @@ -30,13 +30,21 @@ import org.jetbrains.annotations.Nullable; * To change this template use File | Settings | File Templates. */ public interface PyFunction extends PsiNamedElement, PyElement, PyDocStringOwner { - /** - * Returns the AST node for the function name identifier. - * - * @return the node, or null if the function is incomplete (only the "def" - * keyword was typed) - */ - @Nullable ASTNode getNameNode(); - @NotNull PyParameterList getParameterList(); - @NotNull PyStatementList getStatementList(); + /** + * Returns the AST node for the function name identifier. + * + * @return the node, or null if the function is incomplete (only the "def" + * keyword was typed) + */ + @Nullable + ASTNode getNameNode(); + + @NotNull + PyParameterList getParameterList(); + + @NotNull + PyStatementList getStatementList(); + + @Nullable + PyClass getContainingClass(); } diff --git a/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java index 08991185cd54..4b36a8fec5cd 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java @@ -76,6 +76,17 @@ public class PyFunctionImpl extends PyPresentableElementImpl implements PyFuncti return childToPsiNotNull(PyElementTypes.STATEMENT_LIST); } + public PyClass getContainingClass() { + final PsiElement parent = getParent(); + if (parent instanceof PyStatementList) { + PsiElement pparent = parent.getParent(); + if (pparent instanceof PyClass) { + return (PyClass) pparent; + } + } + return null; + } + @Override protected void acceptPyVisitor(PyElementVisitor pyVisitor) { pyVisitor.visitPyFunction(this); diff --git a/python/testData/inspections/returnValueFromInit/expected.xml b/python/testData/inspections/returnValueFromInit/expected.xml new file mode 100644 index 000000000000..aff3dc3a90eb --- /dev/null +++ b/python/testData/inspections/returnValueFromInit/expected.xml @@ -0,0 +1,23 @@ + + + + test17.py + 7 + Cannot return a value from __init__ + + + test17.py + 13 + Cannot return a value from __init__ + + + test17.py + 15 + Cannot return a value from __init__ + + + test17.py + 16 + Cannot return a value from __init__ + + diff --git a/python/testData/inspections/returnValueFromInit/src/test17.py b/python/testData/inspections/returnValueFromInit/src/test17.py new file mode 100644 index 000000000000..7c08df34b4a3 --- /dev/null +++ b/python/testData/inspections/returnValueFromInit/src/test17.py @@ -0,0 +1,35 @@ +'doc' + +class X: + 'should get a warning for returning value from __init__' + def __init__(self): + print 'howdy' + return 1 + +class Y: + 'should get a warning for returning value from __init__' + def __init__(self, x): + if x == 0 : + return 0 + if x == 1 : + return 53 + return None + +class Z: + 'should not get a warning' + def __init__(self, x): + return + + +class Q(Z): + 'd' + def __init__(self): + v = lambda : None + Z.__init__(self, v) + + +class S(Z): + 'd' + def __init__(self): + Z.__init__(self,lambda x: x in ['p','f']) + diff --git a/python/testSrc/com/jetbrains/python/PythonInspectionsTest.java b/python/testSrc/com/jetbrains/python/PythonInspectionsTest.java new file mode 100644 index 000000000000..06a6dd4977db --- /dev/null +++ b/python/testSrc/com/jetbrains/python/PythonInspectionsTest.java @@ -0,0 +1,17 @@ +package com.jetbrains.python; + +import com.intellij.testFramework.InspectionTestCase; +import com.intellij.openapi.application.PathManager; + +/** + * @author yole + */ +public class PythonInspectionsTest extends InspectionTestCase { + public void testReturnValueFromInit() throws Exception { + doTest(getTestName(true), PyInspectionToolProvider.getInstance().createLocalInspectionTool("ReturnValueFromInitInspection")); + } + + protected String getTestDataPath() { + return PathManager.getHomePath() + "/plugins/python/testData/inspections/"; + } +}