From 08b5f44df266f1b86f84ddbe765326779c4df882 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 16 Mar 2010 20:11:22 +0300 Subject: [PATCH] parameter info works for inherited class constructors (PY-256) --- .../jetbrains/python/psi/impl/PyCallExpressionHelper.java | 2 +- python/testData/paramInfo/InheritedClassInit.py | 8 ++++++++ .../testSrc/com/jetbrains/python/PyParameterInfoTest.java | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 python/testData/paramInfo/InheritedClassInit.py diff --git a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java index 67c631aa089a..458fa4969277 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java +++ b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java @@ -88,7 +88,7 @@ public class PyCallExpressionHelper { if (callee instanceof PyReferenceExpression) { PyReferenceExpression ref = (PyReferenceExpression)callee; PsiElement resolved = ref.followAssignmentsChain(); - if (resolved instanceof PyClass) resolved = ((PyClass)resolved).findMethodByName(PyNames.INIT, false); // class to constructor call + if (resolved instanceof PyClass) resolved = ((PyClass)resolved).findMethodByName(PyNames.INIT, true); // class to constructor call else if (resolved instanceof PyCallExpression) { // is it a case of "foo = classmethod(foo)"? PyCallExpression redefining_call = (PyCallExpression)resolved; diff --git a/python/testData/paramInfo/InheritedClassInit.py b/python/testData/paramInfo/InheritedClassInit.py new file mode 100644 index 000000000000..60f7e4dfba34 --- /dev/null +++ b/python/testData/paramInfo/InheritedClassInit.py @@ -0,0 +1,8 @@ +class Bar: + def __init__(self, a, b): + pass + +class Bambr(Bar): + pass + +Bambr(1, 2) diff --git a/python/testSrc/com/jetbrains/python/PyParameterInfoTest.java b/python/testSrc/com/jetbrains/python/PyParameterInfoTest.java index f0423d74b741..d0b6e96a3102 100644 --- a/python/testSrc/com/jetbrains/python/PyParameterInfoTest.java +++ b/python/testSrc/com/jetbrains/python/PyParameterInfoTest.java @@ -239,6 +239,14 @@ public class PyParameterInfoTest extends LightMarkedTestCase { feignCtrlP(marks.get("").getTextOffset()).check("self,a,b", new String[]{"b"}, new String[]{"self,"}); } + public void testInheritedClassInit() throws Exception { + Map marks = loadTest(); + assertEquals("Test data sanity", marks.size(), 2); + + feignCtrlP(marks.get("").getTextOffset()).check("self,a,b", new String[]{"a,"}, new String[]{"self,"}); + feignCtrlP(marks.get("").getTextOffset()).check("self,a,b", new String[]{"b"}, new String[]{"self,"}); + } + // TODO: add method tests with decorators when a mock SDK is available /**