Address primer output
diff --git a/mypy/subtypes.py b/mypy/subtypes.py index f0e7515..08eebe5 100644 --- a/mypy/subtypes.py +++ b/mypy/subtypes.py
@@ -1782,6 +1782,12 @@ item = get_proper_type(item) supertype = get_proper_type(supertype) + # Left `Any` or `Type[Any]` type will never be covered at runtime: + if isinstance(item, AnyType) or ( + isinstance(item, TypeType) and isinstance(item.item, AnyType) + ): + return False + if isinstance(item, (CallableType, TypeType)) and item.is_singleton_type(): if is_proper_subtype(item, supertype): return True
diff --git a/test-data/unit/check-narrowing.test b/test-data/unit/check-narrowing.test index 3b0c763..87beb97 100644 --- a/test-data/unit/check-narrowing.test +++ b/test-data/unit/check-narrowing.test
@@ -1327,6 +1327,28 @@ [builtins fixtures/isinstancelist.pyi] +[case testNarrowingAnyAgainstFinalType] +from typing import Type, Any +from typing_extensions import final + +@final +class Mark: ... + +x: Any +if x is Mark: + reveal_type(x) # N: Revealed type is "def () -> __main__.Mark" +else: + reveal_type(x) # N: Revealed type is "Any" + +y: Type[Any] +if y is Mark: + reveal_type(y) # N: Revealed type is "Type[__main__.Mark]" +else: + reveal_type(y) # N: Revealed type is "Type[Any]" + +[builtins fixtures/isinstancelist.pyi] + + [case testNarrowingIsRegualType] from typing import Type, Union