PyClass (PyCallExpression us) { PyExpression callee = us.getCallee(); PsiElement resolved; QualifiedResolveResult resolveResult; if (callee instanceof PyReferenceExpression ref) { // dereference resolveResult = ref.followAssignmentsChain(PyResolveContext.defaultContext(TypeEvalContext.codeInsightFallback(ref.getProject()))); resolved = resolveResult.getElement(); } else { resolved = callee; } // analyze if (resolved instanceof PyClass) { return (PyClass)resolved; } else if (resolved instanceof PyFunction pyFunction) { return pyFunction.getContainingClass(); } return null; }