Skip to content

Commit 718c4db

Browse files
committed
render "Never" instead of "<nothing>"
1 parent b6e2547 commit 718c4db

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

mypy/messages.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,8 @@ def format_literal_value(typ: LiteralType) -> str:
23002300
if typ.is_noreturn:
23012301
return "NoReturn"
23022302
else:
2303+
if mypy.options._based:
2304+
return "Never"
23032305
return "<nothing>"
23042306
elif isinstance(typ, TypeType):
23052307
if not mypy.options._based:

mypy/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,6 +2893,8 @@ def visit_none_type(self, t: NoneType) -> str:
28932893
return "None"
28942894

28952895
def visit_uninhabited_type(self, t: UninhabitedType) -> str:
2896+
if mypy.options._based:
2897+
return "Never"
28962898
return "<nothing>"
28972899

28982900
def visit_erased_type(self, t: ErasedType) -> str:

test-data/unit/check-based-type-render.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,13 @@ T = TypeVar("T", bound=int)
4848

4949
def foo(t: T): ...
5050
reveal_type(foo) # N: Revealed type is "def[T: int](t: T)"
51+
52+
53+
[case testInferredNever]
54+
a: bool
55+
if a: ...
56+
elif not a: ...
57+
else:
58+
reveal_type(a) # N: Revealed type is "Never"
59+
# E: Statement is unreachable [unreachable]
60+

0 commit comments

Comments
 (0)