Skip to content

Commit 8f68fa3

Browse files
authored
Merge pull request #3041 from ilevkivskyi/typing-noreturn
Allow importing NoReturn from typing
2 parents 6b93e63 + 5af9597 commit 8f68fa3

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,22 @@ 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+
from typing import NoReturn
198+
199+
def h() -> NoReturn:
200+
if bool():
201+
return 5 # E: Return statement in function which does not return
202+
else:
203+
return # E: Return statement in function which does not return
204+
205+
def no_return() -> NoReturn: pass
206+
def f() -> NoReturn:
207+
no_return()
208+
209+
x: NoReturn = 0 # E: Incompatible types in assignment (expression has type "int", variable has type NoReturn)
210+
[builtins fixtures/dict.pyi]
211+
196212
[case testShowErrorContextFunction]
197213
# flags: --show-error-context
198214
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)