Skip to content

Commit 2cb8e18

Browse files
ddfisherambv
authored andcommitted
Add NoReturn (#811)
* Add NoReturn
1 parent 93bb460 commit 2cb8e18

File tree

9 files changed

+22
-9
lines changed

9 files changed

+22
-9
lines changed

stdlib/2/__builtin__.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ from typing import (
1111
MutableSet, ItemsView, KeysView, ValuesView, Optional, Container,
1212
)
1313
from abc import abstractmethod, ABCMeta
14+
from mypy_extensions import NoReturn
1415

1516
_T = TypeVar('_T')
1617
_T_co = TypeVar('_T_co', covariant=True)
@@ -682,7 +683,7 @@ def dir(o: object = ...) -> List[str]: ...
682683
def divmod(a: int, b: int) -> Tuple[int, int]: ...
683684
@overload
684685
def divmod(a: float, b: float) -> Tuple[float, float]: ...
685-
def exit(code: int = ...) -> None: ...
686+
def exit(code: int = ...) -> NoReturn: ...
686687
@overload
687688
def filter(function: Callable[[_T], Any],
688689
iterable: Iterable[_T]) -> List[_T]: ...

stdlib/2/os/__init__.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ from typing import (
55
Dict, MutableMapping, NamedTuple, overload
66
)
77
from . import path
8+
from mypy_extensions import NoReturn
89

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

188-
def _exit(n: int) -> None: ...
189+
def _exit(n: int) -> NoReturn: ...
189190

190191
def fork() -> int: ...
191192
def forkpty() -> Tuple[int, int]: ...

stdlib/2/sys.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ from typing import (
55
overload, Type,
66
)
77
from types import FrameType, ModuleType, TracebackType, ClassType
8+
from mypy_extensions import NoReturn
89

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

120121
# sys.exit() accepts an optional argument of anything printable
121-
def exit(arg: Any = ...) -> None:
122+
def exit(arg: Any = ...) -> NoReturn:
122123
raise SystemExit()
123124
def getcheckinterval() -> int: ... # deprecated
124125
def getdefaultencoding() -> str: ...

stdlib/3/builtins.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ from typing import (
1010
from abc import abstractmethod, ABCMeta
1111
from types import TracebackType
1212
import sys
13+
from mypy_extensions import NoReturn
1314

1415
# Note that names imported above are not automatically made visible via the
1516
# implicit builtins import.
@@ -697,7 +698,7 @@ def eval(source: str, globals: Dict[str, Any] = None,
697698
locals: Mapping[str, Any] = None) -> Any: ... # TODO code object as source
698699
def exec(object: str, globals: Dict[str, Any] = None,
699700
locals: Mapping[str, Any] = None) -> Any: ... # TODO code object as source
700-
def exit(code: int = None) -> None: ...
701+
def exit(code: int = None) -> NoReturn: ...
701702
@overload
702703
def filter(function: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ...
703704
@overload

stdlib/3/os/__init__.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ from typing import (
1111
Optional, Generic, Set, Callable
1212
)
1313
from . import path
14+
from mypy_extensions import NoReturn
1415

1516
# ----- os variables -----
1617

@@ -314,7 +315,7 @@ def execve(path: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]], env: Mapping[
314315
def execvp(file: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]]) -> None: ...
315316
def execvpe(file: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]],
316317
env: Mapping[str, str]) -> None: ...
317-
def _exit(n: int) -> None: ...
318+
def _exit(n: int) -> NoReturn: ...
318319
def fork() -> int: ... # Unix only
319320
def forkpty() -> Tuple[int, int]: ... # some flavors of Unix
320321
def kill(pid: int, sig: int) -> None: ...

stdlib/3/sys.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ from typing import (
88
TypeVar, Callable, Type,
99
)
1010
from types import TracebackType
11+
from mypy_extensions import NoReturn
1112

1213
_T = TypeVar('_T')
1314

@@ -120,7 +121,7 @@ def exc_info() -> Tuple[Optional[Type[BaseException]],
120121
Optional[BaseException],
121122
Optional[TracebackType]]: ...
122123
# sys.exit() accepts an optional argument of anything printable
123-
def exit(arg: Any = ...) -> None:
124+
def exit(arg: Any = ...) -> NoReturn:
124125
raise SystemExit()
125126
def getcheckinterval() -> int: ... # deprecated
126127
def getdefaultencoding() -> str: ...

third_party/2/six/__init__.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ from typing import (
99
)
1010
import typing
1111
import unittest
12+
from mypy_extensions import NoReturn
1213

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

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
from typing import Dict, Type, TypeVar
1+
from typing import Dict, Type, TypeVar, Union
22

33
T = TypeVar('T')
44

55

66
def TypedDict(typename: str, fields: Dict[str, Type[T]]) -> Type[dict]: ...
7+
8+
# Return type that indicates a function does not return.
9+
# This type is equivalent to the None type, but the no-op Union is necessary to
10+
# distinguish the None type from the None value.
11+
NoReturn = Union[None]

third_party/3/six/__init__.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ from typing import (
2323
import types
2424
import typing
2525
import unittest
26+
from mypy_extensions import NoReturn
2627

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

9394
exec_ = exec
9495

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

9899
print_ = print

0 commit comments

Comments
 (0)