PyType (@NotNull TypeEvalContext context, @NotNull PyClass firstClass, @Nullable PyExpression second_arg) { // check 2nd argument, too; it should be an instance if (second_arg != null) { PyType second_type = context.getType(second_arg); if (second_type instanceof PyClassType) { // imitate isinstance(second_arg, possible_class) PyClass secondClass = ((PyClassType)second_type).getPyClass(); if (CompletionUtilCoreImpl.getOriginalOrSelf(firstClass) == secondClass) { return getSuperClassUnionType(firstClass, context); } if (secondClass.isSubclass(firstClass, context)) { final PyClass nextAfterFirstInMro = StreamEx .of(secondClass.getAncestorClasses(context)) .dropWhile(it -> it != firstClass) .skip(1) .findFirst() .orElse(null); if (nextAfterFirstInMro != null) { return new PyClassTypeImpl(nextAfterFirstInMro, false); } } } } return null; }