Skip to content

Add NoReturn #811

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

Merged
merged 3 commits into from
Jan 4, 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
3 changes: 2 additions & 1 deletion stdlib/2/__builtin__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ from typing import (
MutableSet, ItemsView, KeysView, ValuesView, Optional, Container,
)
from abc import abstractmethod, ABCMeta
from mypy_extensions import NoReturn

_T = TypeVar('_T')
_T_co = TypeVar('_T_co', covariant=True)
Expand Down Expand Up @@ -682,7 +683,7 @@ def dir(o: object = ...) -> List[str]: ...
def divmod(a: int, b: int) -> Tuple[int, int]: ...
@overload
def divmod(a: float, b: float) -> Tuple[float, float]: ...
def exit(code: int = ...) -> None: ...
def exit(code: int = ...) -> NoReturn: ...
@overload
def filter(function: Callable[[_T], Any],
iterable: Iterable[_T]) -> List[_T]: ...
Expand Down
3 changes: 2 additions & 1 deletion stdlib/2/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ from typing import (
Dict, MutableMapping, NamedTuple, overload
)
from . import path
from mypy_extensions import NoReturn

error = OSError
name = ... # type: str
Expand Down Expand Up @@ -185,7 +186,7 @@ def execvpe(file: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]], env: Mapping
def execv(path: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]]) -> None: ...
def execve(path: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]], env: Mapping[AnyStr, AnyStr]) -> None: ...

def _exit(n: int) -> None: ...
def _exit(n: int) -> NoReturn: ...

def fork() -> int: ...
def forkpty() -> Tuple[int, int]: ...
Expand Down
3 changes: 2 additions & 1 deletion stdlib/2/sys.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ from typing import (
overload, Type,
)
from types import FrameType, ModuleType, TracebackType, ClassType
from mypy_extensions import NoReturn

class _flags:
bytes_warning = ... # type: int
Expand Down Expand Up @@ -118,7 +119,7 @@ def exc_info() -> Tuple[Optional[Type[BaseException]],
Optional[TracebackType]]: ...

# sys.exit() accepts an optional argument of anything printable
def exit(arg: Any = ...) -> None:
def exit(arg: Any = ...) -> NoReturn:
raise SystemExit()
def getcheckinterval() -> int: ... # deprecated
def getdefaultencoding() -> str: ...
Expand Down
3 changes: 2 additions & 1 deletion stdlib/3/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ from typing import (
from abc import abstractmethod, ABCMeta
from types import TracebackType
import sys
from mypy_extensions import NoReturn

# Note that names imported above are not automatically made visible via the
# implicit builtins import.
Expand Down Expand Up @@ -697,7 +698,7 @@ def eval(source: str, globals: Dict[str, Any] = None,
locals: Mapping[str, Any] = None) -> Any: ... # TODO code object as source
def exec(object: str, globals: Dict[str, Any] = None,
locals: Mapping[str, Any] = None) -> Any: ... # TODO code object as source
def exit(code: int = None) -> None: ...
def exit(code: int = None) -> NoReturn: ...
@overload
def filter(function: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ...
@overload
Expand Down
3 changes: 2 additions & 1 deletion stdlib/3/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ from typing import (
Optional, Generic, Set, Callable
)
from . import path
from mypy_extensions import NoReturn

# ----- os variables -----

Expand Down Expand Up @@ -314,7 +315,7 @@ def execve(path: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]], env: Mapping[
def execvp(file: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]]) -> None: ...
def execvpe(file: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]],
env: Mapping[str, str]) -> None: ...
def _exit(n: int) -> None: ...
def _exit(n: int) -> NoReturn: ...
def fork() -> int: ... # Unix only
def forkpty() -> Tuple[int, int]: ... # some flavors of Unix
def kill(pid: int, sig: int) -> None: ...
Expand Down
3 changes: 2 additions & 1 deletion stdlib/3/sys.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ from typing import (
TypeVar, Callable, Type,
)
from types import TracebackType
from mypy_extensions import NoReturn

_T = TypeVar('_T')

Expand Down Expand Up @@ -120,7 +121,7 @@ def exc_info() -> Tuple[Optional[Type[BaseException]],
Optional[BaseException],
Optional[TracebackType]]: ...
# sys.exit() accepts an optional argument of anything printable
def exit(arg: Any = ...) -> None:
def exit(arg: Any = ...) -> NoReturn:
raise SystemExit()
def getcheckinterval() -> int: ... # deprecated
def getdefaultencoding() -> str: ...
Expand Down
3 changes: 2 additions & 1 deletion third_party/2/six/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ from typing import (
)
import typing
import unittest
from mypy_extensions import NoReturn

# Exports
from __builtin__ import unichr as unichr
Expand Down Expand Up @@ -79,7 +80,7 @@ def assertRaisesRegex(self: unittest.TestCase, msg: str = ...) -> Any: ...
def assertRaisesRegex(self: unittest.TestCase, callable_obj: Callable[..., Any], *args: Any, **kwargs: Any) -> Any: ...
def assertRegex(self: unittest.TestCase, text: AnyStr, expected_regex: Union[AnyStr, Pattern[AnyStr]], msg: str = ...) -> None: ...

def reraise(tp: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[types.TracebackType] = ...) -> None: ...
def reraise(tp: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[types.TracebackType] = ...) -> NoReturn: ...
def exec_(_code_: Union[unicode, types.CodeType], _globs_: Dict[str, Any] = ..., _locs_: Dict[str, Any] = ...): ...
def raise_from(value: BaseException, from_value: BaseException) -> None: ...

Expand Down
7 changes: 6 additions & 1 deletion third_party/2and3/mypy_extensions.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from typing import Dict, Type, TypeVar
from typing import Dict, Type, TypeVar, Union

T = TypeVar('T')


def TypedDict(typename: str, fields: Dict[str, Type[T]]) -> Type[dict]: ...

# Return type that indicates a function does not return.
# This type is equivalent to the None type, but the no-op Union is necessary to
# distinguish the None type from the None value.
NoReturn = Union[None]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand this. NoReturn is different from the NoneType, the latter is a type with one value, while the former is a type with no values, a.k.a. "error type" or "bottom type". Maybe it would be better to write class NoReturn: ...?

@gvanrossum What do you think about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent is to not disrupt typecheckers that don't yet support this (as it's not yet part of PEP 484).

3 changes: 2 additions & 1 deletion third_party/3/six/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ from typing import (
import types
import typing
import unittest
from mypy_extensions import NoReturn

# Exports
from io import StringIO as StringIO, BytesIO as BytesIO
Expand Down Expand Up @@ -92,7 +93,7 @@ def assertRegex(self: unittest.TestCase, text: AnyStr, expected_regex: Union[Any

exec_ = exec

def reraise(tp: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[types.TracebackType] = None) -> None: ...
def reraise(tp: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[types.TracebackType] = None) -> NoReturn: ...
def raise_from(value: BaseException, from_value: BaseException) -> None: ...

print_ = print
Expand Down