Ref<PyType> (@NotNull PyFunction function, @Nullable PyCallSiteExpression callSite, @NotNull TypeEvalContext context) { return Optional .ofNullable(function.getContainingClass()) .map(pyClass -> myStringToReturnTypeMap.get(pyClass.getQualifiedName())) .map(typeCallback -> typeCallback.getType(callSite, getQualifierType(callSite, context), context)) .map(Ref::create) .orElse(null); }