Skip to content

Commit 69e113a

Browse files
committed
Allow importing NoReturn from typing
1 parent 6d354ff commit 69e113a

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

mypy/typeanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
174174
self.fail('Invalid type: ClassVar cannot be generic', t)
175175
return AnyType()
176176
return item
177-
elif fullname == 'mypy_extensions.NoReturn':
177+
elif fullname in ('mypy_extensions.NoReturn', 'typing.NoReturn'):
178178
return UninhabitedType(is_noreturn=True)
179179
elif sym.kind == TYPE_ALIAS:
180180
override = sym.type_override

test-data/unit/check-flags.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,23 @@ from mypy_extensions import NoReturn
193193
x = 0 # type: NoReturn # E: Incompatible types in assignment (expression has type "int", variable has type NoReturn)
194194
[builtins fixtures/dict.pyi]
195195

196+
[case testNoReturnImportFromTyping]
197+
# flags: --warn-no-return
198+
from typing import NoReturn
199+
200+
def h() -> NoReturn:
201+
if bool():
202+
return 5 # E: Return statement in function which does not return
203+
else:
204+
return # E: Return statement in function which does not return
205+
206+
def no_return() -> NoReturn: pass
207+
def f() -> NoReturn:
208+
no_return()
209+
210+
x = 0 # type: NoReturn # E: Incompatible types in assignment (expression has type "int", variable has type NoReturn)
211+
[builtins fixtures/dict.pyi]
212+
196213
[case testShowErrorContextFunction]
197214
# flags: --show-error-context
198215
def f() -> None:

test-data/unit/lib-stub/typing.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ NamedTuple = 0
1818
Type = 0
1919
no_type_check = 0
2020
ClassVar = 0
21+
NoReturn = 0
2122

2223
# Type aliases.
2324
List = 0

0 commit comments

Comments
 (0)