PY-82707 Pycharm July 2025 EAP showing unreachable when using a subtype of Any

(cherry picked from commit c8a61ecc43754144679e5afc9f4623c02f558597)

IJ-MR-170092

GitOrigin-RevId: 612862aa2ce338a8f18e13197f483b936c9d0cdb
This commit is contained in:
Aleksandr.Govenko
2025-07-22 18:34:23 +02:00
committed by intellij-monorepo-bot
parent 7200369f16
commit 4c890f2d47
3 changed files with 24 additions and 0 deletions

View File

@@ -282,6 +282,7 @@ public class PyTypeAssertionEvaluator extends PyRecursiveElementVisitor {
private static boolean match(@Nullable PyType expected, @Nullable PyType actual, @NotNull TypeEvalContext context) {
return !(actual instanceof PyStructuralType) &&
!PyTypeChecker.isUnknown(actual, context) &&
!(PyTypeUtil.inheritsAny(actual, context)) &&
PyTypeChecker.match(expected, actual, context);
}

View File

@@ -182,4 +182,8 @@ public final class PyTypeUtil {
new PyClassTypeImpl(superClass, false));
return PyTypeChecker.convertToType(type, superClassType, context);
}
public static boolean inheritsAny(@NotNull PyType type, @NotNull TypeEvalContext context) {
return type instanceof PyClassLikeType classLikeType && classLikeType.getAncestorTypes(context).contains(null);
}
}