diff --git a/python/src/com/jetbrains/python/inspections/PySuperArgumentsInspection.java b/python/src/com/jetbrains/python/inspections/PySuperArgumentsInspection.java index fbc476b733a9..f57f90135a77 100644 --- a/python/src/com/jetbrains/python/inspections/PySuperArgumentsInspection.java +++ b/python/src/com/jetbrains/python/inspections/PySuperArgumentsInspection.java @@ -10,9 +10,12 @@ import com.jetbrains.python.psi.PyCallExpression; import com.jetbrains.python.psi.PyClass; import com.jetbrains.python.psi.PyExpression; import com.jetbrains.python.psi.PyReferenceExpression; +import com.jetbrains.python.psi.types.PyClassType; +import com.jetbrains.python.psi.types.PyType; import com.jetbrains.python.psi.types.TypeEvalContext; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author Alexey.Ivanov @@ -39,23 +42,41 @@ public class PySuperArgumentsInspection extends PyInspection { @Override public void visitPyCallExpression(PyCallExpression node) { - if (PyNames.SUPER.equals(node.getCallee().getName())) { - PyExpression[] arguments = node.getArguments(); - if (arguments.length == 2) { - if (arguments[0] instanceof PyReferenceExpression && arguments[1] instanceof PyReferenceExpression) { - PsiElement firstElement = ((PyReferenceExpression) arguments[0]).followAssignmentsChain(myTypeEvalContext).getElement(); - PsiElement secondElement = ((PyReferenceExpression) arguments[1]).followAssignmentsChain(myTypeEvalContext).getElement(); - if (firstElement instanceof PyClass && secondElement instanceof PyClass) { - PyClass firstClass = (PyClass) firstElement; - PyClass secondClass = (PyClass) secondElement; - if (!secondClass.isSubclass(firstClass)) { - registerProblem(node.getArgumentList(), PyBundle.message("INSP.$0.is.not.superclass.of.$1", - secondClass.getName(), firstClass.getName())); + final PyExpression callee = node.getCallee(); + if (callee != null) { + if (PyNames.SUPER.equals(callee.getName())) { + PyExpression[] arguments = node.getArguments(); + if (arguments.length == 2) { + if (arguments[0] instanceof PyReferenceExpression && arguments[1] instanceof PyReferenceExpression) { + PyClass firstClass = findClassOf(arguments[0]); + PyClass secondClass = findClassOf(arguments[1]); + if (firstClass != null && secondClass != null) { + if (!secondClass.isSubclass(firstClass)) { + registerProblem( + node.getArgumentList(), + PyBundle.message("INSP.$0.is.not.superclass.of.$1", + secondClass.getName(), firstClass.getName()) + ); + } } } } } } } + + @Nullable + private PyClass findClassOf(PyExpression argument) { + PsiElement firstElement = ((PyReferenceExpression)argument).followAssignmentsChain(myTypeEvalContext).getElement(); + PyClass firstClass = null; + if (firstElement instanceof PyClass) firstClass = (PyClass)firstElement; + else if (firstElement instanceof PyExpression) { + PyType first_type = ((PyExpression)firstElement).getType(TypeEvalContext.fast()); + if (first_type instanceof PyClassType) { + firstClass = ((PyClassType)first_type).getPyClass(); + } + } + return firstClass; + } } }