MCPcopy Index your code
hub / github.com/python/mypy / UninhabitedType

Class UninhabitedType

mypy/types.py:1374–1426  ·  view source on GitHub ↗

This type has no members. This type is the bottom type. With strict Optional checking, it is the only common subtype between all other types, which allows `meet` to be well defined. Without strict Optional checking, NoneType fills this role. In general, for any type T:

Source from the content-addressed store, hash-verified

1372
1373
1374class UninhabitedType(ProperType):
1375 """This type has no members.
1376
1377 This type is the bottom type.
1378 With strict Optional checking, it is the only common subtype between all
1379 other types, which allows `meet` to be well defined. Without strict
1380 Optional checking, NoneType fills this role.
1381
1382 In general, for any type T:
1383 join(UninhabitedType, T) = T
1384 meet(UninhabitedType, T) = UninhabitedType
1385 is_subtype(UninhabitedType, T) = True
1386 """
1387
1388 __slots__ = ("ambiguous",)
1389
1390 ambiguous: bool # Is this a result of inference for a variable without constraints?
1391
1392 def __init__(self, line: int = -1, column: int = -1) -> None:
1393 super().__init__(line, column)
1394 self.ambiguous = False
1395
1396 def can_be_true_default(self) -> bool:
1397 return False
1398
1399 def can_be_false_default(self) -> bool:
1400 return False
1401
1402 def accept(self, visitor: TypeVisitor[T]) -> T:
1403 return visitor.visit_uninhabited_type(self)
1404
1405 def __hash__(self) -> int:
1406 return hash((UninhabitedType, self.ambiguous))
1407
1408 def __eq__(self, other: object) -> bool:
1409 return isinstance(other, UninhabitedType) and other.ambiguous == self.ambiguous
1410
1411 def serialize(self) -> JsonDict:
1412 return {".class": "UninhabitedType"}
1413
1414 @classmethod
1415 def deserialize(cls, data: JsonDict) -> UninhabitedType:
1416 assert data[".class"] == "UninhabitedType"
1417 return UninhabitedType()
1418
1419 def write(self, data: WriteBuffer) -> None:
1420 write_tag(data, UNINHABITED_TYPE)
1421 write_tag(data, END_TAG)
1422
1423 @classmethod
1424 def read(cls, data: ReadBuffer) -> UninhabitedType:
1425 assert read_tag(data) == END_TAG
1426 return UninhabitedType()
1427
1428
1429class NoneType(ProperType):

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…