mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
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:
committed by
intellij-monorepo-bot
parent
7200369f16
commit
4c890f2d47
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,25 @@ def func(x: Any | None = None):
|
||||
print("foo")
|
||||
""");
|
||||
}
|
||||
|
||||
// PY-82707
|
||||
public void testClassInheritingFromAny() {
|
||||
doTestByText("""
|
||||
from typing import Any
|
||||
|
||||
class A(Any): ...
|
||||
|
||||
a = A()
|
||||
if a is not None:
|
||||
print("hi") # reachable
|
||||
|
||||
match a:
|
||||
case int():
|
||||
print()
|
||||
case str():
|
||||
print() # reachable
|
||||
""");
|
||||
}
|
||||
|
||||
// PY-81729
|
||||
public void testTypeVarOrNoneAfterIsNotNoneCast(){
|
||||
|
||||
Reference in New Issue
Block a user