Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow importing NoReturn from typing #3041

Merged
merged 2 commits into from
Mar 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
self.fail('Invalid type: ClassVar cannot be generic', t)
return AnyType()
return item
elif fullname == 'mypy_extensions.NoReturn':
elif fullname in ('mypy_extensions.NoReturn', 'typing.NoReturn'):
return UninhabitedType(is_noreturn=True)
elif sym.kind == TYPE_ALIAS:
override = sym.type_override
Expand Down
16 changes: 16 additions & 0 deletions test-data/unit/check-flags.test
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,22 @@ from mypy_extensions import NoReturn
x = 0 # type: NoReturn # E: Incompatible types in assignment (expression has type "int", variable has type NoReturn)
[builtins fixtures/dict.pyi]

[case testNoReturnImportFromTyping]
from typing import NoReturn

def h() -> NoReturn:
if bool():
return 5 # E: Return statement in function which does not return
else:
return # E: Return statement in function which does not return

def no_return() -> NoReturn: pass
def f() -> NoReturn:
no_return()

x: NoReturn = 0 # E: Incompatible types in assignment (expression has type "int", variable has type NoReturn)
[builtins fixtures/dict.pyi]

[case testShowErrorContextFunction]
# flags: --show-error-context
def f() -> None:
Expand Down
1 change: 1 addition & 0 deletions test-data/unit/lib-stub/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ NamedTuple = 0
Type = 0
no_type_check = 0
ClassVar = 0
NoReturn = 0

# Type aliases.
List = 0
Expand Down