Skip to content

Commit a0308bc

Browse files
committed
Address primer output
1 parent 0076ae8 commit a0308bc

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

mypy/subtypes.py

+6
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,12 @@ def covers_at_runtime(item: Type, supertype: Type) -> bool:
17821782
item = get_proper_type(item)
17831783
supertype = get_proper_type(supertype)
17841784

1785+
# Left `Any` or `Type[Any]` type will never be covered at runtime:
1786+
if isinstance(item, AnyType) or (
1787+
isinstance(item, TypeType) and isinstance(item.item, AnyType)
1788+
):
1789+
return False
1790+
17851791
if isinstance(item, (CallableType, TypeType)) and item.is_singleton_type():
17861792
if is_proper_subtype(item, supertype):
17871793
return True

test-data/unit/check-narrowing.test

+22
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,28 @@ else:
13271327
[builtins fixtures/isinstancelist.pyi]
13281328

13291329

1330+
[case testNarrowingAnyAgainstFinalType]
1331+
from typing import Type, Any
1332+
from typing_extensions import final
1333+
1334+
@final
1335+
class Mark: ...
1336+
1337+
x: Any
1338+
if x is Mark:
1339+
reveal_type(x) # N: Revealed type is "def () -> __main__.Mark"
1340+
else:
1341+
reveal_type(x) # N: Revealed type is "Any"
1342+
1343+
y: Type[Any]
1344+
if y is Mark:
1345+
reveal_type(y) # N: Revealed type is "Type[__main__.Mark]"
1346+
else:
1347+
reveal_type(y) # N: Revealed type is "Type[Any]"
1348+
1349+
[builtins fixtures/isinstancelist.pyi]
1350+
1351+
13301352
[case testNarrowingIsRegualType]
13311353
from typing import Type, Union
13321354

0 commit comments

Comments
 (0)