Skip to content

Commit 16318b9

Browse files
committed
Include ambiguous in UninhabitedType.__eq__
1 parent 5a78607 commit 16318b9

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

mypy/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,10 +1236,10 @@ def accept(self, visitor: TypeVisitor[T]) -> T:
12361236
return visitor.visit_uninhabited_type(self)
12371237

12381238
def __hash__(self) -> int:
1239-
return hash(UninhabitedType)
1239+
return hash((UninhabitedType, self.ambiguous))
12401240

12411241
def __eq__(self, other: object) -> bool:
1242-
return isinstance(other, UninhabitedType)
1242+
return isinstance(other, UninhabitedType) and other.ambiguous == self.ambiguous
12431243

12441244
def serialize(self) -> JsonDict:
12451245
return {".class": "UninhabitedType"}

test-data/unit/check-generic-subtyping.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,20 @@ s, s = Nums() # E: Incompatible types in assignment (expression has type "int",
753753
[builtins fixtures/for.pyi]
754754
[out]
755755

756+
[case testUninhabitedCacheChecksAmbiguous]
757+
# https://github.com/python/mypy/issues/19641
758+
from typing import Mapping, Never, TypeVar
759+
760+
M = TypeVar("M", bound=Mapping[str,object])
761+
762+
def get(arg: M, /) -> M:
763+
return arg
764+
765+
get({})
766+
767+
def upcast(d: dict[Never, Never]) -> Mapping[str, object]:
768+
return d # E: Incompatible return value type (got "dict[Never, Never]", expected "Mapping[str, object]")
769+
[builtins fixtures/dict.pyi]
756770

757771
-- Variance
758772
-- --------

0 commit comments

Comments
 (0)