diff --git a/.travis.yml b/.travis.yml index 011b5212123c..0a315e7668d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,38 +1,25 @@ -dist: xenial +dist: bionic language: python python: 3.7 -matrix: +jobs: include: - name: "pytype" python: 3.6 - env: - - TEST_CMD="./tests/pytype_test.py" - - INSTALL="test" - - name: "mypy" - env: - - TEST_CMD="./tests/mypy_test.py" - - INSTALL="mypy" - - name: "mypy new analyzer" - env: - - TEST_CMD="./tests/mypy_test.py -a" - - INSTALL="mypy" + install: pip install -r requirements-tests-py3.txt + script: ./tests/pytype_test.py + - name: "mypy (typed-ast)" + python: 3.7 + install: pip install -U git+git://github.com/python/mypy git+git://github.com/python/typed_ast + script: ./tests/mypy_test.py + - name: "mypy (ast)" + python: 3.8-dev + install: pip install -U git+git://github.com/python/mypy + script: ./tests/mypy_test.py - name: "mypy self test" - env: TEST_CMD="./tests/mypy_selftest.py" - - name: "mypy self test (new analyzer)" - env: - - NEWSEMANAL=1 - - TEST_CMD="./tests/mypy_selftest.py" + script: ./tests/mypy_selftest.py - name: "check file consistency" - env: TEST_CMD="./tests/check_consistent.py" + script: ./tests/check_consistent.py - name: "flake8" - env: - - TEST_CMD="flake8" - - INSTALL="test" - -install: - - if [[ $INSTALL == 'test' ]]; then pip install -r requirements-tests-py3.txt; fi - - if [[ $INSTALL == 'mypy' ]]; then pip install -U git+git://github.com/python/mypy git+git://github.com/python/typed_ast; fi - -script: - - $TEST_CMD + install: pip install -r requirements-tests-py3.txt + script: flake8 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 045d07f654d0..bdab962fe86d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -238,7 +238,7 @@ rule is that they should be as concise as possible. Specifically: * use variable annotations instead of type comments, even for stubs that target older versions of Python; * for arguments with a type and a default, use spaces around the `=`. -The code formatter [black](https://github.com/python/black) will format +The code formatter [black](https://github.com/psf/black) will format stubs according to this standard. Stub files should only contain information necessary for the type @@ -292,6 +292,15 @@ Type variables and aliases you introduce purely for legibility reasons should be prefixed with an underscore to make it obvious to the reader they are not part of the stubbed API. +When adding type annotations for context manager classes, annotate +the return type of `__exit__` as bool only if the context manager +sometimes suppresses annotations -- if it sometimes returns `True` +at runtime. If the context manager never suppresses exceptions, +have the return type be either `None` or `Optional[bool]`. If you +are not sure whether exceptions are suppressed or not or if the +context manager is meant to be subclassed, pick `Optional[bool]`. +See https://github.com/python/mypy/issues/7214 for more details. + NOTE: there are stubs in this repository that don't conform to the style described above. Fixing them is a great starting point for new contributors. @@ -307,8 +316,8 @@ and optionally the lowest minor version, with the exception of the `2and3` directory which applies to both Python 2 and 3. For example, stubs in the `3` directory will be applied to all versions of -Python 3, though stubs in the `3.6` directory will only be applied to versions -3.6 and above. However, stubs in the `2` directory will not be applied to +Python 3, though stubs in the `3.7` directory will only be applied to versions +3.7 and above. However, stubs in the `2` directory will not be applied to Python 3. It is preferred to use a single stub in the more generic directory that @@ -318,7 +327,7 @@ if the given library works on both Python 2 and Python 3, prefer to put your stubs in the `2and3` directory, unless the types are so different that the stubs become unreadable that way. -You can use checks like `if sys.version_info >= (3, 4):` to denote new +You can use checks like `if sys.version_info >= (3, 8):` to denote new functionality introduced in a given Python version or solve type differences. When doing so, only use one-tuples or two-tuples. This is because: @@ -331,17 +340,17 @@ because: regardless of the micro version used. Because of this, if a given functionality was introduced in, say, Python -3.4.4, your check: +3.7.4, your check: -* should be expressed as `if sys.version_info >= (3, 4):` -* should NOT be expressed as `if sys.version_info >= (3, 4, 4):` -* should NOT be expressed as `if sys.version_info >= (3, 5):` +* should be expressed as `if sys.version_info >= (3, 7):` +* should NOT be expressed as `if sys.version_info >= (3, 7, 4):` +* should NOT be expressed as `if sys.version_info >= (3, 8):` This makes the type checker assume the functionality was also available -in 3.4.0 - 3.4.3, which while *technically* incorrect is relatively +in 3.7.0 - 3.7.3, which while *technically* incorrect is relatively harmless. This is a strictly better compromise than using the latter two forms, which would generate false positive errors for correct use -under Python 3.4.4. +under Python 3.7.4. Note: in its current implementation, typeshed cannot contain stubs for multiple versions of the same third-party library. Prefer to generate diff --git a/README.md b/README.md index 14f32ea72859..76f3ed924e05 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ For information on how to use `typeshed`, read below. Information for contributors can be found in [CONTRIBUTING.md](CONTRIBUTING.md). **Please read it before submitting pull requests.** -Typeshed supports Python versions 2.7 and 3.4 and up. +Typeshed supports Python versions 2.7 and 3.5 and up. ## Using diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000000..3ae4966f6f11 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,11 @@ +[tool.black] +line_length = 130 +target_version = ["py37"] + +[tool.isort] +multi_line_output = 3 +include_trailing_comma = true +force_grid_wrap = 0 +use_parentheses = true +combine_as_imports = true +line_length = 130 diff --git a/requirements-tests-py3.txt b/requirements-tests-py3.txt index 5c23efe5e6b3..34c3a46716aa 100644 --- a/requirements-tests-py3.txt +++ b/requirements-tests-py3.txt @@ -1,6 +1,8 @@ git+https://github.com/python/mypy.git@master typed-ast>=1.0.4 -flake8==3.6.0 -flake8-bugbear==18.8.0 -flake8-pyi==18.3.1 -pytype>=2019.5.15 +black==19.3b0 +flake8==3.7.8 +flake8-bugbear==19.3.0 +flake8-pyi==19.3.0 +isort==4.3.21 +pytype>=2019.7.30 diff --git a/stdlib/2/CGIHTTPServer.pyi b/stdlib/2/CGIHTTPServer.pyi new file mode 100644 index 000000000000..4eae666d86d0 --- /dev/null +++ b/stdlib/2/CGIHTTPServer.pyi @@ -0,0 +1,8 @@ +# Stubs for CGIHTTPServer (Python 2.7) + +from typing import List +import SimpleHTTPServer + +class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): + cgi_directories: List[str] + def do_POST(self) -> None: ... diff --git a/stdlib/2/ConfigParser.pyi b/stdlib/2/ConfigParser.pyi index 5d86811726a8..fa0e551717d1 100644 --- a/stdlib/2/ConfigParser.pyi +++ b/stdlib/2/ConfigParser.pyi @@ -55,8 +55,8 @@ class _Readable(Protocol): class RawConfigParser: _dict: Any - _sections: dict - _defaults: dict + _sections: Dict[Any, Any] + _defaults: Dict[Any, Any] _optcre: Any SECTCRE: Any OPTCRE: Any @@ -86,12 +86,14 @@ class RawConfigParser: class ConfigParser(RawConfigParser): _KEYCRE: Any - def get(self, section: str, option: str, raw: bool = ..., vars: Optional[dict] = ...) -> Any: ... - def items(self, section: str, raw: bool = ..., vars: Optional[dict] = ...) -> List[Tuple[str, Any]]: ... + def get(self, section: str, option: str, raw: bool = ..., vars: Optional[Dict[Any, Any]] = ...) -> Any: ... + def items(self, section: str, raw: bool = ..., vars: Optional[Dict[Any, Any]] = ...) -> List[Tuple[str, Any]]: ... def _interpolate(self, section: str, option: str, rawval: Any, vars: Any) -> str: ... def _interpolation_replace(self, match: Any) -> str: ... class SafeConfigParser(ConfigParser): _interpvar_re: Any def _interpolate(self, section: str, option: str, rawval: Any, vars: Any) -> str: ... - def _interpolate_some(self, option: str, accum: list, rest: str, section: str, map: dict, depth: int) -> None: ... + def _interpolate_some( + self, option: str, accum: List[Any], rest: str, section: str, map: Dict[Any, Any], depth: int, + ) -> None: ... diff --git a/stdlib/2/Cookie.pyi b/stdlib/2/Cookie.pyi index 79a7a8141ef6..91dd93221c73 100644 --- a/stdlib/2/Cookie.pyi +++ b/stdlib/2/Cookie.pyi @@ -1,8 +1,8 @@ -from typing import Any, Optional +from typing import Any, Dict, Optional class CookieError(Exception): ... -class Morsel(dict): +class Morsel(Dict[Any, Any]): key: Any def __init__(self): ... def __setitem__(self, K, V): ... @@ -14,7 +14,7 @@ class Morsel(dict): def js_output(self, attrs: Optional[Any] = ...): ... def OutputString(self, attrs: Optional[Any] = ...): ... -class BaseCookie(dict): +class BaseCookie(Dict[Any, Any]): def value_decode(self, val): ... def value_encode(self, val): ... def __init__(self, input: Optional[Any] = ...): ... diff --git a/stdlib/2/Queue.pyi b/stdlib/2/Queue.pyi index 11b01ed1c23e..76e3dcb5024f 100644 --- a/stdlib/2/Queue.pyi +++ b/stdlib/2/Queue.pyi @@ -1,7 +1,7 @@ # Stubs for Queue (Python 2) from collections import deque -from typing import Any, TypeVar, Generic, Optional +from typing import Any, Deque, TypeVar, Generic, Optional _T = TypeVar('_T') @@ -15,7 +15,7 @@ class Queue(Generic[_T]): not_full: Any all_tasks_done: Any unfinished_tasks: Any - queue: deque # undocumented + queue: Deque[Any] # undocumented def __init__(self, maxsize: int = ...) -> None: ... def task_done(self) -> None: ... def join(self) -> None: ... @@ -27,5 +27,5 @@ class Queue(Generic[_T]): def get(self, block: bool = ..., timeout: Optional[float] = ...) -> _T: ... def get_nowait(self) -> _T: ... -class PriorityQueue(Queue): ... -class LifoQueue(Queue): ... +class PriorityQueue(Queue[_T]): ... +class LifoQueue(Queue[_T]): ... diff --git a/stdlib/2/SimpleHTTPServer.pyi b/stdlib/2/SimpleHTTPServer.pyi index be22b88381d7..4a36cc5bdfe4 100644 --- a/stdlib/2/SimpleHTTPServer.pyi +++ b/stdlib/2/SimpleHTTPServer.pyi @@ -9,7 +9,7 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self) -> None: ... def do_HEAD(self) -> None: ... def send_head(self) -> Optional[IO[str]]: ... - def list_directory(self, path: Union[str, unicode]) -> Optional[StringIO]: ... + def list_directory(self, path: Union[str, unicode]) -> Optional[StringIO[Any]]: ... def translate_path(self, path: AnyStr) -> AnyStr: ... def copyfile(self, source: IO[AnyStr], outputfile: IO[AnyStr]): ... def guess_type(self, path: Union[str, unicode]) -> str: ... diff --git a/stdlib/2/SocketServer.pyi b/stdlib/2/SocketServer.pyi index d485b8bf1034..2403614b4709 100644 --- a/stdlib/2/SocketServer.pyi +++ b/stdlib/2/SocketServer.pyi @@ -1,7 +1,7 @@ # NB: SocketServer.pyi and socketserver.pyi must remain consistent! # Stubs for socketserver -from typing import Any, BinaryIO, Optional, Tuple, Type +from typing import Any, BinaryIO, Optional, Tuple, Type, Text, Union from socket import SocketType import sys import types @@ -15,7 +15,7 @@ class BaseServer: request_queue_size: int socket_type: int timeout: Optional[float] - def __init__(self, server_address: Tuple[str, int], + def __init__(self, server_address: Any, RequestHandlerClass: type) -> None: ... def fileno(self) -> int: ... def handle_request(self) -> None: ... @@ -38,7 +38,7 @@ class BaseServer: def __enter__(self) -> BaseServer: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[types.TracebackType]) -> bool: ... + exc_tb: Optional[types.TracebackType]) -> None: ... if sys.version_info >= (3, 3): def service_actions(self) -> None: ... @@ -54,12 +54,12 @@ class UDPServer(BaseServer): if sys.platform != 'win32': class UnixStreamServer(BaseServer): - def __init__(self, server_address: Tuple[str, int], + def __init__(self, server_address: Union[Text, bytes], RequestHandlerClass: type, bind_and_activate: bool = ...) -> None: ... class UnixDatagramServer(BaseServer): - def __init__(self, server_address: Tuple[str, int], + def __init__(self, server_address: Union[Text, bytes], RequestHandlerClass: type, bind_and_activate: bool = ...) -> None: ... diff --git a/stdlib/2/UserDict.pyi b/stdlib/2/UserDict.pyi index 965e88e03b29..1d850cfc2750 100644 --- a/stdlib/2/UserDict.pyi +++ b/stdlib/2/UserDict.pyi @@ -6,7 +6,7 @@ _VT = TypeVar('_VT') _T = TypeVar('_T') class UserDict(Dict[_KT, _VT], Generic[_KT, _VT]): - data: Mapping[_KT, _VT] + data: Dict[_KT, _VT] def __init__(self, initialdata: Mapping[_KT, _VT] = ...) -> None: ... diff --git a/stdlib/2/UserList.pyi b/stdlib/2/UserList.pyi index b8466eed1405..3c71e8292e3f 100644 --- a/stdlib/2/UserList.pyi +++ b/stdlib/2/UserList.pyi @@ -1,9 +1,10 @@ -from typing import Iterable, MutableSequence, TypeVar, Union, overload +from typing import Iterable, MutableSequence, TypeVar, Union, overload, List _T = TypeVar("_T") -_ULT = TypeVar("_ULT", bound=UserList) +_S = TypeVar("_S") class UserList(MutableSequence[_T]): + data: List[_T] def insert(self, index: int, object: _T) -> None: ... @overload def __setitem__(self, i: int, o: _T) -> None: ... @@ -14,5 +15,5 @@ class UserList(MutableSequence[_T]): @overload def __getitem__(self, i: int) -> _T: ... @overload - def __getitem__(self: _ULT, s: slice) -> _ULT: ... + def __getitem__(self: _S, s: slice) -> _S: ... def sort(self) -> None: ... diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 13a6ef968ecc..966e150897eb 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -11,7 +11,7 @@ from typing import ( ) from abc import abstractmethod, ABCMeta from ast import mod, AST -from types import TracebackType, CodeType +from types import TracebackType, CodeType, ModuleType import sys if sys.version_info >= (3,): @@ -53,30 +53,30 @@ class object: def __getattribute__(self, name: str) -> Any: ... def __delattr__(self, name: str) -> None: ... def __sizeof__(self) -> int: ... - def __reduce__(self) -> tuple: ... - def __reduce_ex__(self, protocol: int) -> tuple: ... + def __reduce__(self) -> Tuple[Any, ...]: ... + def __reduce_ex__(self, protocol: int) -> Tuple[Any, ...]: ... if sys.version_info >= (3,): def __dir__(self) -> Iterable[str]: ... if sys.version_info >= (3, 6): def __init_subclass__(cls) -> None: ... class staticmethod(object): # Special, only valid as a decorator. - __func__: Callable + __func__: Callable[..., Any] if sys.version_info >= (3,): __isabstractmethod__: bool - def __init__(self, f: Callable) -> None: ... + def __init__(self, f: Callable[..., Any]) -> None: ... def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... - def __get__(self, obj: _T, type: Optional[Type[_T]] = ...) -> Callable: ... + def __get__(self, obj: _T, type: Optional[Type[_T]] = ...) -> Callable[..., Any]: ... class classmethod(object): # Special, only valid as a decorator. - __func__: Callable + __func__: Callable[..., Any] if sys.version_info >= (3,): __isabstractmethod__: bool - def __init__(self, f: Callable) -> None: ... + def __init__(self, f: Callable[..., Any]) -> None: ... def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... - def __get__(self, obj: _T, type: Optional[Type[_T]] = ...) -> Callable: ... + def __get__(self, obj: _T, type: Optional[Type[_T]] = ...) -> Callable[..., Any]: ... class type(object): __base__: type @@ -168,7 +168,7 @@ class int: def __rtruediv__(self, x: int) -> float: ... def __rmod__(self, x: int) -> int: ... def __rdivmod__(self, x: int) -> Tuple[int, int]: ... - def __pow__(self, x: int) -> Any: ... # Return type can be int or float, depending on x. + def __pow__(self, __x: int, __modulo: Optional[int] = ...) -> Any: ... # Return type can be int or float, depending on x. def __rpow__(self, x: int) -> Any: ... def __and__(self, n: int) -> int: ... def __or__(self, n: int) -> int: ... @@ -183,7 +183,10 @@ class int: def __neg__(self) -> int: ... def __pos__(self) -> int: ... def __invert__(self) -> int: ... + def __trunc__(self) -> int: ... if sys.version_info >= (3,): + def __ceil__(self) -> int: ... + def __floor__(self) -> int: ... def __round__(self, ndigits: Optional[int] = ...) -> int: ... def __getnewargs__(self) -> Tuple[int]: ... @@ -240,11 +243,10 @@ class float: def __rdivmod__(self, x: float) -> Tuple[float, float]: ... def __rpow__(self, x: float) -> float: ... def __getnewargs__(self) -> Tuple[float]: ... + def __trunc__(self) -> int: ... if sys.version_info >= (3,): @overload - def __round__(self) -> int: ... - @overload - def __round__(self, ndigits: None) -> int: ... + def __round__(self, ndigits: None = ...) -> int: ... @overload def __round__(self, ndigits: int) -> float: ... @@ -332,7 +334,7 @@ else: end: int = ...) -> bool: ... def expandtabs(self, tabsize: int = ...) -> unicode: ... def find(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... - def format(self, *args: Any, **kwargs: Any) -> unicode: ... + def format(self, *args: object, **kwargs: object) -> unicode: ... def index(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... @@ -421,7 +423,7 @@ class str(Sequence[str], _str_base): def endswith(self, suffix: Union[Text, Tuple[Text, ...]]) -> bool: ... def expandtabs(self, tabsize: int = ...) -> str: ... def find(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... - def format(self, *args: Any, **kwargs: Any) -> str: ... + def format(self, *args: object, **kwargs: object) -> str: ... if sys.version_info >= (3,): def format_map(self, map: Mapping[str, Any]) -> str: ... def index(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... @@ -667,6 +669,8 @@ class bytearray(MutableSequence[int], ByteString): def decode(self, encoding: Text = ..., errors: Text = ...) -> str: ... def endswith(self, suffix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... def expandtabs(self, tabsize: int = ...) -> bytearray: ... + if sys.version_info < (3,): + def extend(self, iterable: Union[str, Iterable[int]]) -> None: ... if sys.version_info >= (3,): def find(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... if sys.version_info >= (3, 5): @@ -734,7 +738,7 @@ class bytearray(MutableSequence[int], ByteString): def __repr__(self) -> str: ... def __int__(self) -> int: ... def __float__(self) -> float: ... - def __hash__(self) -> int: ... + __hash__: None # type: ignore @overload def __getitem__(self, i: int) -> int: ... @overload @@ -784,9 +788,10 @@ class memoryview(Sized, Container[_mv_container_type]): c_contiguous: bool f_contiguous: bool contiguous: bool + nbytes: int def __init__(self, obj: Union[bytes, bytearray, memoryview]) -> None: ... def __enter__(self) -> memoryview: ... - def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]) -> bool: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]) -> None: ... else: def __init__(self, obj: Union[bytes, bytearray, buffer, memoryview]) -> None: ... @@ -841,13 +846,14 @@ class bool(int): def __getnewargs__(self) -> Tuple[int]: ... class slice(object): - start: Optional[int] - step: Optional[int] - stop: Optional[int] + start: Any + step: Any + stop: Any @overload - def __init__(self, stop: Optional[int]) -> None: ... + def __init__(self, stop: Any) -> None: ... @overload - def __init__(self, start: Optional[int], stop: Optional[int], step: Optional[int] = ...) -> None: ... + def __init__(self, start: Any, stop: Any, step: Any = ...) -> None: ... + __hash__: None # type: ignore def indices(self, len: int) -> Tuple[int, int, int]: ... class tuple(Sequence[_T_co], Generic[_T_co]): @@ -863,7 +869,10 @@ class tuple(Sequence[_T_co], Generic[_T_co]): def __le__(self, x: Tuple[_T_co, ...]) -> bool: ... def __gt__(self, x: Tuple[_T_co, ...]) -> bool: ... def __ge__(self, x: Tuple[_T_co, ...]) -> bool: ... + @overload def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... + @overload + def __add__(self, x: Tuple[Any, ...]) -> Tuple[Any, ...]: ... def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... def count(self, x: Any) -> int: ... @@ -876,9 +885,9 @@ class function: # TODO not defined in builtins! __name__: str __module__: str + __code__: CodeType if sys.version_info >= (3,): __qualname__: str - __code__: CodeType __annotations__: Dict[str, Any] class list(MutableSequence[_T], Generic[_T]): @@ -905,7 +914,7 @@ class list(MutableSequence[_T], Generic[_T]): def __len__(self) -> int: ... def __iter__(self) -> Iterator[_T]: ... def __str__(self) -> str: ... - def __hash__(self) -> int: ... + __hash__: None # type: ignore @overload def __getitem__(self, i: int) -> _T: ... @overload @@ -979,6 +988,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __delitem__(self, v: _KT) -> None: ... def __iter__(self) -> Iterator[_KT]: ... def __str__(self) -> str: ... + __hash__: None # type: ignore class set(MutableSet[_T], Generic[_T]): def __init__(self, iterable: Iterable[_T] = ...) -> None: ... @@ -1015,6 +1025,7 @@ class set(MutableSet[_T], Generic[_T]): def __lt__(self, s: AbstractSet[object]) -> bool: ... def __ge__(self, s: AbstractSet[object]) -> bool: ... def __gt__(self, s: AbstractSet[object]) -> bool: ... + __hash__: None # type: ignore class frozenset(AbstractSet[_T], Generic[_T]): def __init__(self, iterable: Iterable[_T] = ...) -> None: ... @@ -1124,7 +1135,7 @@ if sys.version_info >= (3, 6): # See https://github.com/python/typeshed/pull/991#issuecomment-288160993 class _PathLike(Generic[AnyStr]): def __fspath__(self) -> AnyStr: ... - def compile(source: Union[str, bytes, mod, AST], filename: Union[str, bytes, _PathLike], mode: str, flags: int = ..., dont_inherit: int = ..., optimize: int = ...) -> Any: ... + def compile(source: Union[str, bytes, mod, AST], filename: Union[str, bytes, _PathLike[Any]], mode: str, flags: int = ..., dont_inherit: int = ..., optimize: int = ...) -> Any: ... elif sys.version_info >= (3,): def compile(source: Union[str, bytes, mod, AST], filename: Union[str, bytes], mode: str, flags: int = ..., dont_inherit: int = ..., optimize: int = ...) -> Any: ... else: @@ -1180,9 +1191,11 @@ else: @overload def iter(__iterable: Iterable[_T]) -> Iterator[_T]: ... @overload -def iter(__function: Callable[[], _T], __sentinel: _T) -> Iterator[_T]: ... -def isinstance(__o: object, __t: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... -def issubclass(__cls: type, __classinfo: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... +def iter(__function: Callable[[], Optional[_T]], __sentinel: None) -> Iterator[_T]: ... +@overload +def iter(__function: Callable[[], Any], __sentinel: Any) -> Iterator[Any]: ... +def isinstance(__o: object, __t: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]) -> bool: ... +def issubclass(__cls: type, __classinfo: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]) -> bool: ... def len(__o: Sized) -> int: ... if sys.version_info >= (3,): def license() -> None: ... @@ -1318,7 +1331,7 @@ def next(__i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ... def oct(__i: Union[int, _SupportsIndex]) -> str: ... if sys.version_info >= (3, 6): - def open(file: Union[str, bytes, int, _PathLike], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., + def open(file: Union[str, bytes, int, _PathLike[Any]], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., errors: Optional[str] = ..., newline: Optional[str] = ..., closefd: bool = ..., opener: Optional[Callable[[str, int], int]] = ...) -> IO[Any]: ... elif sys.version_info >= (3,): @@ -1390,7 +1403,7 @@ if sys.version_info >= (3,): else: def sorted(__iterable: Iterable[_T], *, cmp: Callable[[_T, _T], int] = ..., - key: Callable[[_T], Any] = ..., + key: Optional[Callable[[_T], Any]] = ..., reverse: bool = ...) -> List[_T]: ... @overload def sum(__iterable: Iterable[_T]) -> Union[_T, int]: ... @@ -1436,8 +1449,10 @@ else: def zip(__iter1: Iterable[Any], __iter2: Iterable[Any], __iter3: Iterable[Any], __iter4: Iterable[Any], __iter5: Iterable[Any], __iter6: Iterable[Any], *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... -def __import__(name: Text, globals: Dict[str, Any] = ..., locals: Dict[str, Any] = ..., - fromlist: List[str] = ..., level: int = ...) -> Any: ... +def __import__(name: Text, globals: Optional[Mapping[str, Any]] = ..., + locals: Optional[Mapping[str, Any]] = ..., + fromlist: Sequence[str] = ..., + level: int = ...) -> ModuleType: ... # Actually the type of Ellipsis is , but since it's # not exposed anywhere under that name, we make it private here. @@ -1467,6 +1482,8 @@ class BaseException(object): __suppress_context__: bool __traceback__: Optional[TracebackType] def __init__(self, *args: object) -> None: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... if sys.version_info < (3,): def __getitem__(self, i: int) -> Any: ... def __getslice__(self, start: int, stop: int) -> Tuple[Any, ...]: ... @@ -1523,7 +1540,7 @@ class SyntaxError(_StandardError): msg: str lineno: int offset: Optional[int] - text: str + text: Optional[str] filename: str class SystemError(_StandardError): ... class TypeError(_StandardError): ... @@ -1612,7 +1629,7 @@ if sys.version_info < (3,): def next(self) -> str: ... def read(self, n: int = ...) -> str: ... def __enter__(self) -> BinaryIO: ... - def __exit__(self, t: Optional[type] = ..., exc: Optional[BaseException] = ..., tb: Optional[Any] = ...) -> bool: ... + def __exit__(self, t: Optional[type] = ..., exc: Optional[BaseException] = ..., tb: Optional[Any] = ...) -> Optional[bool]: ... def flush(self) -> None: ... def fileno(self) -> int: ... def isatty(self) -> bool: ... diff --git a/stdlib/2/_collections.pyi b/stdlib/2/_collections.pyi index e24d4053b233..9736a49b9366 100644 --- a/stdlib/2/_collections.pyi +++ b/stdlib/2/_collections.pyi @@ -1,18 +1,19 @@ """Stub file for the '_collections' module.""" -from typing import Any, Generic, Iterator, TypeVar, Optional, Union - -class defaultdict(dict): - default_factory: None - def __init__(self, default: Any = ..., init: Any = ...) -> None: ... - def __missing__(self, key) -> Any: - raise KeyError() - def __copy__(self) -> defaultdict: ... - def copy(self) -> defaultdict: ... +from typing import Any, Callable, Dict, Generic, Iterator, TypeVar, Optional, Union +_K = TypeVar("_K") +_V = TypeVar("_V") _T = TypeVar('_T') _T2 = TypeVar('_T2') +class defaultdict(Dict[_K, _V]): + default_factory: None + def __init__(self, __default_factory: Callable[[], _V] = ..., init: Any = ...) -> None: ... + def __missing__(self, key: _K) -> _V: ... + def __copy__(self: _T) -> _T: ... + def copy(self: _T) -> _T: ... + class deque(Generic[_T]): maxlen: Optional[int] def __init__(self, iterable: Iterator[_T] = ..., maxlen: int = ...) -> None: ... diff --git a/stdlib/2/_functools.pyi b/stdlib/2/_functools.pyi index 064188505d95..876974e45429 100644 --- a/stdlib/2/_functools.pyi +++ b/stdlib/2/_functools.pyi @@ -3,10 +3,6 @@ from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Tuple, overload _T = TypeVar("_T") -_T2 = TypeVar("_T2") -_T3 = TypeVar("_T3") -_T4 = TypeVar("_T4") -_T5 = TypeVar("_T5") _S = TypeVar("_S") @overload @@ -16,72 +12,9 @@ def reduce(function: Callable[[_T, _T], _T], def reduce(function: Callable[[_T, _S], _T], sequence: Iterable[_S], initial: _T) -> _T: ... -@overload -def partial(__func: Callable[[_T], _S], __arg: _T) -> Callable[[], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2], _S], __arg: _T) -> Callable[[_T2], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3], _S], __arg: _T) -> Callable[[_T2, _T3], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4], _S], __arg: _T) -> Callable[[_T2, _T3, _T4], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4, _T5], _S], __arg: _T) -> Callable[[_T2, _T3, _T4, _T5], _S]: ... - -@overload -def partial(__func: Callable[[_T, _T2], _S], - __arg1: _T, - __arg2: _T2) -> Callable[[], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3], _S], - __arg1: _T, - __arg2: _T2) -> Callable[[_T3], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4], _S], - __arg1: _T, - __arg2: _T2) -> Callable[[_T3, _T4], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4, _T5], _S], - __arg1: _T, - __arg2: _T2) -> Callable[[_T3, _T4, _T5], _S]: ... - -@overload -def partial(__func: Callable[[_T, _T2, _T3], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3) -> Callable[[], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3) -> Callable[[_T4], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4, _T5], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3) -> Callable[[_T4, _T5], _S]: ... - -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3, - __arg4: _T4) -> Callable[[], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4, _T5], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3, - __arg4: _T4) -> Callable[[_T5], _S]: ... - -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4, _T5], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3, - __arg4: _T4, - __arg5: _T5) -> Callable[[], _S]: ... - -@overload -def partial(__func: Callable[..., _S], - *args: Any, - **kwargs: Any) -> Callable[..., _S]: ... +class partial(object): + func: Callable[..., Any] + args: Tuple[Any, ...] + keywords: Dict[str, Any] + def __init__(self, func: Callable[..., Any], *args: Any, **kwargs: Any) -> None: ... + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... diff --git a/stdlib/2/_hotshot.pyi b/stdlib/2/_hotshot.pyi index 8a9c8d72bdfd..f75acf24323a 100644 --- a/stdlib/2/_hotshot.pyi +++ b/stdlib/2/_hotshot.pyi @@ -14,7 +14,7 @@ def logreader(a: str) -> LogReaderType: def profiler(a: str, *args, **kwargs) -> Any: raise IOError() -def resolution() -> tuple: ... +def resolution() -> Tuple[Any, ...]: ... class LogReaderType(object): diff --git a/stdlib/2/_io.pyi b/stdlib/2/_io.pyi index e4e15cbfd90f..e8e448f2c8ed 100644 --- a/stdlib/2/_io.pyi +++ b/stdlib/2/_io.pyi @@ -16,7 +16,7 @@ _T = TypeVar("_T") class _IOBase(BinaryIO): @property def closed(self) -> bool: ... - def _checkClosed(self) -> None: ... + def _checkClosed(self, msg: Optional[str] = ...) -> None: ... # undocumented def _checkReadable(self) -> None: ... def _checkSeekable(self) -> None: ... def _checkWritable(self) -> None: ... @@ -32,7 +32,7 @@ class _IOBase(BinaryIO): def truncate(self, size: Optional[int] = ...) -> int: ... def writable(self) -> bool: ... def __enter__(self: _T) -> _T: ... - def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[Any]) -> bool: ... + def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[Any]) -> Optional[bool]: ... def __iter__(self: _T) -> _T: ... # The parameter type of writelines[s]() is determined by that of write(): def writelines(self, lines: Iterable[bytes]) -> None: ... @@ -84,8 +84,8 @@ class BufferedWriter(_BufferedIOBase): class BytesIO(_BufferedIOBase): def __init__(self, initial_bytes: bytes = ...) -> None: ... - def __setstate__(self, tuple) -> None: ... - def __getstate__(self) -> tuple: ... + def __setstate__(self, state: Tuple[Any, ...]) -> None: ... + def __getstate__(self) -> Tuple[Any, ...]: ... # BytesIO does not contain a "name" field. This workaround is necessary # to allow BytesIO sub-classes to add this field, as it is defined # as a read-only property on IO[]. @@ -129,7 +129,7 @@ class _TextIOBase(TextIO): def _checkSeekable(self) -> None: ... def _checkWritable(self) -> None: ... def close(self) -> None: ... - def detach(self) -> IO: ... + def detach(self) -> IO[Any]: ... def fileno(self) -> int: ... def flush(self) -> None: ... def isatty(self) -> bool: ... @@ -146,7 +146,7 @@ class _TextIOBase(TextIO): def write(self, pbuf: unicode) -> int: ... def writelines(self, lines: Iterable[unicode]) -> None: ... def __enter__(self: _T) -> _T: ... - def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[Any]) -> bool: ... + def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[Any]) -> Optional[bool]: ... def __iter__(self: _T) -> _T: ... class StringIO(_TextIOBase): @@ -154,8 +154,8 @@ class StringIO(_TextIOBase): def __init__(self, initial_value: Optional[unicode] = ..., newline: Optional[unicode] = ...) -> None: ... - def __setstate__(self, state: tuple) -> None: ... - def __getstate__(self) -> tuple: ... + def __setstate__(self, state: Tuple[Any, ...]) -> None: ... + def __getstate__(self) -> Tuple[Any, ...]: ... # StringIO does not contain a "name" field. This workaround is necessary # to allow StringIO sub-classes to add this field, as it is defined # as a read-only property on IO[]. @@ -167,12 +167,15 @@ class TextIOWrapper(_TextIOBase): line_buffering: bool buffer: BinaryIO _CHUNK_SIZE: int - def __init__(self, buffer: IO, - encoding: Optional[Text] = ..., - errors: Optional[Text] = ..., - newline: Optional[Text] = ..., - line_buffering: bool = ..., - write_through: bool = ...) -> None: ... + def __init__( + self, + buffer: IO[Any], + encoding: Optional[Text] = ..., + errors: Optional[Text] = ..., + newline: Optional[Text] = ..., + line_buffering: bool = ..., + write_through: bool = ..., + ) -> None: ... def open(file: Union[str, unicode, int], mode: Text = ..., diff --git a/stdlib/2/_json.pyi b/stdlib/2/_json.pyi index 028b7b229a89..f8bd265aca13 100644 --- a/stdlib/2/_json.pyi +++ b/stdlib/2/_json.pyi @@ -1,17 +1,7 @@ -"""Stub file for the '_json' module.""" -# This is an autogenerated file. It serves as a starting point -# for a more precise manual annotation of this module. -# Feel free to edit the source below, but remove this header when you do. - -from typing import Any, List, Tuple, Dict, Generic - -def encode_basestring_ascii(*args, **kwargs) -> str: - raise TypeError() - -def scanstring(a, b, *args, **kwargs) -> tuple: - raise TypeError() +from typing import Any, List, Tuple, Dict, Generic, Tuple +def encode_basestring_ascii(*args, **kwargs) -> str: ... +def scanstring(a, b, *args, **kwargs) -> Tuple[Any, ...]: ... class Encoder(object): ... - class Scanner(object): ... diff --git a/stdlib/2/_socket.pyi b/stdlib/2/_socket.pyi index 8d02bdee3f16..31ba7638afc6 100644 --- a/stdlib/2/_socket.pyi +++ b/stdlib/2/_socket.pyi @@ -253,17 +253,17 @@ class SocketType(object): timeout: float def __init__(self, family: int = ..., type: int = ..., proto: int = ...) -> None: ... - def accept(self) -> Tuple[SocketType, tuple]: ... - def bind(self, address: tuple) -> None: ... + def accept(self) -> Tuple[SocketType, Tuple[Any, ...]]: ... + def bind(self, address: Tuple[Any, ...]) -> None: ... def close(self) -> None: ... - def connect(self, address: tuple) -> None: + def connect(self, address: Tuple[Any, ...]) -> None: raise gaierror raise timeout - def connect_ex(self, address: tuple) -> int: ... + def connect_ex(self, address: Tuple[Any, ...]) -> int: ... def dup(self) -> SocketType: ... def fileno(self) -> int: ... - def getpeername(self) -> tuple: ... - def getsockname(self) -> tuple: ... + def getpeername(self) -> Tuple[Any, ...]: ... + def getsockname(self) -> Tuple[Any, ...]: ... def getsockopt(self, level: int, option: int, buffersize: int = ...) -> str: ... def gettimeout(self) -> float: ... def listen(self, backlog: int) -> None: @@ -271,16 +271,16 @@ class SocketType(object): def makefile(self, mode: str = ..., buffersize: int = ...) -> IO[Any]: ... def recv(self, buffersize: int, flags: int = ...) -> str: ... def recv_into(self, buffer: bytearray, nbytes: int = ..., flags: int = ...) -> int: ... - def recvfrom(self, buffersize: int, flags: int = ...) -> tuple: + def recvfrom(self, buffersize: int, flags: int = ...) -> Tuple[Any, ...]: raise error def recvfrom_into(self, buffer: bytearray, nbytes: int = ..., flags: int = ...) -> int: ... def send(self, data: str, flags: int = ...) -> int: ... def sendall(self, data: str, flags: int = ...) -> None: ... @overload - def sendto(self, data: str, address: tuple) -> int: ... + def sendto(self, data: str, address: Tuple[Any, ...]) -> int: ... @overload - def sendto(self, data: str, flags: int, address: tuple) -> int: ... + def sendto(self, data: str, flags: int, address: Tuple[Any, ...]) -> int: ... def setblocking(self, flag: bool) -> None: ... def setsockopt(self, level: int, option: int, value: Union[int, str]) -> None: ... def settimeout(self, value: Optional[float]) -> None: ... diff --git a/stdlib/2/_sre.pyi b/stdlib/2/_sre.pyi index 0692b4c17085..5ab7ed124da4 100644 --- a/stdlib/2/_sre.pyi +++ b/stdlib/2/_sre.pyi @@ -21,6 +21,8 @@ class SRE_Match(object): def groups(self) -> Tuple[Optional[str], ...]: ... def span(self) -> Tuple[int, int]: raise IndexError() + @property + def regs(self) -> Tuple[Tuple[int, int], ...]: ... # undocumented class SRE_Scanner(object): pattern: str @@ -33,14 +35,14 @@ class SRE_Pattern(object): groups: int groupindex: Mapping[str, int] indexgroup: Sequence[int] - def findall(self, source: str, pos: int = ..., endpos: int = ...) -> List[Union[tuple, str]]: ... - def finditer(self, source: str, pos: int = ..., endpos: int = ...) -> Iterable[Union[tuple, str]]: ... + def findall(self, source: str, pos: int = ..., endpos: int = ...) -> List[Union[Tuple[Any, ...], str]]: ... + def finditer(self, source: str, pos: int = ..., endpos: int = ...) -> Iterable[Union[Tuple[Any, ...], str]]: ... def match(self, pattern, pos: int = ..., endpos: int = ...) -> SRE_Match: ... def scanner(self, s: str, start: int = ..., end: int = ...) -> SRE_Scanner: ... def search(self, pattern, pos: int = ..., endpos: int = ...) -> SRE_Match: ... def split(self, source: str, maxsplit: int = ...) -> List[Optional[str]]: ... - def sub(self, repl: str, string: str, count: int = ...) -> tuple: ... - def subn(self, repl: str, string: str, count: int = ...) -> tuple: ... + def sub(self, repl: str, string: str, count: int = ...) -> Tuple[Any, ...]: ... + def subn(self, repl: str, string: str, count: int = ...) -> Tuple[Any, ...]: ... def compile(pattern: str, flags: int, code: List[int], groups: int = ..., diff --git a/stdlib/2/_warnings.pyi b/stdlib/2/_warnings.pyi index 9609faa4ec1d..192fbd21355a 100644 --- a/stdlib/2/_warnings.pyi +++ b/stdlib/2/_warnings.pyi @@ -1,11 +1,16 @@ -from typing import Any, List, Optional, Type +from typing import Any, Dict, List, Optional, Tuple, Type default_action: str -filters: List[tuple] -once_registry: dict +filters: List[Tuple[Any, ...]] +once_registry: Dict[Any, Any] def warn(message: Warning, category: Optional[Type[Warning]] = ..., stacklevel: int = ...) -> None: ... -def warn_explicit(message: Warning, category: Optional[Type[Warning]], - filename: str, lineno: int, - module: Any = ..., registry: dict = ..., - module_globals: dict = ...) -> None: ... +def warn_explicit( + message: Warning, + category: Optional[Type[Warning]], + filename: str, + lineno: int, + module: Any = ..., + registry: Dict[Any, Any] = ..., + module_globals: Dict[Any, Any] = ..., +) -> None: ... diff --git a/stdlib/2/abc.pyi b/stdlib/2/abc.pyi index 746f5306fcd6..64fbb50bc706 100644 --- a/stdlib/2/abc.pyi +++ b/stdlib/2/abc.pyi @@ -1,18 +1,20 @@ -from typing import Any, Dict, Set, Tuple, Type +from typing import Any, Callable, Dict, Set, Tuple, Type, TypeVar import _weakrefset +_FuncT = TypeVar('_FuncT', bound=Callable[..., Any]) + # NOTE: mypy has special processing for ABCMeta and abstractmethod. -def abstractmethod(funcobj: Any) -> Any: ... +def abstractmethod(funcobj: _FuncT) -> _FuncT: ... class ABCMeta(type): # TODO: FrozenSet __abstractmethods__: Set[Any] - _abc_cache: _weakrefset.WeakSet + _abc_cache: _weakrefset.WeakSet[Any] _abc_invalidation_counter: int - _abc_negative_cache: _weakrefset.WeakSet + _abc_negative_cache: _weakrefset.WeakSet[Any] _abc_negative_cache_version: int - _abc_registry: _weakrefset.WeakSet + _abc_registry: _weakrefset.WeakSet[Any] def __init__(self, name: str, bases: Tuple[type, ...], namespace: Dict[Any, Any]) -> None: ... def __instancecheck__(cls: ABCMeta, instance: Any) -> Any: ... def __subclasscheck__(cls: ABCMeta, subclass: Any) -> Any: ... diff --git a/stdlib/2/collections.pyi b/stdlib/2/collections.pyi index 0daa118e53a7..988e9202f674 100644 --- a/stdlib/2/collections.pyi +++ b/stdlib/2/collections.pyi @@ -1,5 +1,5 @@ # These are not exported. -from typing import Dict, Generic, TypeVar, Tuple, overload, Type, Optional, List, Union, Reversible +from typing import Any, Dict, Generic, TypeVar, Tuple, overload, Type, Optional, List, Union, Reversible # These are exported. from typing import ( @@ -28,7 +28,7 @@ _VT = TypeVar('_VT') # namedtuple is special-cased in the type checker; the initializer is ignored. def namedtuple(typename: Union[str, unicode], field_names: Union[str, unicode, Iterable[Union[str, unicode]]], - verbose: bool = ..., rename: bool = ...) -> Type[tuple]: ... + verbose: bool = ..., rename: bool = ...) -> Type[Tuple[Any, ...]]: ... class deque(Sized, Iterable[_T], Reversible[_T], Generic[_T]): def __init__(self, iterable: Iterable[_T] = ..., @@ -56,8 +56,6 @@ class deque(Sized, Iterable[_T], Reversible[_T], Generic[_T]): def __reversed__(self) -> Iterator[_T]: ... def __iadd__(self: _S, iterable: Iterable[_T]) -> _S: ... -_CounterT = TypeVar('_CounterT', bound=Counter) - class Counter(Dict[_T, int], Generic[_T]): @overload def __init__(self, **kwargs: int) -> None: ... @@ -65,7 +63,7 @@ class Counter(Dict[_T, int], Generic[_T]): def __init__(self, mapping: Mapping[_T, int]) -> None: ... @overload def __init__(self, iterable: Iterable[_T]) -> None: ... - def copy(self: _CounterT) -> _CounterT: ... + def copy(self: _S) -> _S: ... def elements(self) -> Iterator[_T]: ... def most_common(self, n: Optional[int] = ...) -> List[Tuple[_T, int]]: ... @overload @@ -93,15 +91,11 @@ class Counter(Dict[_T, int], Generic[_T]): def __iand__(self, other: Counter[_T]) -> Counter[_T]: ... def __ior__(self, other: Counter[_T]) -> Counter[_T]: ... -_OrderedDictT = TypeVar('_OrderedDictT', bound=OrderedDict) - class OrderedDict(Dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]): def popitem(self, last: bool = ...) -> Tuple[_KT, _VT]: ... - def copy(self: _OrderedDictT) -> _OrderedDictT: ... + def copy(self: _S) -> _S: ... def __reversed__(self) -> Iterator[_KT]: ... -_DefaultDictT = TypeVar('_DefaultDictT', bound=defaultdict) - class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): default_factory: Callable[[], _VT] @overload @@ -123,4 +117,4 @@ class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): def __init__(self, default_factory: Optional[Callable[[], _VT]], iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... def __missing__(self, key: _KT) -> _VT: ... - def copy(self: _DefaultDictT) -> _DefaultDictT: ... + def copy(self: _S) -> _S: ... diff --git a/stdlib/2/compileall.pyi b/stdlib/2/compileall.pyi index c3e861e1e99d..2b7046d8260c 100644 --- a/stdlib/2/compileall.pyi +++ b/stdlib/2/compileall.pyi @@ -1,10 +1,19 @@ # Stubs for compileall (Python 2) -from typing import Optional, Pattern, Union +from typing import Any, Optional, Pattern, Union _Path = Union[str, bytes] # rx can be any object with a 'search' method; once we have Protocols we can change the type -def compile_dir(dir: _Path, maxlevels: int = ..., ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern] = ..., quiet: int = ...) -> int: ... -def compile_file(fullname: _Path, ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern] = ..., quiet: int = ...) -> int: ... +def compile_dir( + dir: _Path, + maxlevels: int = ..., + ddir: Optional[_Path] = ..., + force: bool = ..., + rx: Optional[Pattern[Any]] = ..., + quiet: int = ..., +) -> int: ... +def compile_file( + fullname: _Path, ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern[Any]] = ..., quiet: int = ..., +) -> int: ... def compile_path(skip_curdir: bool = ..., maxlevels: int = ..., force: bool = ..., quiet: int = ...) -> int: ... diff --git a/stdlib/2/cookielib.pyi b/stdlib/2/cookielib.pyi index 5bc4781cece8..abbf29894635 100644 --- a/stdlib/2/cookielib.pyi +++ b/stdlib/2/cookielib.pyi @@ -105,6 +105,8 @@ class FileCookieJar(CookieJar): def load(self, filename: Optional[Any] = ..., ignore_discard: bool = ..., ignore_expires: bool = ...): ... def revert(self, filename: Optional[Any] = ..., ignore_discard: bool = ..., ignore_expires: bool = ...): ... +class LWPCookieJar(FileCookieJar): + def as_lwp_str(self, ignore_discard: bool = ..., ignore_expires: bool = ...) -> str: ... # undocumented + MozillaCookieJar = FileCookieJar -LWPCookieJar = FileCookieJar def lwp_cookie_str(cookie: Cookie) -> str: ... diff --git a/stdlib/2/email/iterators.pyi b/stdlib/2/email/iterators.pyi index 48aaf06a6f67..5002644117a4 100644 --- a/stdlib/2/email/iterators.pyi +++ b/stdlib/2/email/iterators.pyi @@ -1,5 +1,5 @@ -from typing import Generator +from typing import Any, Generator -def walk(self) -> Generator: ... -def body_line_iterator(msg, decode: bool = ...) -> Generator: ... -def typed_subpart_iterator(msg, maintype=..., subtype=...) -> Generator: ... +def walk(self) -> Generator[Any, Any, Any]: ... +def body_line_iterator(msg, decode: bool = ...) -> Generator[Any, Any, Any]: ... +def typed_subpart_iterator(msg, maintype=..., subtype=...) -> Generator[Any, Any, Any]: ... diff --git a/stdlib/2/email/message.pyi b/stdlib/2/email/message.pyi index bd3c6220d6e1..642bba7c0102 100644 --- a/stdlib/2/email/message.pyi +++ b/stdlib/2/email/message.pyi @@ -1,4 +1,4 @@ -from typing import Generator +from typing import Any, Generator class Message: preamble = ... @@ -42,4 +42,4 @@ class Message: def set_boundary(self, boundary) -> None: ... def get_content_charset(self, failobj=...): ... def get_charsets(self, failobj=...): ... - def walk(self) -> Generator: ... + def walk(self) -> Generator[Any, Any, Any]: ... diff --git a/stdlib/2/functools.pyi b/stdlib/2/functools.pyi index c12af8fe7ed3..5d65d23c9d5b 100644 --- a/stdlib/2/functools.pyi +++ b/stdlib/2/functools.pyi @@ -9,10 +9,6 @@ from collections import namedtuple _AnyCallable = Callable[..., Any] _T = TypeVar("_T") -_T2 = TypeVar("_T2") -_T3 = TypeVar("_T3") -_T4 = TypeVar("_T4") -_T5 = TypeVar("_T5") _S = TypeVar("_S") @overload def reduce(function: Callable[[_T, _T], _T], @@ -30,72 +26,9 @@ def wraps(wrapped: _AnyCallable, assigned: Sequence[str] = ..., updated: Sequenc def total_ordering(cls: type) -> type: ... def cmp_to_key(mycmp: Callable[[_T, _T], int]) -> Callable[[_T], Any]: ... -@overload -def partial(__func: Callable[[_T], _S], __arg: _T) -> Callable[[], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2], _S], __arg: _T) -> Callable[[_T2], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3], _S], __arg: _T) -> Callable[[_T2, _T3], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4], _S], __arg: _T) -> Callable[[_T2, _T3, _T4], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4, _T5], _S], __arg: _T) -> Callable[[_T2, _T3, _T4, _T5], _S]: ... - -@overload -def partial(__func: Callable[[_T, _T2], _S], - __arg1: _T, - __arg2: _T2) -> Callable[[], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3], _S], - __arg1: _T, - __arg2: _T2) -> Callable[[_T3], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4], _S], - __arg1: _T, - __arg2: _T2) -> Callable[[_T3, _T4], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4, _T5], _S], - __arg1: _T, - __arg2: _T2) -> Callable[[_T3, _T4, _T5], _S]: ... - -@overload -def partial(__func: Callable[[_T, _T2, _T3], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3) -> Callable[[], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3) -> Callable[[_T4], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4, _T5], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3) -> Callable[[_T4, _T5], _S]: ... - -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3, - __arg4: _T4) -> Callable[[], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4, _T5], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3, - __arg4: _T4) -> Callable[[_T5], _S]: ... - -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4, _T5], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3, - __arg4: _T4, - __arg5: _T5) -> Callable[[], _S]: ... - -@overload -def partial(__func: Callable[..., _S], - *args: Any, - **kwargs: Any) -> Callable[..., _S]: ... +class partial(Generic[_T]): + func = ... # Callable[..., _T] + args: Tuple[Any, ...] + keywords: Dict[str, Any] + def __init__(self, func: Callable[..., _T], *args: Any, **kwargs: Any) -> None: ... + def __call__(self, *args: Any, **kwargs: Any) -> _T: ... diff --git a/stdlib/2/heapq.pyi b/stdlib/2/heapq.pyi index 00abb31a6c59..488221c7cf94 100644 --- a/stdlib/2/heapq.pyi +++ b/stdlib/2/heapq.pyi @@ -1,7 +1,10 @@ -from typing import TypeVar, List, Iterable, Any, Callable, Optional +from typing import TypeVar, List, Iterable, Any, Callable, Optional, Protocol _T = TypeVar('_T') +class _Sortable(Protocol): + def __lt__(self: _T, other: _T) -> bool: ... + def cmp_lt(x, y) -> bool: ... def heappush(heap: List[_T], item: _T) -> None: ... def heappop(heap: List[_T]) -> _T: @@ -12,5 +15,6 @@ def heapreplace(heap: List[_T], item: _T) -> _T: raise IndexError() # if heap is empty def merge(*iterables: Iterable[_T]) -> Iterable[_T]: ... def nlargest(n: int, iterable: Iterable[_T], - key: Optional[Callable[[_T], Any]] = ...) -> List[_T]: ... -def nsmallest(n: int, iterable: Iterable[_T]) -> List[_T]: ... + key: Optional[Callable[[_T], _Sortable]] = ...) -> List[_T]: ... +def nsmallest(n: int, iterable: Iterable[_T], + key: Optional[Callable[[_T], _Sortable]] = ...) -> List[_T]: ... diff --git a/stdlib/2/htmlentitydefs.pyi b/stdlib/2/htmlentitydefs.pyi index 6ae88e757212..749b3039dfc3 100644 --- a/stdlib/2/htmlentitydefs.pyi +++ b/stdlib/2/htmlentitydefs.pyi @@ -1,5 +1,5 @@ -from typing import Any, Mapping +from typing import Dict -name2codepoint: Mapping[str, int] -codepoint2name: Mapping[int, str] -entitydefs: Mapping[str, str] +name2codepoint: Dict[str, int] +codepoint2name: Dict[int, str] +entitydefs: Dict[str, str] diff --git a/stdlib/2/inspect.pyi b/stdlib/2/inspect.pyi index 8bc2eacb114f..67be3a41a7c9 100644 --- a/stdlib/2/inspect.pyi +++ b/stdlib/2/inspect.pyi @@ -1,4 +1,4 @@ -from types import CodeType, TracebackType, FrameType, ModuleType +from types import CodeType, TracebackType, FrameType, FunctionType, MethodType, ModuleType from typing import Any, Dict, Callable, List, NamedTuple, Optional, Sequence, Tuple, Type, Union # Types and members @@ -52,31 +52,28 @@ def isgetsetdescriptor(object: object) -> bool: ... def ismemberdescriptor(object: object) -> bool: ... # Retrieving source code -def findsource(object: object) -> Tuple[List[str], int]: ... -def getabsfile(object: object) -> str: ... +_SourceObjectType = Union[ModuleType, Type[Any], MethodType, FunctionType, TracebackType, FrameType, CodeType] + +def findsource(object: _SourceObjectType) -> Tuple[List[str], int]: ... +def getabsfile(object: _SourceObjectType) -> str: ... def getblock(lines: Sequence[str]) -> Sequence[str]: ... -def getdoc(object: object) -> str: ... -def getcomments(object: object) -> str: ... -def getfile(object: object) -> str: ... -def getmodule(object: object) -> ModuleType: ... -def getsourcefile(object: object) -> str: ... -# TODO restrict to "module, class, method, function, traceback, frame, -# or code object" -def getsourcelines(object: object) -> Tuple[List[str], int]: ... -# TODO restrict to "a module, class, method, function, traceback, frame, -# or code object" -def getsource(object: object) -> str: ... +def getdoc(object: object) -> Optional[str]: ... +def getcomments(object: object) -> Optional[str]: ... +def getfile(object: _SourceObjectType) -> str: ... +def getmodule(object: object) -> Optional[ModuleType]: ... +def getsourcefile(object: _SourceObjectType) -> Optional[str]: ... +def getsourcelines(object: _SourceObjectType) -> Tuple[List[str], int]: ... +def getsource(object: _SourceObjectType) -> str: ... def cleandoc(doc: str) -> str: ... def indentsize(line: str) -> int: ... # Classes and functions -def getclasstree(classes: List[type], unique: bool = ...) -> List[ - Union[Tuple[type, Tuple[type, ...]], list]]: ... +def getclasstree(classes: List[type], unique: bool = ...) -> List[Union[Tuple[type, Tuple[type, ...]], List[Any]]]: ... ArgSpec = NamedTuple('ArgSpec', [('args', List[str]), ('varargs', Optional[str]), ('keywords', Optional[str]), - ('defaults', tuple), + ('defaults', Tuple[Any, ...]), ]) ArgInfo = NamedTuple('ArgInfo', [('args', List[str]), @@ -110,12 +107,12 @@ Traceback = NamedTuple( ('filename', str), ('lineno', int), ('function', str), - ('code_context', List[str]), - ('index', int), + ('code_context', Optional[List[str]]), + ('index', Optional[int]), ] ) -_FrameInfo = Tuple[FrameType, str, int, str, List[str], int] +_FrameInfo = Tuple[FrameType, str, int, str, Optional[List[str]], Optional[int]] def getouterframes(frame: FrameType, context: int = ...) -> List[_FrameInfo]: ... def getframeinfo(frame: Union[FrameType, TracebackType], context: int = ...) -> Traceback: ... diff --git a/stdlib/2/itertools.pyi b/stdlib/2/itertools.pyi index 1c8522c87663..1d5b4ee84827 100644 --- a/stdlib/2/itertools.pyi +++ b/stdlib/2/itertools.pyi @@ -14,8 +14,6 @@ def cycle(iterable: Iterable[_T]) -> Iterator[_T]: ... def repeat(object: _T, times: int = ...) -> Iterator[_T]: ... -def accumulate(iterable: Iterable[_T]) -> Iterator[_T]: ... - class chain(Iterator[_T], Generic[_T]): def __init__(self, *iterables: Iterable[_T]) -> None: ... def next(self) -> _T: ... diff --git a/stdlib/2/json.pyi b/stdlib/2/json.pyi index 9cc151b27f34..578e0cd0c507 100644 --- a/stdlib/2/json.pyi +++ b/stdlib/2/json.pyi @@ -1,4 +1,4 @@ -from typing import Any, IO, Optional, Tuple, Callable, Dict, List, Union, Text, Protocol +from typing import Any, IO, Optional, Tuple, Callable, Dict, List, Union, Text, Protocol, Type class JSONDecodeError(ValueError): def dumps(self, obj: Any) -> str: ... @@ -11,7 +11,7 @@ def dumps(obj: Any, ensure_ascii: bool = ..., check_circular: bool = ..., allow_nan: bool = ..., - cls: Any = ..., + cls: Optional[Type[JSONEncoder]] = ..., indent: Optional[int] = ..., separators: Optional[Tuple[str, str]] = ..., encoding: str = ..., @@ -25,7 +25,7 @@ def dump(obj: Any, ensure_ascii: bool = ..., check_circular: bool = ..., allow_nan: bool = ..., - cls: Any = ..., + cls: Optional[Type[JSONEncoder]] = ..., indent: Optional[int] = ..., separators: Optional[Tuple[str, str]] = ..., encoding: str = ..., @@ -35,8 +35,8 @@ def dump(obj: Any, def loads(s: Union[Text, bytes], encoding: Any = ..., - cls: Any = ..., - object_hook: Optional[Callable[[Dict], Any]] = ..., + cls: Optional[Type[JSONDecoder]] = ..., + object_hook: Optional[Callable[[Dict[Any, Any]], Any]] = ..., parse_float: Optional[Callable[[str], Any]] = ..., parse_int: Optional[Callable[[str], Any]] = ..., parse_constant: Optional[Callable[[str], Any]] = ..., @@ -48,8 +48,8 @@ class _Reader(Protocol): def load(fp: _Reader, encoding: Optional[str] = ..., - cls: Any = ..., - object_hook: Optional[Callable[[Dict], Any]] = ..., + cls: Optional[Type[JSONDecoder]] = ..., + object_hook: Optional[Callable[[Dict[Any, Any]], Any]] = ..., parse_float: Optional[Callable[[str], Any]] = ..., parse_int: Optional[Callable[[str], Any]] = ..., parse_constant: Optional[Callable[[str], Any]] = ..., diff --git a/stdlib/2/multiprocessing/dummy/__init__.pyi b/stdlib/2/multiprocessing/dummy/__init__.pyi index e8e02eb16eee..ea41a4cf8ada 100644 --- a/stdlib/2/multiprocessing/dummy/__init__.pyi +++ b/stdlib/2/multiprocessing/dummy/__init__.pyi @@ -14,7 +14,7 @@ from Queue import Queue class DummyProcess(threading.Thread): - _children: weakref.WeakKeyDictionary + _children: weakref.WeakKeyDictionary[Any, Any] _parent: threading.Thread _pid: None _start_called: bool @@ -42,10 +42,10 @@ class Value(object): JoinableQueue = Queue -def Array(typecode, sequence, lock=...) -> array.array: ... +def Array(typecode, sequence, lock=...) -> array.array[Any]: ... def Manager() -> Any: ... def Pool(processes=..., initializer=..., initargs=...) -> Any: ... -def active_children() -> List: ... +def active_children() -> List[Any]: ... def current_process() -> threading.Thread: ... def freeze_support() -> None: ... def shutdown() -> None: ... diff --git a/stdlib/2/multiprocessing/dummy/connection.pyi b/stdlib/2/multiprocessing/dummy/connection.pyi index a7a4f995fdb0..663d39434cef 100644 --- a/stdlib/2/multiprocessing/dummy/connection.pyi +++ b/stdlib/2/multiprocessing/dummy/connection.pyi @@ -15,7 +15,7 @@ class Connection(object): def poll(self, timeout=...) -> Any: ... class Listener(object): - _backlog_queue: Optional[Queue] + _backlog_queue: Optional[Queue[Any]] address: Any def __init__(self, address=..., family=..., backlog=...) -> None: ... def accept(self) -> Connection: ... diff --git a/stdlib/2/mutex.pyi b/stdlib/2/mutex.pyi index 8da8bfbaffce..fa41bbb4fcec 100644 --- a/stdlib/2/mutex.pyi +++ b/stdlib/2/mutex.pyi @@ -1,13 +1,12 @@ # Source: https://hg.python.org/cpython/file/2.7/Lib/mutex.py -from collections import deque -from typing import Any, Callable, TypeVar +from typing import Any, Callable, Deque, TypeVar _ArgType = TypeVar('_ArgType') class mutex: locked: bool - queue: deque + queue: Deque[Any] def __init__(self) -> None: ... def test(self) -> bool: ... def testandset(self) -> bool: ... diff --git a/stdlib/2/os/__init__.pyi b/stdlib/2/os/__init__.pyi index 2c66dc79d471..63407c289e88 100644 --- a/stdlib/2/os/__init__.pyi +++ b/stdlib/2/os/__init__.pyi @@ -3,7 +3,7 @@ from builtins import OSError as error from io import TextIOWrapper as _TextIOWrapper -from posix import stat_result as stat_result # TODO: use this, see https://github.com/python/mypy/issues/3078 +from posix import listdir as listdir, stat_result as stat_result # TODO: use this, see https://github.com/python/mypy/issues/3078 import sys from typing import ( Mapping, MutableMapping, Dict, List, Any, Tuple, Iterator, overload, Union, AnyStr, @@ -192,7 +192,7 @@ def lseek(fd: int, pos: int, how: int) -> int: ... def open(file: _PathType, flags: int, mode: int = ...) -> int: ... def pipe() -> Tuple[int, int]: ... def read(fd: int, n: int) -> bytes: ... -def write(fd: int, string: bytes) -> int: ... +def write(fd: int, string: Union[bytes, buffer]) -> int: ... def access(path: _PathType, mode: int) -> bool: ... def chdir(path: _PathType) -> None: ... def fchdir(fd: int) -> None: ... @@ -200,7 +200,6 @@ def getcwd() -> str: ... def getcwdu() -> unicode: ... def chmod(path: _PathType, mode: int) -> None: ... def link(src: _PathType, link_name: _PathType) -> None: ... -def listdir(path: AnyStr) -> List[AnyStr]: ... def lstat(path: _PathType) -> Any: ... def mknod(filename: _PathType, mode: int = ..., device: int = ...) -> None: ... def major(device: int) -> int: ... diff --git a/stdlib/2/popen2.pyi b/stdlib/2/popen2.pyi index 23435b3a2a9f..b39ba5f074b0 100644 --- a/stdlib/2/popen2.pyi +++ b/stdlib/2/popen2.pyi @@ -5,24 +5,24 @@ _T = TypeVar('_T') class Popen3: sts: int - cmd: Iterable + cmd: Iterable[Any] pid: int tochild: TextIO fromchild: TextIO childerr: Optional[TextIO] - def __init__(self, cmd: Iterable = ..., capturestderr: bool = ..., bufsize: int = ...) -> None: ... + def __init__(self, cmd: Iterable[Any] = ..., capturestderr: bool = ..., bufsize: int = ...) -> None: ... def __del__(self) -> None: ... def poll(self, _deadstate: _T = ...) -> Union[int, _T]: ... def wait(self) -> int: ... class Popen4(Popen3): childerr: None - cmd: Iterable + cmd: Iterable[Any] pid: int tochild: TextIO fromchild: TextIO - def __init__(self, cmd: Iterable = ..., bufsize: int = ...) -> None: ... + def __init__(self, cmd: Iterable[Any] = ..., bufsize: int = ...) -> None: ... -def popen2(cmd: Iterable = ..., bufsize: int = ..., mode: str = ...) -> Tuple[TextIO, TextIO]: ... -def popen3(cmd: Iterable = ..., bufsize: int = ..., mode: str = ...) -> Tuple[TextIO, TextIO, TextIO]: ... -def popen4(cmd: Iterable = ..., bufsize: int = ..., mode: str = ...) -> Tuple[TextIO, TextIO]: ... +def popen2(cmd: Iterable[Any] = ..., bufsize: int = ..., mode: str = ...) -> Tuple[TextIO, TextIO]: ... +def popen3(cmd: Iterable[Any] = ..., bufsize: int = ..., mode: str = ...) -> Tuple[TextIO, TextIO, TextIO]: ... +def popen4(cmd: Iterable[Any] = ..., bufsize: int = ..., mode: str = ...) -> Tuple[TextIO, TextIO]: ... diff --git a/stdlib/2/posix.pyi b/stdlib/2/posix.pyi index fcd4a66f9d2b..c6ff52ccfdd7 100644 --- a/stdlib/2/posix.pyi +++ b/stdlib/2/posix.pyi @@ -1,4 +1,4 @@ -from typing import Dict, List, Mapping, Tuple, Union, Sequence, IO, Optional, TypeVar +from typing import AnyStr, Dict, List, Mapping, Tuple, Union, Sequence, IO, Optional, TypeVar error = OSError @@ -7,6 +7,8 @@ environ: Dict[str, str] pathconf_names: Dict[str, int] sysconf_names: Dict[str, int] +_T = TypeVar("_T") + EX_CANTCREAT: int EX_CONFIG: int EX_DATAERR: int @@ -143,8 +145,7 @@ def kill(pid: int, sig: int) -> None: ... def killpg(pgid: int, sig: int) -> None: ... def lchown(path: unicode, uid: int, gid: int) -> None: ... def link(source: unicode, link_name: str) -> None: ... -_T = TypeVar("_T") -def listdir(path: _T) -> List[_T]: ... +def listdir(path: AnyStr) -> List[AnyStr]: ... def lseek(fd: int, pos: int, how: int) -> None: ... def lstat(path: unicode) -> stat_result: ... def major(device: int) -> int: ... diff --git a/stdlib/2/repr.pyi b/stdlib/2/repr.pyi index ad89789e5a6c..a24e59bc9fec 100644 --- a/stdlib/2/repr.pyi +++ b/stdlib/2/repr.pyi @@ -1,3 +1,5 @@ +from typing import Any, List + class Repr: maxarray: int maxdeque: int @@ -25,7 +27,7 @@ class Repr: def repr_str(self, x, level: complex) -> str: ... def repr_tuple(self, x, level: complex) -> str: ... -def _possibly_sorted(x) -> list: ... +def _possibly_sorted(x) -> List[Any]: ... aRepr: Repr def repr(x) -> str: ... diff --git a/stdlib/2/sets.pyi b/stdlib/2/sets.pyi index a68994f2f2b6..3ec4cae2fc44 100644 --- a/stdlib/2/sets.pyi +++ b/stdlib/2/sets.pyi @@ -3,7 +3,7 @@ from typing import Any, Callable, Hashable, Iterable, Iterator, MutableMapping, _T = TypeVar('_T') _Setlike = Union[BaseSet[_T], Iterable[_T]] -_SelfT = TypeVar('_SelfT', bound=BaseSet) +_SelfT = TypeVar('_SelfT') class BaseSet(Iterable[_T]): def __init__(self) -> None: ... @@ -18,13 +18,13 @@ class BaseSet(Iterable[_T]): def __copy__(self: _SelfT) -> _SelfT: ... def __deepcopy__(self: _SelfT, memo: MutableMapping[int, BaseSet[_T]]) -> _SelfT: ... def __or__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... - def union(self: _SelfT, other: _Setlike) -> _SelfT: ... + def union(self: _SelfT, other: _Setlike[_T]) -> _SelfT: ... def __and__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... - def intersection(self: _SelfT, other: _Setlike) -> _SelfT: ... + def intersection(self: _SelfT, other: _Setlike[Any]) -> _SelfT: ... def __xor__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... - def symmetric_difference(self: _SelfT, other: _Setlike) -> _SelfT: ... + def symmetric_difference(self: _SelfT, other: _Setlike[_T]) -> _SelfT: ... def __sub__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... - def difference(self: _SelfT, other: _Setlike) -> _SelfT: ... + def difference(self: _SelfT, other: _Setlike[Any]) -> _SelfT: ... def __contains__(self, element: Any) -> bool: ... def issubset(self, other: BaseSet[_T]) -> bool: ... def issuperset(self, other: BaseSet[_T]) -> bool: ... @@ -34,20 +34,20 @@ class BaseSet(Iterable[_T]): def __gt__(self, other: BaseSet[_T]) -> bool: ... class ImmutableSet(BaseSet[_T], Hashable): - def __init__(self, iterable: Optional[_Setlike] = ...) -> None: ... + def __init__(self, iterable: Optional[_Setlike[_T]] = ...) -> None: ... def __hash__(self) -> int: ... class Set(BaseSet[_T]): - def __init__(self, iterable: Optional[_Setlike] = ...) -> None: ... - def __ior__(self, other: BaseSet[_T]) -> Set: ... - def union_update(self, other: _Setlike) -> None: ... - def __iand__(self, other: BaseSet[_T]) -> Set: ... - def intersection_update(self, other: _Setlike) -> None: ... - def __ixor__(self, other: BaseSet[_T]) -> Set: ... - def symmetric_difference_update(self, other: _Setlike) -> None: ... - def __isub__(self, other: BaseSet[_T]) -> Set: ... - def difference_update(self, other: _Setlike) -> None: ... - def update(self, iterable: _Setlike) -> None: ... + def __init__(self, iterable: Optional[_Setlike[_T]] = ...) -> None: ... + def __ior__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... + def union_update(self, other: _Setlike[_T]) -> None: ... + def __iand__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... + def intersection_update(self, other: _Setlike[Any]) -> None: ... + def __ixor__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... + def symmetric_difference_update(self, other: _Setlike[_T]) -> None: ... + def __isub__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... + def difference_update(self, other: _Setlike[Any]) -> None: ... + def update(self, iterable: _Setlike[_T]) -> None: ... def clear(self) -> None: ... def add(self, element: _T) -> None: ... def remove(self, element: _T) -> None: ... diff --git a/stdlib/2/shelve.pyi b/stdlib/2/shelve.pyi index d7d9b8c60188..15828bc1793a 100644 --- a/stdlib/2/shelve.pyi +++ b/stdlib/2/shelve.pyi @@ -2,7 +2,7 @@ from typing import Any, Dict, Iterator, List, Optional, Tuple import collections -class Shelf(collections.MutableMapping): +class Shelf(collections.MutableMapping[Any, Any]): def __init__(self, dict: Dict[Any, Any], protocol: Optional[int] = ..., writeback: bool = ..., keyencoding: str = ...) -> None: ... def __iter__(self) -> Iterator[str]: ... def keys(self) -> List[Any]: ... diff --git a/stdlib/2/sre_parse.pyi b/stdlib/2/sre_parse.pyi index beabb40946b6..d23753527d12 100644 --- a/stdlib/2/sre_parse.pyi +++ b/stdlib/2/sre_parse.pyi @@ -4,10 +4,10 @@ from typing import Any, Dict, Iterable, List, Match, Optional, Pattern as _Patte SPECIAL_CHARS: str REPEAT_CHARS: str -DIGITS: Set -OCTDIGITS: Set -HEXDIGITS: Set -WHITESPACE: Set +DIGITS: Set[Any] +OCTDIGITS: Set[Any] +HEXDIGITS: Set[Any] +WHITESPACE: Set[Any] ESCAPES: Dict[str, Tuple[str, int]] CATEGORIES: Dict[str, Union[Tuple[str, str], Tuple[str, List[Tuple[str, str]]]]] FLAGS: Dict[str, int] @@ -59,5 +59,5 @@ def isdigit(char: str) -> bool: ... def isname(name: str) -> bool: ... def parse(str: str, flags: int = ..., pattern: Pattern = ...) -> SubPattern: ... _Template = Tuple[List[Tuple[int, int]], List[Optional[int]]] -def parse_template(source: str, pattern: _Pattern) -> _Template: ... -def expand_template(template: _Template, match: Match) -> str: ... +def parse_template(source: str, pattern: _Pattern[Any]) -> _Template: ... +def expand_template(template: _Template, match: Match[Any]) -> str: ... diff --git a/stdlib/2/subprocess.pyi b/stdlib/2/subprocess.pyi index b60e89e677ac..54dd0dbd3bc8 100644 --- a/stdlib/2/subprocess.pyi +++ b/stdlib/2/subprocess.pyi @@ -2,7 +2,9 @@ # Based on http://docs.python.org/2/library/subprocess.html and Python 3 stub -from typing import Sequence, Any, Mapping, Callable, Tuple, IO, Union, Optional, List, Text +from typing import ( + Sequence, Any, Mapping, Callable, Tuple, IO, Union, Optional, List, Text, TypeVar, Generic, +) _FILE = Union[None, int, IO[Any]] _TXT = Union[bytes, Text] @@ -63,45 +65,46 @@ class CalledProcessError(Exception): # morally: _CMD cmd: Any # morally: Optional[bytes] - output: Any + output: bytes def __init__(self, returncode: int, cmd: _CMD, output: Optional[bytes] = ...) -> None: ... -class Popen: - stdin: Optional[IO[Any]] - stdout: Optional[IO[Any]] - stderr: Optional[IO[Any]] +# We use a dummy type variable used to make Popen generic like it is in python 3 +_T = TypeVar('_T', bound=bytes) + +class Popen(Generic[_T]): + stdin: Optional[IO[bytes]] + stdout: Optional[IO[bytes]] + stderr: Optional[IO[bytes]] pid = 0 returncode = 0 - def __init__(self, - args: _CMD, - bufsize: int = ..., - executable: Optional[_TXT] = ..., - stdin: Optional[_FILE] = ..., - stdout: Optional[_FILE] = ..., - stderr: Optional[_FILE] = ..., - preexec_fn: Optional[Callable[[], Any]] = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: Optional[_TXT] = ..., - env: Optional[_ENV] = ..., - universal_newlines: bool = ..., - startupinfo: Optional[Any] = ..., - creationflags: int = ...) -> None: ... + def __new__(cls, + args: _CMD, + bufsize: int = ..., + executable: Optional[_TXT] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_TXT] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Optional[Any] = ..., + creationflags: int = ...) -> Popen[bytes]: ... def poll(self) -> int: ... def wait(self) -> int: ... # morally: -> Tuple[Optional[bytes], Optional[bytes]] - def communicate(self, input: Optional[_TXT] = ...) -> Tuple[Any, Any]: ... + def communicate(self, input: Optional[_TXT] = ...) -> Tuple[bytes, bytes]: ... def send_signal(self, signal: int) -> None: ... def terminate(self) -> None: ... def kill(self) -> None: ... - def __enter__(self) -> Popen: ... - def __exit__(self, type, value, traceback) -> bool: ... def list2cmdline(seq: Sequence[str]) -> str: ... # undocumented diff --git a/stdlib/2/sys.pyi b/stdlib/2/sys.pyi index e67b26325af1..2b38c6da0c49 100644 --- a/stdlib/2/sys.pyi +++ b/stdlib/2/sys.pyi @@ -8,7 +8,7 @@ from types import FrameType, ModuleType, TracebackType, ClassType # The following type alias are stub-only and do not exist during runtime _ExcInfo = Tuple[Type[BaseException], BaseException, TracebackType] -_OptExcInfo = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]] +_OptExcInfo = Union[_ExcInfo, Tuple[None, None, None]] class _flags: bytes_warning: int diff --git a/stdlib/2/tempfile.pyi b/stdlib/2/tempfile.pyi index 2dcc1a924beb..536b391ad4d0 100644 --- a/stdlib/2/tempfile.pyi +++ b/stdlib/2/tempfile.pyi @@ -19,12 +19,12 @@ class _RandomNameSequence: class _TemporaryFileWrapper(IO[str]): delete: bool - file: IO + file: IO[str] name: Any - def __init__(self, file: IO, name: Any, delete: bool = ...) -> None: ... + def __init__(self, file: IO[str], name: Any, delete: bool = ...) -> None: ... def __del__(self) -> None: ... def __enter__(self) -> _TemporaryFileWrapper: ... - def __exit__(self, exc, value, tb) -> bool: ... + def __exit__(self, exc, value, tb) -> Optional[bool]: ... def __getattr__(self, name: unicode) -> Any: ... def close(self) -> None: ... def unlink(self, path: unicode) -> None: ... @@ -88,7 +88,7 @@ class TemporaryDirectory: dir: Union[bytes, unicode] = ...) -> None: ... def cleanup(self) -> None: ... def __enter__(self) -> Any: ... # Can be str or unicode - def __exit__(self, type, value, traceback) -> bool: ... + def __exit__(self, type, value, traceback) -> None: ... @overload def mkstemp() -> Tuple[int, str]: ... diff --git a/stdlib/2/types.pyi b/stdlib/2/types.pyi index 5984706aee8a..47c52e88a29d 100644 --- a/stdlib/2/types.pyi +++ b/stdlib/2/types.pyi @@ -64,6 +64,23 @@ class CodeType: co_nlocals: int co_stacksize: int co_varnames: Tuple[str, ...] + def __init__( + self, + argcount: int, + nlocals: int, + stacksize: int, + flags: int, + codestring: str, + constants: Tuple[Any, ...], + names: Tuple[str, ...], + varnames: Tuple[str, ...], + filename: str, + name: str, + firstlineno: int, + lnotab: str, + freevars: Tuple[str, ...] = ..., + cellvars: Tuple[str, ...] = ..., + ) -> None: ... class GeneratorType: gi_code: CodeType @@ -86,7 +103,7 @@ class UnboundMethodType: __name__: str __func__ = im_func __self__ = im_self - def __init__(self, func: Callable, obj: object) -> None: ... + def __init__(self, func: Callable[..., Any], obj: object) -> None: ... def __call__(self, *args: Any, **kwargs: Any) -> Any: ... class InstanceType(object): ... @@ -137,7 +154,7 @@ class EllipsisType: ... class DictProxyType: # TODO is it possible to have non-string keys? # no __init__ - def copy(self) -> dict: ... + def copy(self) -> Dict[Any, Any]: ... def get(self, key: str, default: _T = ...) -> Union[Any, _T]: ... def has_key(self, key: str) -> bool: ... def items(self) -> List[Tuple[str, Any]]: ... diff --git a/stdlib/2/typing.pyi b/stdlib/2/typing.pyi index 6c159b963207..d45aba1da6b7 100644 --- a/stdlib/2/typing.pyi +++ b/stdlib/2/typing.pyi @@ -22,6 +22,12 @@ Protocol: _SpecialForm = ... Callable: _SpecialForm = ... Type: _SpecialForm = ... ClassVar: _SpecialForm = ... +Final: _SpecialForm = ... +_F = TypeVar('_F', bound=Callable[..., Any]) +def final(f: _F) -> _F: ... +Literal: _SpecialForm = ... +# TypedDict is a (non-subscriptable) special form. +TypedDict: object = ... class GenericMeta(type): ... @@ -63,41 +69,41 @@ _KT_co = TypeVar('_KT_co', covariant=True) # Key type covariant containers. _VT_co = TypeVar('_VT_co', covariant=True) # Value type covariant containers. _T_contra = TypeVar('_T_contra', contravariant=True) # Ditto contravariant. _TC = TypeVar('_TC', bound=Type[object]) -_C = TypeVar("_C", bound=Callable) +_C = TypeVar("_C", bound=Callable[..., Any]) -def runtime(cls: _TC) -> _TC: ... +def runtime_checkable(cls: _TC) -> _TC: ... -@runtime +@runtime_checkable class SupportsInt(Protocol, metaclass=ABCMeta): @abstractmethod def __int__(self) -> int: ... -@runtime +@runtime_checkable class SupportsFloat(Protocol, metaclass=ABCMeta): @abstractmethod def __float__(self) -> float: ... -@runtime +@runtime_checkable class SupportsComplex(Protocol, metaclass=ABCMeta): @abstractmethod def __complex__(self) -> complex: ... -@runtime +@runtime_checkable class SupportsAbs(Protocol[_T_co]): @abstractmethod def __abs__(self) -> _T_co: ... -@runtime +@runtime_checkable class Reversible(Protocol[_T_co]): @abstractmethod def __reversed__(self) -> Iterator[_T_co]: ... -@runtime +@runtime_checkable class Sized(Protocol, metaclass=ABCMeta): @abstractmethod def __len__(self) -> int: ... -@runtime +@runtime_checkable class Hashable(Protocol, metaclass=ABCMeta): # TODO: This is special, in that a subclass of a hashable class may not be hashable # (for example, list vs. object). It's not obvious how to represent this. This class @@ -105,12 +111,12 @@ class Hashable(Protocol, metaclass=ABCMeta): @abstractmethod def __hash__(self) -> int: ... -@runtime +@runtime_checkable class Iterable(Protocol[_T_co]): @abstractmethod def __iter__(self) -> Iterator[_T_co]: ... -@runtime +@runtime_checkable class Iterator(Iterable[_T_co], Protocol[_T_co]): @abstractmethod def next(self) -> _T_co: ... @@ -135,7 +141,7 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]): @property def gi_running(self) -> bool: ... -@runtime +@runtime_checkable class Container(Protocol[_T_co]): @abstractmethod def __contains__(self, x: object) -> bool: ... @@ -234,7 +240,7 @@ class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]): def __contains__(self, o: object) -> bool: ... def __iter__(self) -> Iterator[_VT_co]: ... -@runtime +@runtime_checkable class ContextManager(Protocol[_T_co]): def __enter__(self) -> _T_co: ... def __exit__(self, __exc_type: Optional[Type[BaseException]], @@ -337,7 +343,7 @@ class IO(Iterator[AnyStr], Generic[AnyStr]): def __enter__(self) -> IO[AnyStr]: ... @abstractmethod def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException], - traceback: Optional[TracebackType]) -> bool: ... + traceback: Optional[TracebackType]) -> Optional[bool]: ... class BinaryIO(IO[str]): # TODO readinto @@ -398,6 +404,8 @@ class Match(Generic[AnyStr]): def start(self, group: Union[int, str] = ...) -> int: ... def end(self, group: Union[int, str] = ...) -> int: ... def span(self, group: Union[int, str] = ...) -> Tuple[int, int]: ... + @property + def regs(self) -> Tuple[Tuple[int, int], ...]: ... # undocumented # We need a second TypeVar with the same definition as AnyStr, because # Pattern is generic over AnyStr (determining the type of its .pattern @@ -439,8 +447,9 @@ class Pattern(Generic[AnyStr]): # Functions -def get_type_hints(obj: Callable, globalns: Optional[dict[Text, Any]] = ..., - localns: Optional[dict[Text, Any]] = ...) -> None: ... +def get_type_hints( + obj: Callable[..., Any], globalns: Optional[Dict[Text, Any]] = ..., localns: Optional[Dict[Text, Any]] = ..., +) -> None: ... @overload def cast(tp: Type[_T], obj: Any) -> _T: ... @@ -450,7 +459,7 @@ def cast(tp: str, obj: Any) -> Any: ... # Type constructors # NamedTuple is special-cased in the type checker -class NamedTuple(tuple): +class NamedTuple(Tuple[Any, ...]): _fields: Tuple[str, ...] def __init__(self, typename: Text, fields: Iterable[Tuple[Text, Any]] = ..., *, @@ -459,9 +468,24 @@ class NamedTuple(tuple): @classmethod def _make(cls: Type[_T], iterable: Iterable[Any]) -> _T: ... - def _asdict(self) -> dict: ... + def _asdict(self) -> Dict[str, Any]: ... def _replace(self: _T, **kwargs: Any) -> _T: ... +# Internal mypy fallback type for all typed dicts (does not exist at runtime) +class _TypedDict(Mapping[str, object], metaclass=ABCMeta): + def copy(self: _T) -> _T: ... + # Using NoReturn so that only calls using mypy plugin hook that specialize the signature + # can go through. + def setdefault(self, k: NoReturn, default: object) -> object: ... + # Mypy plugin hook for 'pop' expects that 'default' has a type variable type. + def pop(self, k: NoReturn, default: _T = ...) -> object: ... + def update(self: _T, __m: _T) -> None: ... + def has_key(self, k: str) -> bool: ... + def viewitems(self) -> ItemsView[str, object]: ... + def viewkeys(self) -> KeysView[str]: ... + def viewvalues(self) -> ValuesView[object]: ... + def __delitem__(self, k: NoReturn) -> None: ... + def NewType(name: str, tp: Type[_T]) -> Type[_T]: ... # This itself is only available during type checking diff --git a/stdlib/2/xmlrpclib.pyi b/stdlib/2/xmlrpclib.pyi index abf40987e61d..d1d293718dae 100644 --- a/stdlib/2/xmlrpclib.pyi +++ b/stdlib/2/xmlrpclib.pyi @@ -12,7 +12,7 @@ from gzip import GzipFile _Unmarshaller = Any _timeTuple = Tuple[int, int, int, int, int, int, int, int, int] # Represents types that can be compared against a DateTime object -_dateTimeComp = Union[AnyStr, DateTime, datetime, _timeTuple] +_dateTimeComp = Union[unicode, DateTime, datetime] # A "host description" used by Transport factories _hostDesc = Union[str, Tuple[str, Mapping[Any, Any]]] @@ -55,26 +55,26 @@ Boolean: Type[bool] class DateTime: value: str def __init__(self, value: Union[str, unicode, datetime, float, int, _timeTuple, struct_time] = ...) -> None: ... - def make_comparable(self, other: _dateTimeComp) -> Tuple[_dateTimeComp, _dateTimeComp]: ... + def make_comparable(self, other: _dateTimeComp) -> Tuple[unicode, unicode]: ... def __lt__(self, other: _dateTimeComp) -> bool: ... def __le__(self, other: _dateTimeComp) -> bool: ... def __gt__(self, other: _dateTimeComp) -> bool: ... def __ge__(self, other: _dateTimeComp) -> bool: ... - def __eq__(self, other: _dateTimeComp) -> bool: ... - def __ne__(self, other: _dateTimeComp) -> bool: ... + def __eq__(self, other: _dateTimeComp) -> bool: ... # type: ignore + def __ne__(self, other: _dateTimeComp) -> bool: ... # type: ignore def timetuple(self) -> struct_time: ... def __cmp__(self, other: _dateTimeComp) -> int: ... def decode(self, data: Any) -> None: ... - def encode(self, out: IO) -> None: ... + def encode(self, out: IO[str]) -> None: ... class Binary: data: str def __init__(self, data: Optional[str] = ...) -> None: ... def __cmp__(self, other: Any) -> int: ... def decode(self, data: str) -> None: ... - def encode(self, out: IO) -> None: ... + def encode(self, out: IO[str]) -> None: ... -WRAPPERS: tuple +WRAPPERS: Tuple[Type[Any], ...] # Still part of the public API, but see http://bugs.python.org/issue1773632 FastParser: None @@ -104,7 +104,28 @@ class Marshaller: allow_none: bool def __init__(self, encoding: Optional[str] = ..., allow_none: bool = ...) -> None: ... dispatch: Mapping[type, Callable[[Marshaller, str, Callable[[str], None]], None]] - def dumps(self, values: Union[Iterable[Union[None, int, bool, long, float, str, unicode, List, Tuple, Mapping, datetime, InstanceType]], Fault]) -> str: ... + def dumps( + self, + values: Union[ + Iterable[ + Union[ + None, + int, + bool, + long, + float, + str, + unicode, + List[Any], + Tuple[Any, ...], + Mapping[Any, Any], + datetime, + InstanceType, + ], + ], + Fault, + ], + ) -> str: ... def dump_nil(self, value: None, write: Callable[[str], None]) -> None: ... def dump_int(self, value: int, write: Callable[[str], None]) -> None: ... def dump_bool(self, value: bool, write: Callable[[str], None]) -> None: ... @@ -112,15 +133,20 @@ class Marshaller: def dump_double(self, value: float, write: Callable[[str], None]) -> None: ... def dump_string(self, value: str, write: Callable[[str], None], escape: Callable[[AnyStr, Callable[[AnyStr, AnyStr, AnyStr], AnyStr]], AnyStr] = ...) -> None: ... def dump_unicode(self, value: unicode, write: Callable[[str], None], escape: Callable[[AnyStr, Callable[[AnyStr, AnyStr, AnyStr], AnyStr]], AnyStr] = ...) -> None: ... - def dump_array(self, value: Union[List, Tuple], write: Callable[[str], None]) -> None: ... - def dump_struct(self, value: Mapping, write: Callable[[str], None], escape: Callable[[AnyStr, Callable[[AnyStr, AnyStr, AnyStr], AnyStr]], AnyStr] = ...) -> None: ... + def dump_array(self, value: Iterable[Any], write: Callable[[str], None]) -> None: ... + def dump_struct( + self, + value: Mapping[unicode, Any], + write: Callable[[str], None], + escape: Callable[[AnyStr, Callable[[AnyStr, AnyStr, AnyStr], AnyStr]], AnyStr] = ..., + ) -> None: ... def dump_datetime(self, value: datetime, write: Callable[[str], None]) -> None: ... def dump_instance(self, value: InstanceType, write: Callable[[str], None]) -> None: ... class Unmarshaller: def append(self, object: Any) -> None: ... def __init__(self, use_datetime: bool = ...) -> None: ... - def close(self) -> tuple: ... + def close(self) -> Tuple[Any, ...]: ... def getmethodname(self) -> Optional[str]: ... def xml(self, encoding: str, standalone: bool) -> None: ... def start(self, tag: str, attrs: Any) -> None: ... @@ -143,9 +169,9 @@ class Unmarshaller: def end_methodName(self, data: str) -> None: ... class _MultiCallMethod: - def __init__(self, call_list: List[Tuple[str, tuple]], name: str) -> None: ... + def __init__(self, call_list: List[Tuple[str, Tuple[Any, ...]]], name: str) -> None: ... class MultiCallIterator: - def __init__(self, results: List) -> None: ... + def __init__(self, results: List[Any]) -> None: ... class MultiCall: def __init__(self, server: ServerProxy) -> None: ... @@ -153,19 +179,25 @@ class MultiCall: def __call__(self) -> MultiCallIterator: ... def getparser(use_datetime: bool = ...) -> Tuple[Union[ExpatParser, SlowParser], Unmarshaller]: ... -def dumps(params: Union[tuple, Fault], methodname: Optional[str] = ..., methodresponse: Optional[bool] = ..., encoding: Optional[str] = ..., allow_none: bool = ...) -> str: ... -def loads(data: str, use_datetime: bool = ...) -> Tuple[tuple, Optional[str]]: ... +def dumps( + params: Union[Tuple[Any, ...], Fault], + methodname: Optional[str] = ..., + methodresponse: Optional[bool] = ..., + encoding: Optional[str] = ..., + allow_none: bool = ..., +) -> str: ... +def loads(data: str, use_datetime: bool = ...) -> Tuple[Tuple[Any, ...], Optional[str]]: ... def gzip_encode(data: str) -> str: ... def gzip_decode(data: str, max_decode: int = ...) -> str: ... class GzipDecodedResponse(GzipFile): - stringio: StringIO + stringio: StringIO[Any] def __init__(self, response: HTTPResponse) -> None: ... def close(self): ... class _Method: - def __init__(self, send: Callable[[str, tuple], Any], name: str) -> None: ... + def __init__(self, send: Callable[[str, Tuple[Any, ...]], Any], name: str) -> None: ... def __getattr__(self, name: str) -> _Method: ... def __call__(self, *args: Any) -> Any: ... @@ -174,9 +206,9 @@ class Transport: accept_gzip_encoding: bool encode_threshold: Optional[int] def __init__(self, use_datetime: bool = ...) -> None: ... - def request(self, host: _hostDesc, handler: str, request_body: str, verbose: bool = ...) -> tuple: ... + def request(self, host: _hostDesc, handler: str, request_body: str, verbose: bool = ...) -> Tuple[Any, ...]: ... verbose: bool - def single_request(self, host: _hostDesc, handler: str, request_body: str, verbose: bool = ...) -> tuple: ... + def single_request(self, host: _hostDesc, handler: str, request_body: str, verbose: bool = ...) -> Tuple[Any, ...]: ... def getparser(self) -> Tuple[Union[ExpatParser, SlowParser], Unmarshaller]: ... def get_host_info(self, host: _hostDesc) -> Tuple[str, Optional[List[Tuple[str, str]]], Optional[Mapping[Any, Any]]]: ... def make_connection(self, host: _hostDesc) -> HTTPConnection: ... @@ -185,7 +217,7 @@ class Transport: def send_host(self, connection: HTTPConnection, host: str) -> None: ... def send_user_agent(self, connection: HTTPConnection) -> None: ... def send_content(self, connection: HTTPConnection, request_body: str) -> None: ... - def parse_response(self, response: HTTPResponse) -> tuple: ... + def parse_response(self, response: HTTPResponse) -> Tuple[Any, ...]: ... class SafeTransport(Transport): def __init__(self, use_datetime: bool = ..., context: Optional[SSLContext] = ...) -> None: ... diff --git a/stdlib/2and3/_bisect.pyi b/stdlib/2and3/_bisect.pyi index 62335472f8ae..38e7a7b376f5 100644 --- a/stdlib/2and3/_bisect.pyi +++ b/stdlib/2and3/_bisect.pyi @@ -1,11 +1,11 @@ """Stub file for the '_bisect' module.""" -from typing import Sequence, TypeVar +from typing import Sequence, MutableSequence, TypeVar _T = TypeVar('_T') def bisect(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... def bisect_left(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... def bisect_right(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... -def insort(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> None: ... -def insort_left(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> None: ... -def insort_right(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> None: ... +def insort(a: MutableSequence[_T], x: _T, lo: int = ..., hi: int = ...) -> None: ... +def insort_left(a: MutableSequence[_T], x: _T, lo: int = ..., hi: int = ...) -> None: ... +def insort_right(a: MutableSequence[_T], x: _T, lo: int = ..., hi: int = ...) -> None: ... diff --git a/stdlib/2and3/_curses.pyi b/stdlib/2and3/_curses.pyi index 836089f5b32d..cf640b53f7a5 100644 --- a/stdlib/2and3/_curses.pyi +++ b/stdlib/2and3/_curses.pyi @@ -287,7 +287,7 @@ def tparm(fmt: bytes, i1: int = ..., i2: int = ..., i3: int = ..., i4: int = ... def typeahead(fd: int) -> None: ... def unctrl(ch: _chtype) -> bytes: ... if sys.version_info >= (3, 3): - def unget_wch(ch: _chtype) -> None: ... + def unget_wch(ch: Union[int, str]) -> None: ... def ungetch(ch: _chtype) -> None: ... def ungetmouse(id: int, x: int, y: int, z: int, bstate: int) -> None: ... if sys.version_info >= (3, 5): @@ -350,14 +350,14 @@ class _CursesWindow: def getbegyx(self) -> Tuple[int, int]: ... def getbkgd(self) -> Tuple[int, int]: ... @overload - def getch(self) -> _chtype: ... + def getch(self) -> int: ... @overload - def getch(self, y: int, x: int) -> _chtype: ... + def getch(self, y: int, x: int) -> int: ... if sys.version_info >= (3, 3): @overload - def get_wch(self) -> _chtype: ... + def get_wch(self) -> Union[int, str]: ... @overload - def get_wch(self, y: int, x: int) -> _chtype: ... + def get_wch(self, y: int, x: int) -> Union[int, str]: ... @overload def getkey(self) -> str: ... @overload diff --git a/stdlib/2and3/_heapq.pyi b/stdlib/2and3/_heapq.pyi index 8b7f6eac0d30..9ff4a08fee11 100644 --- a/stdlib/2and3/_heapq.pyi +++ b/stdlib/2and3/_heapq.pyi @@ -1,6 +1,7 @@ """Stub file for the '_heapq' module.""" -from typing import TypeVar, List +from typing import TypeVar, List, Iterable, Any, Callable, Optional +import sys _T = TypeVar("_T") @@ -11,5 +12,6 @@ def heappush(heap: List[_T], item: _T) -> None: ... def heappushpop(heap: List[_T], item: _T) -> _T: ... def heapreplace(heap: List[_T], item: _T) -> _T: raise IndexError() # if list is empty -def nlargest(a: int, b: List[_T]) -> List[_T]: ... -def nsmallest(a: int, b: List[_T]) -> List[_T]: ... +if sys.version_info < (3,): + def nlargest(n: int, iterable: Iterable[_T]) -> List[_T]: ... + def nsmallest(n: int, iterable: Iterable[_T]) -> List[_T]: ... diff --git a/stdlib/2and3/_weakrefset.pyi b/stdlib/2and3/_weakrefset.pyi index 950d3fe64265..f7dc56ec3295 100644 --- a/stdlib/2and3/_weakrefset.pyi +++ b/stdlib/2and3/_weakrefset.pyi @@ -2,7 +2,7 @@ from typing import Iterator, Any, Iterable, MutableSet, Optional, TypeVar, Gener _S = TypeVar('_S') _T = TypeVar('_T') -_SelfT = TypeVar('_SelfT', bound=WeakSet) +_SelfT = TypeVar('_SelfT', bound=WeakSet[Any]) class WeakSet(MutableSet[_T], Generic[_T]): def __init__(self, data: Optional[Iterable[_T]] = ...) -> None: ... diff --git a/stdlib/2and3/aifc.pyi b/stdlib/2and3/aifc.pyi new file mode 100644 index 000000000000..a141125a96fc --- /dev/null +++ b/stdlib/2and3/aifc.pyi @@ -0,0 +1,81 @@ + +from typing import Union, IO, Optional, Type, NamedTuple, List, Tuple, Any, Text, overload +from typing_extensions import Literal +from types import TracebackType +import sys + +class Error(Exception): ... + +_aifc_params = NamedTuple('_aifc_params', [('nchannels', int), ('sampwidth', int), ('framerate', int), + ('nframes', int), ('comptype', bytes), ('compname', bytes)]) + +_File = Union[Text, IO[bytes]] +_Marker = Tuple[int, int, bytes] + +class Aifc_read: + def __init__(self, f: _File) -> None: ... + if sys.version_info >= (3, 4): + def __enter__(self) -> Aifc_read: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> None: ... + def initfp(self, file: IO[bytes]) -> None: ... + def getfp(self) -> IO[bytes]: ... + def rewind(self) -> None: ... + def close(self) -> None: ... + def tell(self) -> int: ... + def getnchannels(self) -> int: ... + def getnframes(self) -> int: ... + def getsampwidth(self) -> int: ... + def getframerate(self) -> int: ... + def getcomptype(self) -> bytes: ... + def getcompname(self) -> bytes: ... + def getparams(self) -> _aifc_params: ... + def getmarkers(self) -> Optional[List[_Marker]]: ... + def getmark(self, id: int) -> _Marker: ... + def setpos(self, pos: int) -> None: ... + def readframes(self, nframes: int) -> bytes: ... + +class Aifc_write: + def __init__(self, f: _File) -> None: ... + def __del__(self) -> None: ... + if sys.version_info >= (3, 4): + def __enter__(self) -> Aifc_write: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> None: ... + def initfp(self, file: IO[bytes]) -> None: ... + def aiff(self) -> None: ... + def aifc(self) -> None: ... + def setnchannels(self, nchannels: int) -> None: ... + def getnchannels(self) -> int: ... + def setsampwidth(self, sampwidth: int) -> None: ... + def getsampwidth(self) -> int: ... + def setframerate(self, framerate: int) -> None: ... + def getframerate(self) -> int: ... + def setnframes(self, nframes: int) -> None: ... + def getnframes(self) -> int: ... + def setcomptype(self, comptype: bytes, compname: bytes) -> None: ... + def getcomptype(self) -> bytes: ... + def getcompname(self) -> bytes: ... + def setparams(self, params: Tuple[int, int, int, int, bytes, bytes]) -> None: ... + def getparams(self) -> _aifc_params: ... + def setmark(self, id: int, pos: int, name: bytes) -> None: ... + def getmark(self, id: int) -> _Marker: ... + def getmarkers(self) -> Optional[List[_Marker]]: ... + def tell(self) -> int: ... + def writeframesraw(self, data: Any) -> None: ... # Actual type for data is Buffer Protocol + def writeframes(self, data: Any) -> None: ... + def close(self) -> None: ... + +@overload +def open(f: _File, mode: Literal["r", "rb"] = ...) -> Aifc_read: ... +@overload +def open(f: _File, mode: Literal["w", "wb"]) -> Aifc_write: ... +@overload +def open(f: _File, mode: str) -> Any: ... + +@overload +def openfp(f: _File, mode: Literal["r", "rb"] = ...) -> Aifc_read: ... +@overload +def openfp(f: _File, mode: Literal["w", "wb"]) -> Aifc_write: ... +@overload +def openfp(f: _File, mode: str) -> Any: ... diff --git a/stdlib/2and3/argparse.pyi b/stdlib/2and3/argparse.pyi index 03b9620d3225..2c33cac7122d 100644 --- a/stdlib/2and3/argparse.pyi +++ b/stdlib/2and3/argparse.pyi @@ -5,7 +5,7 @@ from typing import ( import sys _T = TypeVar('_T') -_ActionT = TypeVar('_ActionT', bound='Action') +_ActionT = TypeVar('_ActionT', bound=Action) _N = TypeVar('_N') if sys.version_info >= (3,): @@ -225,7 +225,7 @@ class HelpFormatter: def _expand_help(self, action: Action) -> _Text: ... def _iter_indented_subactions(self, action: Action) -> Generator[Action, None, None]: ... def _split_lines(self, text: Text, width: int) -> List[_Text]: ... - def _fill_text(self, text: Text, width: int, indent: int) -> _Text: ... + def _fill_text(self, text: Text, width: int, indent: Text) -> _Text: ... def _get_help_string(self, action: Action) -> Optional[_Text]: ... def _get_default_metavar_for_optional(self, action: Action) -> _Text: ... def _get_default_metavar_for_positional(self, action: Action) -> _Text: ... diff --git a/stdlib/2and3/asyncore.pyi b/stdlib/2and3/asyncore.pyi index 8dc8f477543f..9d0a2c60e3f4 100644 --- a/stdlib/2and3/asyncore.pyi +++ b/stdlib/2and3/asyncore.pyi @@ -13,8 +13,9 @@ from errno import (EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, EPIPE, EAGAIN, errorcode) # cyclic dependence with asynchat -_maptype = Dict[str, Any] +_maptype = Dict[int, Any] +socket_map: _maptype = ... # Undocumented class ExitNow(Exception): ... @@ -50,8 +51,8 @@ class dispatcher: def readable(self) -> bool: ... def writable(self) -> bool: ... def listen(self, backlog: int) -> None: ... - def bind(self, address: Union[tuple, str]) -> None: ... - def connect(self, address: Union[tuple, str]) -> None: ... + def bind(self, address: Union[Tuple[Any, ...], str]) -> None: ... + def connect(self, address: Union[Tuple[Any, ...], str]) -> None: ... def accept(self) -> Optional[Tuple[SocketType, Any]]: ... def send(self, data: bytes) -> int: ... def recv(self, buffer_size: int) -> bytes: ... @@ -103,7 +104,7 @@ class dispatcher: def recvfrom_into(self, buffer: bytes, nbytes: int, flags: int = ...) -> Any: ... def recv_into(self, buffer: bytes, nbytes: int, flags: int = ...) -> Any: ... def sendall(self, data: bytes, flags: int = ...) -> None: ... - def sendto(self, data: bytes, address: Union[tuple, str], flags: int = ...) -> int: ... + def sendto(self, data: bytes, address: Union[Tuple[str, int], str], flags: int = ...) -> int: ... def setblocking(self, flag: bool) -> None: ... def settimeout(self, value: Union[float, None]) -> None: ... def setsockopt(self, level: int, optname: int, value: Union[int, bytes]) -> None: ... diff --git a/stdlib/2and3/binascii.pyi b/stdlib/2and3/binascii.pyi index 9689b712b919..d268a1b6a66b 100644 --- a/stdlib/2and3/binascii.pyi +++ b/stdlib/2and3/binascii.pyi @@ -5,20 +5,15 @@ import sys from typing import Union, Text - if sys.version_info < (3,): # Python 2 accepts unicode ascii pretty much everywhere. - _Bytes = Union[bytes, Text] - _Ascii = Union[bytes, Text] -elif sys.version_info < (3, 3): - # Python 3.2 and below only accepts bytes. - _Bytes = bytes - _Ascii = bytes + _Bytes = Text + _Ascii = Text else: # But since Python 3.3 ASCII-only unicode strings are accepted by the # a2b_* functions. _Bytes = bytes - _Ascii = Union[bytes, Text] + _Ascii = Union[bytes, str] def a2b_uu(string: _Ascii) -> bytes: ... if sys.version_info >= (3, 7): diff --git a/stdlib/2and3/bisect.pyi b/stdlib/2and3/bisect.pyi index 5c541124ab58..c3075297c394 100644 --- a/stdlib/2and3/bisect.pyi +++ b/stdlib/2and3/bisect.pyi @@ -1,22 +1,13 @@ # Stubs for bisect -from typing import Any, Sequence, TypeVar +from typing import Any, Sequence, MutableSequence, TypeVar _T = TypeVar('_T') -# TODO uncomment when mypy# 2035 is fixed -# def bisect_left(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... -# def bisect_right(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... -# def bisect(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... -# -# def insort_left(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... -# def insort_right(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... -# def insort(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... +def bisect_left(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... +def bisect_right(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... +def bisect(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... -def bisect_left(a: Sequence, x: Any, lo: int = ..., hi: int = ...) -> int: ... -def bisect_right(a: Sequence, x: Any, lo: int = ..., hi: int = ...) -> int: ... -def bisect(a: Sequence, x: Any, lo: int = ..., hi: int = ...) -> int: ... - -def insort_left(a: Sequence, x: Any, lo: int = ..., hi: int = ...) -> int: ... -def insort_right(a: Sequence, x: Any, lo: int = ..., hi: int = ...) -> int: ... -def insort(a: Sequence, x: Any, lo: int = ..., hi: int = ...) -> int: ... +def insort_left(a: MutableSequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... +def insort_right(a: MutableSequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... +def insort(a: MutableSequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 13a6ef968ecc..966e150897eb 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -11,7 +11,7 @@ from typing import ( ) from abc import abstractmethod, ABCMeta from ast import mod, AST -from types import TracebackType, CodeType +from types import TracebackType, CodeType, ModuleType import sys if sys.version_info >= (3,): @@ -53,30 +53,30 @@ class object: def __getattribute__(self, name: str) -> Any: ... def __delattr__(self, name: str) -> None: ... def __sizeof__(self) -> int: ... - def __reduce__(self) -> tuple: ... - def __reduce_ex__(self, protocol: int) -> tuple: ... + def __reduce__(self) -> Tuple[Any, ...]: ... + def __reduce_ex__(self, protocol: int) -> Tuple[Any, ...]: ... if sys.version_info >= (3,): def __dir__(self) -> Iterable[str]: ... if sys.version_info >= (3, 6): def __init_subclass__(cls) -> None: ... class staticmethod(object): # Special, only valid as a decorator. - __func__: Callable + __func__: Callable[..., Any] if sys.version_info >= (3,): __isabstractmethod__: bool - def __init__(self, f: Callable) -> None: ... + def __init__(self, f: Callable[..., Any]) -> None: ... def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... - def __get__(self, obj: _T, type: Optional[Type[_T]] = ...) -> Callable: ... + def __get__(self, obj: _T, type: Optional[Type[_T]] = ...) -> Callable[..., Any]: ... class classmethod(object): # Special, only valid as a decorator. - __func__: Callable + __func__: Callable[..., Any] if sys.version_info >= (3,): __isabstractmethod__: bool - def __init__(self, f: Callable) -> None: ... + def __init__(self, f: Callable[..., Any]) -> None: ... def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... - def __get__(self, obj: _T, type: Optional[Type[_T]] = ...) -> Callable: ... + def __get__(self, obj: _T, type: Optional[Type[_T]] = ...) -> Callable[..., Any]: ... class type(object): __base__: type @@ -168,7 +168,7 @@ class int: def __rtruediv__(self, x: int) -> float: ... def __rmod__(self, x: int) -> int: ... def __rdivmod__(self, x: int) -> Tuple[int, int]: ... - def __pow__(self, x: int) -> Any: ... # Return type can be int or float, depending on x. + def __pow__(self, __x: int, __modulo: Optional[int] = ...) -> Any: ... # Return type can be int or float, depending on x. def __rpow__(self, x: int) -> Any: ... def __and__(self, n: int) -> int: ... def __or__(self, n: int) -> int: ... @@ -183,7 +183,10 @@ class int: def __neg__(self) -> int: ... def __pos__(self) -> int: ... def __invert__(self) -> int: ... + def __trunc__(self) -> int: ... if sys.version_info >= (3,): + def __ceil__(self) -> int: ... + def __floor__(self) -> int: ... def __round__(self, ndigits: Optional[int] = ...) -> int: ... def __getnewargs__(self) -> Tuple[int]: ... @@ -240,11 +243,10 @@ class float: def __rdivmod__(self, x: float) -> Tuple[float, float]: ... def __rpow__(self, x: float) -> float: ... def __getnewargs__(self) -> Tuple[float]: ... + def __trunc__(self) -> int: ... if sys.version_info >= (3,): @overload - def __round__(self) -> int: ... - @overload - def __round__(self, ndigits: None) -> int: ... + def __round__(self, ndigits: None = ...) -> int: ... @overload def __round__(self, ndigits: int) -> float: ... @@ -332,7 +334,7 @@ else: end: int = ...) -> bool: ... def expandtabs(self, tabsize: int = ...) -> unicode: ... def find(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... - def format(self, *args: Any, **kwargs: Any) -> unicode: ... + def format(self, *args: object, **kwargs: object) -> unicode: ... def index(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... @@ -421,7 +423,7 @@ class str(Sequence[str], _str_base): def endswith(self, suffix: Union[Text, Tuple[Text, ...]]) -> bool: ... def expandtabs(self, tabsize: int = ...) -> str: ... def find(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... - def format(self, *args: Any, **kwargs: Any) -> str: ... + def format(self, *args: object, **kwargs: object) -> str: ... if sys.version_info >= (3,): def format_map(self, map: Mapping[str, Any]) -> str: ... def index(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... @@ -667,6 +669,8 @@ class bytearray(MutableSequence[int], ByteString): def decode(self, encoding: Text = ..., errors: Text = ...) -> str: ... def endswith(self, suffix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... def expandtabs(self, tabsize: int = ...) -> bytearray: ... + if sys.version_info < (3,): + def extend(self, iterable: Union[str, Iterable[int]]) -> None: ... if sys.version_info >= (3,): def find(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... if sys.version_info >= (3, 5): @@ -734,7 +738,7 @@ class bytearray(MutableSequence[int], ByteString): def __repr__(self) -> str: ... def __int__(self) -> int: ... def __float__(self) -> float: ... - def __hash__(self) -> int: ... + __hash__: None # type: ignore @overload def __getitem__(self, i: int) -> int: ... @overload @@ -784,9 +788,10 @@ class memoryview(Sized, Container[_mv_container_type]): c_contiguous: bool f_contiguous: bool contiguous: bool + nbytes: int def __init__(self, obj: Union[bytes, bytearray, memoryview]) -> None: ... def __enter__(self) -> memoryview: ... - def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]) -> bool: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]) -> None: ... else: def __init__(self, obj: Union[bytes, bytearray, buffer, memoryview]) -> None: ... @@ -841,13 +846,14 @@ class bool(int): def __getnewargs__(self) -> Tuple[int]: ... class slice(object): - start: Optional[int] - step: Optional[int] - stop: Optional[int] + start: Any + step: Any + stop: Any @overload - def __init__(self, stop: Optional[int]) -> None: ... + def __init__(self, stop: Any) -> None: ... @overload - def __init__(self, start: Optional[int], stop: Optional[int], step: Optional[int] = ...) -> None: ... + def __init__(self, start: Any, stop: Any, step: Any = ...) -> None: ... + __hash__: None # type: ignore def indices(self, len: int) -> Tuple[int, int, int]: ... class tuple(Sequence[_T_co], Generic[_T_co]): @@ -863,7 +869,10 @@ class tuple(Sequence[_T_co], Generic[_T_co]): def __le__(self, x: Tuple[_T_co, ...]) -> bool: ... def __gt__(self, x: Tuple[_T_co, ...]) -> bool: ... def __ge__(self, x: Tuple[_T_co, ...]) -> bool: ... + @overload def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... + @overload + def __add__(self, x: Tuple[Any, ...]) -> Tuple[Any, ...]: ... def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... def count(self, x: Any) -> int: ... @@ -876,9 +885,9 @@ class function: # TODO not defined in builtins! __name__: str __module__: str + __code__: CodeType if sys.version_info >= (3,): __qualname__: str - __code__: CodeType __annotations__: Dict[str, Any] class list(MutableSequence[_T], Generic[_T]): @@ -905,7 +914,7 @@ class list(MutableSequence[_T], Generic[_T]): def __len__(self) -> int: ... def __iter__(self) -> Iterator[_T]: ... def __str__(self) -> str: ... - def __hash__(self) -> int: ... + __hash__: None # type: ignore @overload def __getitem__(self, i: int) -> _T: ... @overload @@ -979,6 +988,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __delitem__(self, v: _KT) -> None: ... def __iter__(self) -> Iterator[_KT]: ... def __str__(self) -> str: ... + __hash__: None # type: ignore class set(MutableSet[_T], Generic[_T]): def __init__(self, iterable: Iterable[_T] = ...) -> None: ... @@ -1015,6 +1025,7 @@ class set(MutableSet[_T], Generic[_T]): def __lt__(self, s: AbstractSet[object]) -> bool: ... def __ge__(self, s: AbstractSet[object]) -> bool: ... def __gt__(self, s: AbstractSet[object]) -> bool: ... + __hash__: None # type: ignore class frozenset(AbstractSet[_T], Generic[_T]): def __init__(self, iterable: Iterable[_T] = ...) -> None: ... @@ -1124,7 +1135,7 @@ if sys.version_info >= (3, 6): # See https://github.com/python/typeshed/pull/991#issuecomment-288160993 class _PathLike(Generic[AnyStr]): def __fspath__(self) -> AnyStr: ... - def compile(source: Union[str, bytes, mod, AST], filename: Union[str, bytes, _PathLike], mode: str, flags: int = ..., dont_inherit: int = ..., optimize: int = ...) -> Any: ... + def compile(source: Union[str, bytes, mod, AST], filename: Union[str, bytes, _PathLike[Any]], mode: str, flags: int = ..., dont_inherit: int = ..., optimize: int = ...) -> Any: ... elif sys.version_info >= (3,): def compile(source: Union[str, bytes, mod, AST], filename: Union[str, bytes], mode: str, flags: int = ..., dont_inherit: int = ..., optimize: int = ...) -> Any: ... else: @@ -1180,9 +1191,11 @@ else: @overload def iter(__iterable: Iterable[_T]) -> Iterator[_T]: ... @overload -def iter(__function: Callable[[], _T], __sentinel: _T) -> Iterator[_T]: ... -def isinstance(__o: object, __t: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... -def issubclass(__cls: type, __classinfo: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... +def iter(__function: Callable[[], Optional[_T]], __sentinel: None) -> Iterator[_T]: ... +@overload +def iter(__function: Callable[[], Any], __sentinel: Any) -> Iterator[Any]: ... +def isinstance(__o: object, __t: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]) -> bool: ... +def issubclass(__cls: type, __classinfo: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]) -> bool: ... def len(__o: Sized) -> int: ... if sys.version_info >= (3,): def license() -> None: ... @@ -1318,7 +1331,7 @@ def next(__i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ... def oct(__i: Union[int, _SupportsIndex]) -> str: ... if sys.version_info >= (3, 6): - def open(file: Union[str, bytes, int, _PathLike], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., + def open(file: Union[str, bytes, int, _PathLike[Any]], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., errors: Optional[str] = ..., newline: Optional[str] = ..., closefd: bool = ..., opener: Optional[Callable[[str, int], int]] = ...) -> IO[Any]: ... elif sys.version_info >= (3,): @@ -1390,7 +1403,7 @@ if sys.version_info >= (3,): else: def sorted(__iterable: Iterable[_T], *, cmp: Callable[[_T, _T], int] = ..., - key: Callable[[_T], Any] = ..., + key: Optional[Callable[[_T], Any]] = ..., reverse: bool = ...) -> List[_T]: ... @overload def sum(__iterable: Iterable[_T]) -> Union[_T, int]: ... @@ -1436,8 +1449,10 @@ else: def zip(__iter1: Iterable[Any], __iter2: Iterable[Any], __iter3: Iterable[Any], __iter4: Iterable[Any], __iter5: Iterable[Any], __iter6: Iterable[Any], *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... -def __import__(name: Text, globals: Dict[str, Any] = ..., locals: Dict[str, Any] = ..., - fromlist: List[str] = ..., level: int = ...) -> Any: ... +def __import__(name: Text, globals: Optional[Mapping[str, Any]] = ..., + locals: Optional[Mapping[str, Any]] = ..., + fromlist: Sequence[str] = ..., + level: int = ...) -> ModuleType: ... # Actually the type of Ellipsis is , but since it's # not exposed anywhere under that name, we make it private here. @@ -1467,6 +1482,8 @@ class BaseException(object): __suppress_context__: bool __traceback__: Optional[TracebackType] def __init__(self, *args: object) -> None: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... if sys.version_info < (3,): def __getitem__(self, i: int) -> Any: ... def __getslice__(self, start: int, stop: int) -> Tuple[Any, ...]: ... @@ -1523,7 +1540,7 @@ class SyntaxError(_StandardError): msg: str lineno: int offset: Optional[int] - text: str + text: Optional[str] filename: str class SystemError(_StandardError): ... class TypeError(_StandardError): ... @@ -1612,7 +1629,7 @@ if sys.version_info < (3,): def next(self) -> str: ... def read(self, n: int = ...) -> str: ... def __enter__(self) -> BinaryIO: ... - def __exit__(self, t: Optional[type] = ..., exc: Optional[BaseException] = ..., tb: Optional[Any] = ...) -> bool: ... + def __exit__(self, t: Optional[type] = ..., exc: Optional[BaseException] = ..., tb: Optional[Any] = ...) -> Optional[bool]: ... def flush(self) -> None: ... def fileno(self) -> int: ... def isatty(self) -> bool: ... diff --git a/stdlib/2and3/cProfile.pyi b/stdlib/2and3/cProfile.pyi index 71e25edb8355..da0eb21dfc0d 100644 --- a/stdlib/2and3/cProfile.pyi +++ b/stdlib/2and3/cProfile.pyi @@ -5,7 +5,7 @@ from typing import Any, Callable, Dict, Optional, Text, TypeVar, Union def run(statement: str, filename: Optional[str] = ..., sort: Union[str, int] = ...) -> None: ... def runctx(statement: str, globals: Dict[str, Any], locals: Dict[str, Any], filename: Optional[str] = ..., sort: Union[str, int] = ...) -> None: ... -_SelfT = TypeVar('_SelfT', bound='Profile') +_SelfT = TypeVar('_SelfT', bound=Profile) _T = TypeVar('_T') if sys.version_info >= (3, 6): _Path = Union[bytes, Text, os.PathLike[Any]] diff --git a/stdlib/2and3/cgi.pyi b/stdlib/2and3/cgi.pyi index 02979c090f20..0f580ccfce7f 100644 --- a/stdlib/2and3/cgi.pyi +++ b/stdlib/2and3/cgi.pyi @@ -101,7 +101,7 @@ class FieldStorage(object): if sys.version_info < (3, 0): from UserDict import UserDict - class FormContentDict(UserDict): + class FormContentDict(UserDict[str, List[str]]): query_string: str def __init__(self, environ: Mapping[str, str] = ..., keep_blank_values: int = ..., strict_parsing: int = ...) -> None: ... diff --git a/stdlib/2and3/codecs.pyi b/stdlib/2and3/codecs.pyi index b99ce9134a6f..7c06ee937a85 100644 --- a/stdlib/2and3/codecs.pyi +++ b/stdlib/2and3/codecs.pyi @@ -31,6 +31,8 @@ class _IncrementalDecoder(Protocol): def encode(obj: _Decoded, encoding: str = ..., errors: str = ...) -> _Encoded: ... def decode(obj: _Encoded, encoding: str = ..., errors: str = ...) -> _Decoded: ... def lookup(encoding: str) -> CodecInfo: ... +def utf_16_be_decode(__obj: _Encoded, __errors: str = ..., __final: bool = ...) -> Tuple[_Decoded, int]: ... # undocumented +def utf_16_be_encode(__obj: _Decoded, __errors: str = ...) -> Tuple[_Encoded, int]: ... # undocumented class CodecInfo(Tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]): @property @@ -63,7 +65,7 @@ def getincrementalencoder(encoding: str) -> _IncrementalEncoder: ... def getincrementaldecoder(encoding: str) -> _IncrementalDecoder: ... def getreader(encoding: str) -> _StreamReader: ... def getwriter(encoding: str) -> _StreamWriter: ... -def register(search_function: Callable[[str], CodecInfo]) -> None: ... +def register(search_function: Callable[[str], Optional[CodecInfo]]) -> None: ... def open(filename: str, mode: str = ..., encoding: str = ..., errors: str = ..., buffering: int = ...) -> StreamReaderWriter: ... def EncodedFile(file: IO[_Encoded], data_encoding: str, file_encoding: str = ..., errors: str = ...) -> StreamRecoder: ... def iterencode(iterator: Iterable[_Decoded], encoding: str, errors: str = ...) -> Generator[_Encoded, None, None]: ... @@ -186,7 +188,7 @@ class StreamReaderWriter(TextIO): def __enter__(self: _T) -> _T: ... def __exit__( self, typ: Optional[Type[BaseException]], exc: Optional[BaseException], tb: Optional[types.TracebackType] - ) -> bool: ... + ) -> None: ... def __getattr__(self, name: str) -> Any: ... # These methods don't actually exist directly, but they are needed to satisfy the TextIO # interface. At runtime, they are delegated through __getattr__. @@ -227,7 +229,7 @@ class StreamRecoder(BinaryIO): def __enter__(self: _SRT) -> _SRT: ... def __exit__( self, type: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[types.TracebackType] - ) -> bool: ... + ) -> None: ... # These methods don't actually exist directly, but they are needed to satisfy the BinaryIO # interface. At runtime, they are delegated through __getattr__. def seek(self, offset: int, whence: int = ...) -> int: ... diff --git a/stdlib/2and3/contextlib.pyi b/stdlib/2and3/contextlib.pyi index dec1b411d515..2832d94b8518 100644 --- a/stdlib/2and3/contextlib.pyi +++ b/stdlib/2and3/contextlib.pyi @@ -18,17 +18,20 @@ if sys.version_info >= (3, 7): from typing import AsyncContextManager as AbstractAsyncContextManager _T = TypeVar('_T') +_F = TypeVar('_F', bound=Callable[..., Any]) _ExitFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], bool] -_CM_EF = TypeVar('_CM_EF', ContextManager, _ExitFunc) +_CM_EF = TypeVar('_CM_EF', ContextManager[Any], _ExitFunc) if sys.version_info >= (3, 2): - class GeneratorContextManager(ContextManager[_T], Generic[_T]): - def __call__(self, func: Callable[..., _T]) -> Callable[..., _T]: ... - def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., GeneratorContextManager[_T]]: ... + class _GeneratorContextManager(ContextManager[_T], Generic[_T]): + def __call__(self, func: _F) -> _F: ... + def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., _GeneratorContextManager[_T]]: ... else: + class GeneratorContextManager(ContextManager[_T], Generic[_T]): + def __call__(self, func: _F) -> _F: ... def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., ContextManager[_T]]: ... if sys.version_info >= (3, 7): @@ -43,19 +46,22 @@ class closing(ContextManager[_T], Generic[_T]): if sys.version_info >= (3, 4): class suppress(ContextManager[None]): def __init__(self, *exceptions: Type[BaseException]) -> None: ... + def __exit__(self, exctype: Optional[Type[BaseException]], + excinst: Optional[BaseException], + exctb: Optional[TracebackType]) -> bool: ... class redirect_stdout(ContextManager[None]): - def __init__(self, new_target: IO[str]) -> None: ... + def __init__(self, new_target: Optional[IO[str]]) -> None: ... if sys.version_info >= (3, 5): class redirect_stderr(ContextManager[None]): - def __init__(self, new_target: IO[str]) -> None: ... + def __init__(self, new_target: Optional[IO[str]]) -> None: ... if sys.version_info >= (3,): class ContextDecorator: def __call__(self, func: Callable[..., None]) -> Callable[..., ContextManager[None]]: ... - _U = TypeVar('_U', bound='ExitStack') + _U = TypeVar('_U', bound=ExitStack) class ExitStack(ContextManager[ExitStack]): def __init__(self) -> None: ... @@ -66,17 +72,20 @@ if sys.version_info >= (3,): def pop_all(self: _U) -> _U: ... def close(self) -> None: ... def __enter__(self: _U) -> _U: ... + def __exit__(self, __exc_type: Optional[Type[BaseException]], + __exc_value: Optional[BaseException], + __traceback: Optional[TracebackType]) -> bool: ... if sys.version_info >= (3, 7): from typing import Awaitable - _S = TypeVar('_S', bound='AsyncExitStack') + _S = TypeVar('_S', bound=AsyncExitStack) _ExitCoroFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], Awaitable[bool]] _CallbackCoroFunc = Callable[..., Awaitable[Any]] - _ACM_EF = TypeVar('_ACM_EF', AsyncContextManager, _ExitCoroFunc) + _ACM_EF = TypeVar('_ACM_EF', AsyncContextManager[Any], _ExitCoroFunc) class AsyncExitStack(AsyncContextManager[AsyncExitStack]): def __init__(self) -> None: ... @@ -91,6 +100,9 @@ if sys.version_info >= (3, 7): def pop_all(self: _S) -> _S: ... def aclose(self) -> Awaitable[None]: ... def __aenter__(self: _S) -> Awaitable[_S]: ... + def __aexit__(self, __exc_type: Optional[Type[BaseException]], + __exc_value: Optional[BaseException], + __traceback: Optional[TracebackType]) -> Awaitable[bool]: ... if sys.version_info >= (3, 7): @overload diff --git a/stdlib/2and3/csv.pyi b/stdlib/2and3/csv.pyi index da5c709df42a..28a35fab9cc0 100644 --- a/stdlib/2and3/csv.pyi +++ b/stdlib/2and3/csv.pyi @@ -79,7 +79,7 @@ class DictWriter(object): restval: Optional[Any] extrasaction: str writer: _writer - def __init__(self, f: Any, fieldnames: Sequence[str], + def __init__(self, f: Any, fieldnames: Iterable[str], restval: Optional[Any] = ..., extrasaction: str = ..., dialect: _Dialect = ..., *args: Any, **kwds: Any) -> None: ... def writeheader(self) -> None: ... diff --git a/stdlib/2and3/ctypes/__init__.pyi b/stdlib/2and3/ctypes/__init__.pyi index e4cd6b48fc18..2c7653f5f40f 100644 --- a/stdlib/2and3/ctypes/__init__.pyi +++ b/stdlib/2and3/ctypes/__init__.pyi @@ -228,7 +228,7 @@ class c_wchar_p(_PointerLike, _SimpleCData[Optional[Text]]): def __init__(self, value: Optional[_UnionT[int, Text]] = ...) -> None: ... class c_bool(_SimpleCData[bool]): - def __init__(self, value: bool) -> None: ... + def __init__(self, value: bool = ...) -> None: ... if sys.platform == 'win32': class HRESULT(_SimpleCData[int]): ... # TODO undocumented diff --git a/stdlib/2and3/curses/__init__.pyi b/stdlib/2and3/curses/__init__.pyi index c327c7803931..8bd806b476b4 100644 --- a/stdlib/2and3/curses/__init__.pyi +++ b/stdlib/2and3/curses/__init__.pyi @@ -1,9 +1,15 @@ from _curses import * # noqa: F403 +from _curses import _CursesWindow as _CursesWindow from typing import TypeVar, Callable, Any _T = TypeVar('_T') +# available after calling `curses.initscr()` LINES: int COLS: int +# available after calling `curses.start_color()` +COLORS: int +COLOR_PAIRS: int + def wrapper(func: Callable[..., _T], *arg: Any, **kwds: Any) -> _T: ... diff --git a/stdlib/2and3/datetime.pyi b/stdlib/2and3/datetime.pyi index ccc92ba35078..df3fda4a3ae4 100644 --- a/stdlib/2and3/datetime.pyi +++ b/stdlib/2and3/datetime.pyi @@ -233,10 +233,10 @@ class datetime(date): def utcnow(cls) -> datetime: ... if sys.version_info >= (3, 6): @classmethod - def combine(cls, date: date, time: time, tzinfo: Optional[_tzinfo] = ...) -> datetime: ... + def combine(cls, date: _date, time: _time, tzinfo: Optional[_tzinfo] = ...) -> datetime: ... else: @classmethod - def combine(cls, date: date, time: time) -> datetime: ... + def combine(cls, date: _date, time: _time) -> datetime: ... if sys.version_info >= (3, 7): @classmethod def fromisoformat(cls, date_string: str) -> datetime: ... diff --git a/stdlib/2and3/distutils/version.pyi b/stdlib/2and3/distutils/version.pyi index cb636b4d95fb..36ee4b84b96a 100644 --- a/stdlib/2and3/distutils/version.pyi +++ b/stdlib/2and3/distutils/version.pyi @@ -2,7 +2,7 @@ import sys from abc import abstractmethod from typing import Any, Optional, TypeVar, Union, Pattern, Text, Tuple -_T = TypeVar('_T', bound='Version') +_T = TypeVar('_T', bound=Version) class Version: def __repr__(self) -> str: ... diff --git a/stdlib/2and3/doctest.pyi b/stdlib/2and3/doctest.pyi index 8151fb572799..b6df8c5b053d 100644 --- a/stdlib/2and3/doctest.pyi +++ b/stdlib/2and3/doctest.pyi @@ -56,8 +56,8 @@ class DocTest: class DocTestParser: def parse(self, string: str, name: str = ...) -> List[Union[str, Example]]: ... - def get_doctest(self, string: str, globs: Dict[str, Any], name: str, filename: Optional[str], lineno: Optional[str]) -> DocTest: ... - def get_examples(self, strin: str, name: str = ...) -> List[Example]: ... + def get_doctest(self, string: str, globs: Dict[str, Any], name: str, filename: Optional[str], lineno: Optional[int]) -> DocTest: ... + def get_examples(self, string: str, name: str = ...) -> List[Example]: ... class DocTestFinder: def __init__(self, verbose: bool = ..., parser: DocTestParser = ..., diff --git a/stdlib/2and3/errno.pyi b/stdlib/2and3/errno.pyi index 14987bbe80df..731681f1c6fd 100644 --- a/stdlib/2and3/errno.pyi +++ b/stdlib/2and3/errno.pyi @@ -128,3 +128,13 @@ ENAVAIL: int EISNAM: int EREMOTEIO: int EDQUOT: int +ECANCELED: int # undocumented +EKEYEXPIRED: int # undocumented +EKEYREJECTED: int # undocumented +EKEYREVOKED: int # undocumented +EMEDIUMTYPE: int # undocumented +ENOKEY: int # undocumented +ENOMEDIUM: int # undocumented +ENOTRECOVERABLE: int # undocumented +EOWNERDEAD: int # undocumented +ERFKILL: int # undocumented diff --git a/stdlib/2and3/formatter.pyi b/stdlib/2and3/formatter.pyi index 77a4956260ed..b11ce7e56293 100644 --- a/stdlib/2and3/formatter.pyi +++ b/stdlib/2and3/formatter.pyi @@ -92,9 +92,9 @@ class AbstractWriter(NullWriter): def send_literal_data(self, data: str) -> None: ... class DumbWriter(NullWriter): - file: IO + file: IO[str] maxcol: int - def __init__(self, file: Optional[IO] = ..., maxcol: int = ...) -> None: ... + def __init__(self, file: Optional[IO[str]] = ..., maxcol: int = ...) -> None: ... def reset(self) -> None: ... def send_paragraph(self, blankline: int) -> None: ... def send_line_break(self) -> None: ... diff --git a/stdlib/2and3/ftplib.pyi b/stdlib/2and3/ftplib.pyi index dff8c4788bc2..9c303f5c46b1 100644 --- a/stdlib/2and3/ftplib.pyi +++ b/stdlib/2and3/ftplib.pyi @@ -1,11 +1,27 @@ -# Stubs for ftplib (Python 2.7/3) import sys -from typing import Optional, BinaryIO, Tuple, TextIO, Iterable, Callable, List, Union, Iterator, Dict, Text, Type, TypeVar, Generic, Any +from typing import ( + Any, + BinaryIO, + Callable, + Dict, + Generic, + Iterable, + Iterator, + List, + Optional, + Protocol, + Text, + TextIO, + Tuple, + Type, + TypeVar, + Union, +) from types import TracebackType from socket import socket from ssl import SSLContext -_T = TypeVar('_T') +_T = TypeVar("_T") _IntOrStr = Union[int, Text] MSG_OOB: int @@ -23,6 +39,12 @@ class error_proto(Error): ... all_errors = Tuple[Exception, ...] +class _Readable(Protocol): + def read(self, __length: int) -> bytes: ... + +class _ReadLineable(Protocol): + def readline(self, _length: int) -> bytes: ... + class FTP: debugging: int @@ -43,22 +65,31 @@ class FTP: file: Optional[TextIO] encoding: str def __enter__(self: _T) -> _T: ... - def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... + def __exit__( + self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType] + ) -> None: ... else: file: Optional[BinaryIO] if sys.version_info >= (3, 3): source_address: Optional[Tuple[str, int]] - def __init__(self, host: Text = ..., user: Text = ..., passwd: Text = ..., acct: Text = ..., - timeout: float = ..., source_address: Optional[Tuple[str, int]] = ...) -> None: ... - def connect(self, host: Text = ..., port: int = ..., timeout: float = ..., - source_address: Optional[Tuple[str, int]] = ...) -> str: ... + def __init__( + self, + host: Text = ..., + user: Text = ..., + passwd: Text = ..., + acct: Text = ..., + timeout: float = ..., + source_address: Optional[Tuple[str, int]] = ..., + ) -> None: ... + def connect( + self, host: Text = ..., port: int = ..., timeout: float = ..., source_address: Optional[Tuple[str, int]] = ... + ) -> str: ... else: - def __init__(self, host: Text = ..., user: Text = ..., passwd: Text = ..., acct: Text = ..., - timeout: float = ...) -> None: ... + def __init__( + self, host: Text = ..., user: Text = ..., passwd: Text = ..., acct: Text = ..., timeout: float = ... + ) -> None: ... def connect(self, host: Text = ..., port: int = ..., timeout: float = ...) -> str: ... - def getwelcome(self) -> str: ... def set_debuglevel(self, level: int) -> None: ... def debug(self, level: int) -> None: ... @@ -78,22 +109,26 @@ class FTP: def makeport(self) -> socket: ... def makepasv(self) -> Tuple[str, int]: ... def login(self, user: Text = ..., passwd: Text = ..., acct: Text = ...) -> str: ... - # In practice, `rest` rest can actually be anything whose str() is an integer sequence, so to make it simple we allow integers. def ntransfercmd(self, cmd: Text, rest: Optional[_IntOrStr] = ...) -> Tuple[socket, int]: ... def transfercmd(self, cmd: Text, rest: Optional[_IntOrStr] = ...) -> socket: ... - def retrbinary(self, cmd: Text, callback: Callable[[bytes], Any], blocksize: int = ..., rest: Optional[_IntOrStr] = ...) -> str: ... - def storbinary(self, cmd: Text, fp: BinaryIO, blocksize: int = ..., callback: Optional[Callable[[bytes], Any]] = ..., rest: Optional[_IntOrStr] = ...) -> str: ... - + def retrbinary( + self, cmd: Text, callback: Callable[[bytes], Any], blocksize: int = ..., rest: Optional[_IntOrStr] = ... + ) -> str: ... + def storbinary( + self, + cmd: Text, + fp: _Readable, + blocksize: int = ..., + callback: Optional[Callable[[bytes], Any]] = ..., + rest: Optional[_IntOrStr] = ..., + ) -> str: ... def retrlines(self, cmd: Text, callback: Optional[Callable[[str], Any]] = ...) -> str: ... - def storlines(self, cmd: Text, fp: BinaryIO, callback: Optional[Callable[[bytes], Any]] = ...) -> str: ... - + def storlines(self, cmd: Text, fp: _ReadLineable, callback: Optional[Callable[[bytes], Any]] = ...) -> str: ... def acct(self, password: Text) -> str: ... def nlst(self, *args: Text) -> List[str]: ... - # Technically only the last arg can be a Callable but ... def dir(self, *args: Union[str, Callable[[str], None]]) -> None: ... - if sys.version_info >= (3, 3): def mlsd(self, path: Text = ..., facts: Iterable[str] = ...) -> Iterator[Tuple[str, Dict[str, str]]]: ... def rename(self, fromname: Text, toname: Text) -> str: ... @@ -107,21 +142,26 @@ class FTP: def close(self) -> None: ... class FTP_TLS(FTP): - def __init__(self, host: Text = ..., user: Text = ..., passwd: Text = ..., acct: Text = ..., - keyfile: Optional[str] = ..., certfile: Optional[str] = ..., - context: Optional[SSLContext] = ..., timeout: float = ..., - source_address: Optional[Tuple[str, int]] = ...) -> None: ... - + def __init__( + self, + host: Text = ..., + user: Text = ..., + passwd: Text = ..., + acct: Text = ..., + keyfile: Optional[str] = ..., + certfile: Optional[str] = ..., + context: Optional[SSLContext] = ..., + timeout: float = ..., + source_address: Optional[Tuple[str, int]] = ..., + ) -> None: ... ssl_version: int keyfile: Optional[str] certfile: Optional[str] context: SSLContext - def login(self, user: Text = ..., passwd: Text = ..., acct: Text = ..., secure: bool = ...) -> str: ... def auth(self) -> str: ... def prot_p(self) -> str: ... def prot_c(self) -> str: ... - if sys.version_info >= (3, 3): def ccc(self) -> str: ... diff --git a/stdlib/2and3/imaplib.pyi b/stdlib/2and3/imaplib.pyi index ab32e7bac31f..07272ce02548 100644 --- a/stdlib/2and3/imaplib.pyi +++ b/stdlib/2and3/imaplib.pyi @@ -5,7 +5,7 @@ import subprocess import sys import time from socket import socket as _socket -from ssl import SSLSocket +from ssl import SSLSocket, SSLContext from typing import Any, Callable, Dict, IO, List, Optional, Pattern, Text, Tuple, Type, Union CommandResults = Tuple[str, List[Any]] @@ -44,7 +44,7 @@ class IMAP4: def recent(self) -> CommandResults: ... def response(self, code: str) -> CommandResults: ... def append(self, mailbox: str, flags: str, date_time: str, message: str) -> str: ... - def authenticate(self, mechanism: str, authobject: Callable) -> Tuple[str, str]: ... + def authenticate(self, mechanism: str, authobject: Callable[[bytes], Optional[bytes]]) -> Tuple[str, str]: ... def capability(self) -> CommandResults: ... def check(self) -> CommandResults: ... def close(self) -> CommandResults: ... @@ -52,6 +52,8 @@ class IMAP4: def create(self, mailbox: str) -> CommandResults: ... def delete(self, mailbox: str) -> CommandResults: ... def deleteacl(self, mailbox: str, who: str) -> CommandResults: ... + if sys.version_info >= (3, 5): + def enable(self, capability: str) -> CommandResults: ... def expunge(self) -> CommandResults: ... def fetch(self, message_set: str, message_parts: str) -> CommandResults: ... def getacl(self, mailbox: str) -> CommandResults: ... @@ -72,24 +74,27 @@ class IMAP4: def search(self, charset: Optional[str], *criteria: str) -> CommandResults: ... def select(self, mailbox: str = ..., readonly: bool = ...) -> CommandResults: ... def setacl(self, mailbox: str, who: str, what: str) -> CommandResults: ... - def setannotation(self, *args: List[str]) -> CommandResults: ... + def setannotation(self, *args: str) -> CommandResults: ... def setquota(self, root: str, limits: str) -> CommandResults: ... - def sort(self, sort_criteria: str, charset: str, *search_criteria: List[str]) -> CommandResults: ... + def sort(self, sort_criteria: str, charset: str, *search_criteria: str) -> CommandResults: ... if sys.version_info >= (3,): def starttls(self, ssl_context: Optional[Any] = ...) -> CommandResults: ... def status(self, mailbox: str, names: str) -> CommandResults: ... def store(self, message_set: str, command: str, flags: str) -> CommandResults: ... def subscribe(self, mailbox: str) -> CommandResults: ... - def thread(self, threading_algorithm: str, charset: str, *search_criteria: List[str]) -> CommandResults: ... - def uid(self, command: str, *args: List[str]) -> CommandResults: ... + def thread(self, threading_algorithm: str, charset: str, *search_criteria: str) -> CommandResults: ... + def uid(self, command: str, *args: str) -> CommandResults: ... def unsubscribe(self, mailbox: str) -> CommandResults: ... - def xatom(self, name: str, *args: List[str]) -> CommandResults: ... + def xatom(self, name: str, *args: str) -> CommandResults: ... def print_log(self) -> None: ... class IMAP4_SSL(IMAP4): keyfile: str = ... certfile: str = ... - def __init__(self, host: str = ..., port: int = ..., keyfile: Optional[str] = ..., certfile: Optional[str] = ...) -> None: ... + if sys.version_info >= (3, 3): + def __init__(self, host: str = ..., port: int = ..., keyfile: Optional[str] = ..., certfile: Optional[str] = ..., ssl_context: Optional[SSLContext] = ...) -> None: ... + else: + def __init__(self, host: str = ..., port: int = ..., keyfile: Optional[str] = ..., certfile: Optional[str] = ...) -> None: ... host: str = ... port: int = ... sock: _socket = ... @@ -111,7 +116,7 @@ class IMAP4_stream(IMAP4): port: int = ... sock: _socket = ... file: IO[Any] = ... - process: subprocess.Popen = ... + process: subprocess.Popen[bytes] = ... writefile: IO[Any] = ... readfile: IO[Any] = ... def open(self, host: str = ..., port: Optional[int] = ...) -> None: ... @@ -121,8 +126,8 @@ class IMAP4_stream(IMAP4): def shutdown(self) -> None: ... class _Authenticator: - mech: Callable = ... - def __init__(self, mechinst: Callable) -> None: ... + mech: Callable[[bytes], bytes] = ... + def __init__(self, mechinst: Callable[[bytes], bytes]) -> None: ... def process(self, data: str) -> str: ... def encode(self, inp: bytes) -> str: ... def decode(self, inp: str) -> bytes: ... diff --git a/stdlib/2and3/lib2to3/pgen2/literals.pyi b/stdlib/2and3/lib2to3/pgen2/literals.pyi index 8719500dadd0..3166ffbf304c 100644 --- a/stdlib/2and3/lib2to3/pgen2/literals.pyi +++ b/stdlib/2and3/lib2to3/pgen2/literals.pyi @@ -4,6 +4,6 @@ from typing import Dict, Match, Text simple_escapes: Dict[Text, Text] -def escape(m: Match) -> Text: ... +def escape(m: Match[str]) -> Text: ... def evalString(s: Text) -> Text: ... def test() -> None: ... diff --git a/stdlib/2and3/logging/__init__.pyi b/stdlib/2and3/logging/__init__.pyi index d736b0838230..79ee6261b22b 100644 --- a/stdlib/2and3/logging/__init__.pyi +++ b/stdlib/2and3/logging/__init__.pyi @@ -1,4 +1,4 @@ -# Stubs for logging (Python 3.4) +# Stubs for logging (Python 3.7) from typing import ( Any, Callable, Dict, Iterable, List, Mapping, MutableMapping, Optional, IO, @@ -26,6 +26,9 @@ else: _Path = str raiseExceptions: bool +logThreads: bool +logMultiprocessing: bool +logProcesses: bool def currentframe() -> FrameType: ... @@ -33,7 +36,7 @@ if sys.version_info >= (3,): _levelToName: Dict[int, str] _nameToLevel: Dict[str, int] else: - _levelNames: dict + _levelNames: Dict[Union[int, str], Union[str, int]] # Union[int:str, str:int] class Filterer(object): filters: List[Filter] @@ -50,8 +53,8 @@ class Logger(Filterer): handlers: List[Handler] disabled: int def __init__(self, name: str, level: _Level = ...) -> None: ... - def setLevel(self, level: Union[int, str]) -> None: ... - def isEnabledFor(self, lvl: int) -> bool: ... + def setLevel(self, level: _Level) -> None: ... + def isEnabledFor(self, level: int) -> bool: ... def getEffectiveLevel(self) -> int: ... def getChild(self, suffix: str) -> Logger: ... if sys.version_info >= (3,): @@ -115,7 +118,7 @@ class Logger(Filterer): def findCaller(self) -> Tuple[str, int, str]: ... def handle(self, record: LogRecord) -> None: ... if sys.version_info >= (3,): - def makeRecord(self, name: str, lvl: int, fn: str, lno: int, msg: Any, + def makeRecord(self, name: str, level: int, fn: str, lno: int, msg: Any, args: _ArgsType, exc_info: Optional[_SysExcInfoType], func: Optional[str] = ..., @@ -123,7 +126,7 @@ class Logger(Filterer): sinfo: Optional[str] = ...) -> LogRecord: ... else: def makeRecord(self, - name: str, lvl: int, fn: str, lno: int, msg: Any, + name: str, level: int, fn: str, lno: int, msg: Any, args: _ArgsType, exc_info: Optional[_SysExcInfoType], func: Optional[str] = ..., @@ -151,8 +154,8 @@ class Handler(Filterer): def createLock(self) -> None: ... def acquire(self) -> None: ... def release(self) -> None: ... - def setLevel(self, lvl: Union[int, str]) -> None: ... - def setFormatter(self, form: Formatter) -> None: ... + def setLevel(self, level: _Level) -> None: ... + def setFormatter(self, fmt: Formatter) -> None: ... def addFilter(self, filt: _FilterType) -> None: ... def removeFilter(self, filt: _FilterType) -> None: ... def filter(self, record: LogRecord) -> bool: ... @@ -354,17 +357,17 @@ def getLevelName(lvl: Union[int, str]) -> Any: ... def makeLogRecord(attrdict: Mapping[str, Any]) -> LogRecord: ... if sys.version_info >= (3,): - def basicConfig(*, filename: _Path = ..., filemode: str = ..., - format: str = ..., datefmt: str = ..., style: str = ..., - level: _Level = ..., stream: IO[str] = ..., - handlers: Iterable[Handler] = ...) -> None: ... + def basicConfig(*, filename: Optional[_Path] = ..., filemode: str = ..., + format: str = ..., datefmt: Optional[str] = ..., style: str = ..., + level: Optional[_Level] = ..., stream: Optional[IO[str]] = ..., + handlers: Optional[Iterable[Handler]] = ...) -> None: ... else: @overload def basicConfig() -> None: ... @overload - def basicConfig(*, filename: str = ..., filemode: str = ..., - format: str = ..., datefmt: str = ..., - level: _Level = ..., stream: IO[str] = ...) -> None: ... + def basicConfig(*, filename: Optional[str] = ..., filemode: str = ..., + format: str = ..., datefmt: Optional[str] = ..., + level: Optional[_Level] = ..., stream: IO[str] = ...) -> None: ... def shutdown() -> None: ... def setLoggerClass(klass: type) -> None: ... @@ -380,17 +383,19 @@ if sys.version_info >= (3,): class StreamHandler(Handler): - stream: IO[str] - if sys.version_info >= (3,): + stream: IO[str] # undocumented + if sys.version_info >= (3, 2): terminator: str def __init__(self, stream: Optional[IO[str]] = ...) -> None: ... + if sys.version_info >= (3, 7): + def setStream(self, stream: IO[str]) -> Optional[IO[str]]: ... -class FileHandler(Handler): - baseFilename: str - mode: str - encoding: Optional[str] - delay: bool +class FileHandler(StreamHandler): + baseFilename: str # undocumented + mode: str # undocumented + encoding: Optional[str] # undocumented + delay: bool # undocumented def __init__(self, filename: _Path, mode: str = ..., encoding: Optional[str] = ..., delay: bool = ...) -> None: ... diff --git a/stdlib/2and3/logging/handlers.pyi b/stdlib/2and3/logging/handlers.pyi index c18ddccf568f..5b923ea8d5b5 100644 --- a/stdlib/2and3/logging/handlers.pyi +++ b/stdlib/2and3/logging/handlers.pyi @@ -6,7 +6,9 @@ from socket import SocketType import ssl import sys from typing import Any, Callable, Dict, List, Optional, Tuple, Union, overload -if sys.version_info >= (3,): +if sys.version_info >= (3, 7): + from queue import SimpleQueue, Queue +elif sys.version_info >= (3,): from queue import Queue else: from Queue import Queue @@ -195,13 +197,20 @@ class HTTPHandler(Handler): if sys.version_info >= (3,): class QueueHandler(Handler): - def __init__(self, queue: Queue) -> None: ... + if sys.version_info >= (3, 7): + def __init__(self, queue: Union[SimpleQueue[Any], Queue[Any]]) -> None: ... + else: + def __init__(self, queue: Queue[Any]) -> None: ... def prepare(self, record: LogRecord) -> Any: ... def enqueue(self, record: LogRecord) -> None: ... class QueueListener: - if sys.version_info >= (3, 5): - def __init__(self, queue: Queue, *handlers: Handler, + if sys.version_info >= (3, 7): + def __init__(self, queue: Union[SimpleQueue[Any], Queue[Any]], + *handlers: Handler, + respect_handler_level: bool = ...) -> None: ... + elif sys.version_info >= (3, 5): + def __init__(self, queue: Queue[Any], *handlers: Handler, respect_handler_level: bool = ...) -> None: ... else: def __init__(self, diff --git a/stdlib/2and3/marshal.pyi b/stdlib/2and3/marshal.pyi index 6eb3f175d145..9848f775459e 100644 --- a/stdlib/2and3/marshal.pyi +++ b/stdlib/2and3/marshal.pyi @@ -4,5 +4,5 @@ version: int def dump(value: Any, file: IO[Any], version: int = ...) -> None: ... def load(file: IO[Any]) -> Any: ... -def dumps(value: Any, version: int = ...) -> str: ... -def loads(string: str) -> Any: ... +def dumps(value: Any, version: int = ...) -> bytes: ... +def loads(string: bytes) -> Any: ... diff --git a/stdlib/2and3/math.pyi b/stdlib/2and3/math.pyi index 25eb1c4ba127..b3b8579280cf 100644 --- a/stdlib/2and3/math.pyi +++ b/stdlib/2and3/math.pyi @@ -40,7 +40,7 @@ else: def floor(x: SupportsFloat) -> float: ... def fmod(x: SupportsFloat, y: SupportsFloat) -> float: ... def frexp(x: SupportsFloat) -> Tuple[float, int]: ... -def fsum(iterable: Iterable) -> float: ... +def fsum(iterable: Iterable[float]) -> float: ... def gamma(x: SupportsFloat) -> float: ... if sys.version_info >= (3, 5): def gcd(a: int, b: int) -> int: ... diff --git a/stdlib/2and3/mmap.pyi b/stdlib/2and3/mmap.pyi index 709d5d93f291..b8d040e9cf30 100644 --- a/stdlib/2and3/mmap.pyi +++ b/stdlib/2and3/mmap.pyi @@ -49,7 +49,7 @@ class _mmap(Generic[AnyStr]): def __len__(self) -> int: ... if sys.version_info >= (3,): - class mmap(_mmap, ContextManager[mmap], Iterable[bytes], Sized): + class mmap(_mmap[bytes], ContextManager[mmap], Iterable[bytes], Sized): closed: bool def rfind(self, sub: bytes, start: int = ..., stop: int = ...) -> int: ... @overload @@ -65,7 +65,7 @@ if sys.version_info >= (3,): # __len__, so we claim that there is also an __iter__ to help type checkers. def __iter__(self) -> Iterator[bytes]: ... else: - class mmap(_mmap, Sequence[bytes]): + class mmap(_mmap[bytes], Sequence[bytes]): def rfind(self, string: bytes, start: int = ..., stop: int = ...) -> int: ... def __getitem__(self, index: Union[int, slice]) -> bytes: ... def __getslice__(self, i: Optional[int], j: Optional[int]) -> bytes: ... diff --git a/stdlib/2and3/numbers.pyi b/stdlib/2and3/numbers.pyi index 50b561c24a32..befe7d53a781 100644 --- a/stdlib/2and3/numbers.pyi +++ b/stdlib/2and3/numbers.pyi @@ -5,7 +5,7 @@ # Note: these stubs are incomplete. The more complex type # signatures are currently omitted. -from typing import Any, Optional, SupportsFloat +from typing import Any, Optional, SupportsFloat, overload from abc import ABCMeta, abstractmethod import sys @@ -70,7 +70,11 @@ class Real(Complex, SupportsFloat): @abstractmethod def __ceil__(self) -> int: ... @abstractmethod - def __round__(self, ndigits: Optional[int] = ...): ... + @overload + def __round__(self, ndigits: None = ...): ... + @abstractmethod + @overload + def __round__(self, ndigits: int): ... def __divmod__(self, other): ... def __rdivmod__(self, other): ... @abstractmethod diff --git a/stdlib/2and3/operator.pyi b/stdlib/2and3/operator.pyi index eafc37cb36b9..3a70b47e9391 100644 --- a/stdlib/2and3/operator.pyi +++ b/stdlib/2and3/operator.pyi @@ -34,8 +34,8 @@ def is_(a: Any, b: Any) -> bool: ... def is_not(a: Any, b: Any) -> bool: ... -def abs(x: SupportsAbs) -> Any: ... -def __abs__(a: SupportsAbs) -> Any: ... +def abs(x: SupportsAbs[_T]) -> _T: ... +def __abs__(a: SupportsAbs[_T]) -> _T: ... def add(a: Any, b: Any) -> Any: ... def __add__(a: Any, b: Any) -> Any: ... diff --git a/stdlib/2and3/optparse.pyi b/stdlib/2and3/optparse.pyi index 9b8b8eac568c..e3fe3142a254 100644 --- a/stdlib/2and3/optparse.pyi +++ b/stdlib/2and3/optparse.pyi @@ -92,12 +92,12 @@ class Option: ACTIONS: Tuple[_Text, ...] ALWAYS_TYPED_ACTIONS: Tuple[_Text, ...] ATTRS: List[_Text] - CHECK_METHODS: Optional[List[Callable]] + CHECK_METHODS: Optional[List[Callable[..., Any]]] CONST_ACTIONS: Tuple[_Text, ...] STORE_ACTIONS: Tuple[_Text, ...] TYPED_ACTIONS: Tuple[_Text, ...] TYPES: Tuple[_Text, ...] - TYPE_CHECKER: Dict[_Text, Callable] + TYPE_CHECKER: Dict[_Text, Callable[..., Any]] _long_opts: List[_Text] _short_opts: List[_Text] action: _Text @@ -196,13 +196,13 @@ class OptionParser(OptionContainer): def _add_version_option(self) -> None: ... def _create_option_list(self) -> None: ... def _get_all_options(self) -> List[Option]: ... - def _get_args(self, args: Iterable) -> List[Any]: ... + def _get_args(self, args: Iterable[Any]) -> List[Any]: ... def _init_parsing_state(self) -> None: ... def _match_long_opt(self, opt: _Text) -> _Text: ... def _populate_option_list(self, option_list: Iterable[Option], add_help: bool = ...) -> None: ... - def _process_args(self, largs: List, rargs: List, values: Values) -> None: ... - def _process_long_opt(self, rargs: List, values: Any) -> None: ... - def _process_short_opts(self, rargs: List, values: Any) -> None: ... + def _process_args(self, largs: List[Any], rargs: List[Any], values: Values) -> None: ... + def _process_long_opt(self, rargs: List[Any], values: Any) -> None: ... + def _process_short_opts(self, rargs: List[Any], values: Any) -> None: ... def add_option_group(self, *args, **kwargs) -> OptionParser: ... def check_values(self, values: Values, args: List[_Text]) -> Tuple[Values, List[_Text]]: ... def disable_interspersed_args(self) -> None: ... diff --git a/stdlib/2and3/pickle.pyi b/stdlib/2and3/pickle.pyi index 7bfad8f3bf1b..e0222324cb20 100644 --- a/stdlib/2and3/pickle.pyi +++ b/stdlib/2and3/pickle.pyi @@ -26,11 +26,11 @@ class PicklingError(PickleError): ... class UnpicklingError(PickleError): ... _reducedtype = Union[str, - Tuple[Callable[..., Any], Tuple], - Tuple[Callable[..., Any], Tuple, Any], - Tuple[Callable[..., Any], Tuple, Any, + Tuple[Callable[..., Any], Tuple[Any, ...]], + Tuple[Callable[..., Any], Tuple[Any, ...], Any], + Tuple[Callable[..., Any], Tuple[Any, ...], Any, Optional[Iterator]], - Tuple[Callable[..., Any], Tuple, Any, + Tuple[Callable[..., Any], Tuple[Any, ...], Any, Optional[Iterator], Optional[Iterator]]] diff --git a/stdlib/2and3/plistlib.pyi b/stdlib/2and3/plistlib.pyi index 64201dd5b6dd..532be815ebd9 100644 --- a/stdlib/2and3/plistlib.pyi +++ b/stdlib/2and3/plistlib.pyi @@ -10,8 +10,8 @@ if sys.version_info >= (3,): from enum import Enum class PlistFormat(Enum): - FMT_XML = ... - FMT_BINARY = ... + FMT_XML: int + FMT_BINARY: int FMT_XML = PlistFormat.FMT_XML FMT_BINARY = PlistFormat.FMT_BINARY @@ -47,7 +47,7 @@ if sys.version_info < (3,): def writePlistToString(rootObject: Mapping[str, Any]) -> str: ... if sys.version_info < (3, 7): - class Dict(dict): + class Dict(DictT[str, Any]): def __getattr__(self, attr: str) -> Any: ... def __setattr__(self, attr: str, value: Any) -> None: ... def __delattr__(self, attr: str) -> None: ... diff --git a/stdlib/2and3/profile.pyi b/stdlib/2and3/profile.pyi index 31236bbfb100..b511cbc28f74 100644 --- a/stdlib/2and3/profile.pyi +++ b/stdlib/2and3/profile.pyi @@ -5,7 +5,7 @@ from typing import Any, Callable, Dict, Optional, Text, TypeVar, Union def run(statement: str, filename: Optional[str] = ..., sort: Union[str, int] = ...) -> None: ... def runctx(statement: str, globals: Dict[str, Any], locals: Dict[str, Any], filename: Optional[str] = ..., sort: Union[str, int] = ...) -> None: ... -_SelfT = TypeVar('_SelfT', bound='Profile') +_SelfT = TypeVar('_SelfT', bound=Profile) _T = TypeVar('_T') if sys.version_info >= (3, 6): _Path = Union[bytes, Text, os.PathLike[Any]] diff --git a/stdlib/2and3/pstats.pyi b/stdlib/2and3/pstats.pyi index 8bf1b0dae900..5c1bb2a3583a 100644 --- a/stdlib/2and3/pstats.pyi +++ b/stdlib/2and3/pstats.pyi @@ -5,7 +5,7 @@ import sys from typing import Any, Dict, IO, Iterable, List, Text, Tuple, TypeVar, Union, overload _Selector = Union[str, float, int] -_T = TypeVar('_T', bound='Stats') +_T = TypeVar('_T', bound=Stats) if sys.version_info >= (3, 6): _Path = Union[bytes, Text, os.PathLike[Any]] else: diff --git a/stdlib/2and3/py_compile.pyi b/stdlib/2and3/py_compile.pyi index a8be1136a52d..4b57f0d3a62d 100644 --- a/stdlib/2and3/py_compile.pyi +++ b/stdlib/2and3/py_compile.pyi @@ -1,7 +1,8 @@ # Stubs for py_compile (Python 2 and 3) +import enum import sys -from typing import Optional, List, Text, AnyStr, Union +from typing import Optional, List, Text, AnyStr, Union, Type _EitherStr = Union[bytes, Text] @@ -10,9 +11,16 @@ class PyCompileError(Exception): exc_value: BaseException file: str msg: str - def __init__(self, exc_type: str, exc_value: BaseException, file: str, msg: str = ...) -> None: ... + def __init__(self, exc_type: Type[BaseException], exc_value: BaseException, file: str, msg: str = ...) -> None: ... -if sys.version_info >= (3, 2): +if sys.version_info >= (3, 7): + class PycInvalidationMode(enum.Enum): + TIMESTAMP: int = ... + CHECKED_HASH: int = ... + UNCHECKED_HASH: int = ... + def _get_default_invalidation_mode() -> PycInvalidationMode: ... + def compile(file: AnyStr, cfile: Optional[AnyStr] = ..., dfile: Optional[AnyStr] = ..., doraise: bool = ..., optimize: int = ..., invalidation_mode: Optional[PycInvalidationMode] = ...) -> Optional[AnyStr]: ... +elif sys.version_info >= (3, 2): def compile(file: AnyStr, cfile: Optional[AnyStr] = ..., dfile: Optional[AnyStr] = ..., doraise: bool = ..., optimize: int = ...) -> Optional[AnyStr]: ... else: def compile(file: _EitherStr, cfile: Optional[_EitherStr] = ..., dfile: Optional[_EitherStr] = ..., doraise: bool = ...) -> None: ... diff --git a/stdlib/2and3/pydoc.pyi b/stdlib/2and3/pydoc.pyi index 1150741bd205..6a2385055695 100644 --- a/stdlib/2and3/pydoc.pyi +++ b/stdlib/2and3/pydoc.pyi @@ -81,7 +81,7 @@ class HTMLDoc(Doc): def modulelink(self, object: object) -> str: ... def modpkglink(self, data: Tuple[str, str, bool, bool]) -> str: ... def markup(self, text: str, escape: Optional[Callable[[str], str]] = ..., funcs: Mapping[str, str] = ..., classes: Mapping[str, str] = ..., methods: Mapping[str, str] = ...) -> str: ... - def formattree(self, tree: List[Union[Tuple[type, Tuple[type, ...]], list]], modname: str, parent: Optional[type] = ...) -> str: ... + def formattree(self, tree: List[Union[Tuple[type, Tuple[type, ...]], List[Any]]], modname: str, parent: Optional[type] = ...) -> str: ... def docmodule(self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., *ignored) -> str: ... def docclass(self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., funcs: Mapping[str, str] = ..., classes: Mapping[str, str] = ..., *ignored) -> str: ... def formatvalue(self, object: object) -> str: ... @@ -108,7 +108,7 @@ class TextDoc(Doc): def bold(self, text: str) -> str: ... def indent(self, text: str, prefix: str = ...) -> str: ... def section(self, title: str, contents: str) -> str: ... - def formattree(self, tree: List[Union[Tuple[type, Tuple[type, ...]], list]], modname: str, parent: Optional[type] = ..., prefix: str = ...) -> str: ... + def formattree(self, tree: List[Union[Tuple[type, Tuple[type, ...]], List[Any]]], modname: str, parent: Optional[type] = ..., prefix: str = ...) -> str: ... def docmodule(self, object: object, name: Optional[str] = ..., mod: Optional[Any] = ..., *ignored) -> str: ... def docclass(self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., *ignored) -> str: ... def formatvalue(self, object: object) -> str: ... @@ -171,7 +171,7 @@ help: Helper class ModuleScanner: quit: bool - def run(self, callback: Callable[[Optional[str], str, str], None], key: Optional[Any] = ..., completer: Optional[Callable[[], None]] = ..., onerror: Optional[Callable] = ...) -> None: ... + def run(self, callback: Callable[[Optional[str], str, str], None], key: Optional[Any] = ..., completer: Optional[Callable[[], None]] = ..., onerror: Optional[Callable[[str], None]] = ...) -> None: ... def apropos(key: str) -> None: ... def serve(port: int, callback: Optional[Callable[[Any], None]] = ..., completer: Optional[Callable[[], None]] = ...) -> None: ... diff --git a/stdlib/2and3/select.pyi b/stdlib/2and3/select.pyi index ab9ffc63603a..3fc05450bc40 100644 --- a/stdlib/2and3/select.pyi +++ b/stdlib/2and3/select.pyi @@ -1,9 +1,10 @@ import sys -from typing import Any, Optional, Sequence, Tuple, Iterable, List, Union +from typing import Any, Iterable, List, Optional, Protocol, Sequence, Tuple, Union -# When we have protocols, this should change to a protocol with a fileno method -# See https://docs.python.org/3/c-api/file.html#c.PyObject_AsFileDescriptor -_FileDescriptor = Union[int, Any] +class _HasFileno(Protocol): + def fileno(self) -> int: ... + +_FileDescriptor = Union[int, _HasFileno] EPOLLERR: int EPOLLET: int diff --git a/stdlib/2and3/shutil.pyi b/stdlib/2and3/shutil.pyi index de1f8fcc8330..98761d046f76 100644 --- a/stdlib/2and3/shutil.pyi +++ b/stdlib/2and3/shutil.pyi @@ -73,15 +73,17 @@ else: def ignore_patterns(*patterns: _Path) -> Callable[[Any, List[_AnyStr]], Set[_AnyStr]]: ... if sys.version_info >= (3,): - _IgnoreFn = Union[None, Callable[[str, List[str]], Iterable[str]], Callable[[_Path, List[str]], Iterable[str]]] def copytree(src: _Path, dst: _Path, symlinks: bool = ..., - ignore: _IgnoreFn = ..., + ignore: Union[None, + Callable[[str, List[str]], Iterable[str]], + Callable[[_Path, List[str]], Iterable[str]]] = ..., copy_function: Callable[[str, str], None] = ..., ignore_dangling_symlinks: bool = ...) -> _PathReturn: ... else: - _IgnoreFn = Union[None, Callable[[AnyStr, List[AnyStr]], Iterable[AnyStr]]] def copytree(src: AnyStr, dst: AnyStr, symlinks: bool = ..., - ignore: _IgnoreFn = ...) -> _PathReturn: ... + ignore: Union[None, + Callable[[AnyStr, List[AnyStr]], + Iterable[AnyStr]]] = ...) -> _PathReturn: ... if sys.version_info >= (3,): @overload diff --git a/stdlib/2and3/smtpd.pyi b/stdlib/2and3/smtpd.pyi index 923b8bc65df4..67599d7dea6a 100644 --- a/stdlib/2and3/smtpd.pyi +++ b/stdlib/2and3/smtpd.pyi @@ -13,10 +13,8 @@ class SMTPChannel(asynchat.async_chat): COMMAND: int DATA: int - if sys.version_info >= (3, 3): - command_size_limits: DefaultDict[str, int] - if sys.version_info >= (3,): + command_size_limits: DefaultDict[str, int] smtp_server: SMTPServer conn: socket.socket addr: Any @@ -32,19 +30,14 @@ class SMTPChannel(asynchat.async_chat): command_size_limit: int data_size_limit: int - if sys.version_info >= (3, 5): enable_SMTPUTF8: bool - if sys.version_info >= (3, 3): @property def max_command_size_limit(self) -> int: ... - if sys.version_info >= (3, 5): + if sys.version_info >= (3,): def __init__(self, server: SMTPServer, conn: socket.socket, addr: Any, data_size_limit: int = ..., map: Optional[asyncore._maptype] = ..., enable_SMTPUTF8: bool = ..., decode_data: bool = ...) -> None: ... - elif sys.version_info >= (3, 4): - def __init__(self, server: SMTPServer, conn: socket.socket, addr: Any, data_size_limit: int = ..., - map: Optional[asyncore._maptype] = ...) -> None: ... else: def __init__(self, server: SMTPServer, conn: socket.socket, addr: Any, data_size_limit: int = ...) -> None: ... def push(self, msg: bytes) -> None: ... @@ -69,13 +62,10 @@ class SMTPServer(asyncore.dispatcher): data_size_limit: int enable_SMTPUTF8: bool - if sys.version_info >= (3, 5): + if sys.version_info >= (3,): def __init__(self, localaddr: _Address, remoteaddr: _Address, data_size_limit: int = ..., map: Optional[asyncore._maptype] = ..., enable_SMTPUTF8: bool = ..., decode_data: bool = ...) -> None: ... - elif sys.version_info >= (3, 4): - def __init__(self, localaddr: _Address, remoteaddr: _Address, - data_size_limit: int = ..., map: Optional[asyncore._maptype] = ...) -> None: ... else: def __init__(self, localaddr: _Address, remoteaddr: _Address, data_size_limit: int = ...) -> None: ... diff --git a/stdlib/2and3/socket.pyi b/stdlib/2and3/socket.pyi index 22b2f91357a3..1a42632187a1 100644 --- a/stdlib/2and3/socket.pyi +++ b/stdlib/2and3/socket.pyi @@ -411,45 +411,45 @@ if sys.version_info >= (3, 4): from enum import IntEnum class AddressFamily(IntEnum): - AF_UNIX = ... - AF_INET = ... - AF_INET6 = ... - AF_APPLETALK = ... - AF_ASH = ... - AF_ATMPVC = ... - AF_ATMSVC = ... - AF_AX25 = ... - AF_BLUETOOTH = ... - AF_BRIDGE = ... - AF_DECnet = ... - AF_ECONET = ... - AF_IPX = ... - AF_IRDA = ... - AF_KEY = ... - AF_LLC = ... - AF_NETBEUI = ... - AF_NETLINK = ... - AF_NETROM = ... - AF_PACKET = ... - AF_PPPOX = ... - AF_ROSE = ... - AF_ROUTE = ... - AF_SECURITY = ... - AF_SNA = ... - AF_TIPC = ... - AF_UNSPEC = ... - AF_WANPIPE = ... - AF_X25 = ... - AF_LINK = ... + AF_UNIX: int + AF_INET: int + AF_INET6: int + AF_APPLETALK: int + AF_ASH: int + AF_ATMPVC: int + AF_ATMSVC: int + AF_AX25: int + AF_BLUETOOTH: int + AF_BRIDGE: int + AF_DECnet: int + AF_ECONET: int + AF_IPX: int + AF_IRDA: int + AF_KEY: int + AF_LLC: int + AF_NETBEUI: int + AF_NETLINK: int + AF_NETROM: int + AF_PACKET: int + AF_PPPOX: int + AF_ROSE: int + AF_ROUTE: int + AF_SECURITY: int + AF_SNA: int + AF_TIPC: int + AF_UNSPEC: int + AF_WANPIPE: int + AF_X25: int + AF_LINK: int class SocketKind(IntEnum): - SOCK_STREAM = ... - SOCK_DGRAM = ... - SOCK_RAW = ... - SOCK_RDM = ... - SOCK_SEQPACKET = ... - SOCK_CLOEXEC = ... - SOCK_NONBLOCK = ... + SOCK_STREAM: int + SOCK_DGRAM: int + SOCK_RAW: int + SOCK_RDM: int + SOCK_SEQPACKET: int + SOCK_CLOEXEC: int + SOCK_NONBLOCK: int else: AddressFamily = int SocketKind = int @@ -458,40 +458,42 @@ if sys.version_info >= (3, 6): from enum import IntFlag class AddressInfo(IntFlag): - AI_ADDRCONFIG = ... - AI_ALL = ... - AI_CANONNAME = ... - AI_NUMERICHOST = ... - AI_NUMERICSERV = ... - AI_PASSIVE = ... - AI_V4MAPPED = ... + AI_ADDRCONFIG: int + AI_ALL: int + AI_CANONNAME: int + AI_NUMERICHOST: int + AI_NUMERICSERV: int + AI_PASSIVE: int + AI_V4MAPPED: int class MsgFlag(IntFlag): - MSG_CTRUNC = ... - MSG_DONTROUTE = ... - MSG_DONTWAIT = ... - MSG_EOR = ... - MSG_OOB = ... - MSG_PEEK = ... - MSG_TRUNC = ... - MSG_WAITALL = ... + MSG_CTRUNC: int + MSG_DONTROUTE: int + MSG_DONTWAIT: int + MSG_EOR: int + MSG_OOB: int + MSG_PEEK: int + MSG_TRUNC: int + MSG_WAITALL: int else: AddressInfo = int MsgFlag = int # ----- exceptions ----- -class error(IOError): - ... +if sys.version_info < (3,): + class error(IOError): ... +else: + error = OSError class herror(error): - def __init__(self, herror: int, string: str) -> None: ... + def __init__(self, herror: int = ..., string: str = ...) -> None: ... class gaierror(error): - def __init__(self, error: int, string: str) -> None: ... + def __init__(self, error: int = ..., string: str = ...) -> None: ... class timeout(error): - ... + def __init__(self, error: int = ..., string: str = ...) -> None: ... # Addresses can be either tuples of varying lengths (AF_INET, AF_INET6, @@ -590,7 +592,7 @@ def create_connection(address: Tuple[Optional[str], int], def getaddrinfo( host: Optional[Union[bytearray, bytes, Text]], port: Union[str, int, None], family: int = ..., socktype: int = ..., proto: int = ..., - flags: int = ...) -> List[Tuple[int, int, int, str, Tuple[Any, ...]]]: + flags: int = ...) -> List[Tuple[AddressFamily, SocketKind, int, str, Tuple[Any, ...]]]: ... def getfqdn(name: str = ...) -> str: ... @@ -598,7 +600,7 @@ def gethostbyname(hostname: str) -> str: ... def gethostbyname_ex(hostname: str) -> Tuple[str, List[str], List[str]]: ... def gethostname() -> str: ... def gethostbyaddr(ip_address: str) -> Tuple[str, List[str], List[str]]: ... -def getnameinfo(sockaddr: tuple, flags: int) -> Tuple[str, int]: ... +def getnameinfo(sockaddr: Union[Tuple[str, int], Tuple[str, int, int, int]], flags: int) -> Tuple[str, int]: ... def getprotobyname(protocolname: str) -> int: ... def getservbyname(servicename: str, protocolname: str = ...) -> int: ... def getservbyport(port: int, protocolname: str = ...) -> str: ... diff --git a/stdlib/2and3/sqlite3/dbapi2.pyi b/stdlib/2and3/sqlite3/dbapi2.pyi index 5b3d2a03ed1a..e338ebbe322b 100644 --- a/stdlib/2and3/sqlite3/dbapi2.pyi +++ b/stdlib/2and3/sqlite3/dbapi2.pyi @@ -130,9 +130,9 @@ class Connection(object): def create_collation(self, name: str, callable: Any) -> None: ... def create_function(self, name: str, num_params: int, func: Any) -> None: ... def cursor(self, cursorClass: Optional[type] = ...) -> Cursor: ... - def execute(self, sql: str, parameters: Iterable = ...) -> Cursor: ... + def execute(self, sql: str, parameters: Iterable[Any] = ...) -> Cursor: ... # TODO: please check in executemany() if seq_of_parameters type is possible like this - def executemany(self, sql: str, seq_of_parameters: Iterable[Iterable]) -> Cursor: ... + def executemany(self, sql: str, seq_of_parameters: Iterable[Iterable[Any]]) -> Cursor: ... def executescript(self, sql_script: Union[bytes, Text]) -> Cursor: ... def interrupt(self, *args, **kwargs) -> None: ... def iterdump(self, *args, **kwargs) -> None: ... @@ -168,8 +168,8 @@ class Cursor(Iterator[Any]): # however, the name of the __init__ variable is unknown def __init__(self, *args, **kwargs) -> None: ... def close(self, *args, **kwargs) -> None: ... - def execute(self, sql: str, parameters: Iterable = ...) -> Cursor: ... - def executemany(self, sql: str, seq_of_parameters: Iterable[Iterable]) -> Cursor: ... + def execute(self, sql: str, parameters: Iterable[Any] = ...) -> Cursor: ... + def executemany(self, sql: str, seq_of_parameters: Iterable[Iterable[Any]]) -> Cursor: ... def executescript(self, sql_script: Union[bytes, Text]) -> Cursor: ... def fetchall(self) -> List[Any]: ... def fetchmany(self, size: Optional[int] = ...) -> List[Any]: ... diff --git a/stdlib/2and3/sre_compile.pyi b/stdlib/2and3/sre_compile.pyi index be39a314c84c..e6036e205454 100644 --- a/stdlib/2and3/sre_compile.pyi +++ b/stdlib/2and3/sre_compile.pyi @@ -15,4 +15,4 @@ else: _IsStringType = bool def isstring(obj: Any) -> _IsStringType: ... -def compile(p: Union[str, bytes, SubPattern], flags: int = ...) -> Pattern: ... +def compile(p: Union[str, bytes, SubPattern], flags: int = ...) -> Pattern[Any]: ... diff --git a/stdlib/2and3/ssl.pyi b/stdlib/2and3/ssl.pyi index 4b51e409f0f4..3e358f356004 100644 --- a/stdlib/2and3/ssl.pyi +++ b/stdlib/2and3/ssl.pyi @@ -1,10 +1,12 @@ # Stubs for ssl from typing import ( - Any, Dict, Callable, List, NamedTuple, Optional, Set, Tuple, Union, + Any, Callable, ClassVar, Dict, List, NamedTuple, Optional, Set, Text, Type, Tuple, Union, ) +import enum import socket import sys +import os _PCTRTT = Tuple[Tuple[str, str], ...] _PCTRTTT = Tuple[_PCTRTT, ...] @@ -13,6 +15,11 @@ _PeerCertRetType = Union[_PeerCertRetDictType, bytes, None] _EnumRetType = List[Tuple[bytes, str, Union[Set[str], bool]]] _PasswordType = Union[Callable[[], Union[str, bytes]], str, bytes] +if sys.version_info < (3, 6): + _Path = Text +else: + _Path = Union[str, os.PathLike[Any]] + if sys.version_info >= (3, 5): _SC1ArgT = Union[SSLSocket, SSLObject] else: @@ -47,23 +54,24 @@ def wrap_socket(sock: socket.socket, keyfile: Optional[str] = ..., ciphers: Optional[str] = ...) -> SSLSocket: ... -if sys.version_info < (3,) or sys.version_info >= (3, 4): - def create_default_context(purpose: Any = ..., *, +def create_default_context( + purpose: Any = ..., + *, + cafile: Optional[str] = ..., + capath: Optional[str] = ..., + cadata: Union[Text, bytes, None] = ..., +) -> SSLContext: ... + +def _create_unverified_context(protocol: int = ..., *, + cert_reqs: int = ..., + check_hostname: bool = ..., + purpose: Any = ..., + certfile: Optional[str] = ..., + keyfile: Optional[str] = ..., cafile: Optional[str] = ..., capath: Optional[str] = ..., - cadata: Optional[str] = ...) -> SSLContext: ... - -if sys.version_info >= (3, 4): - def _create_unverified_context(protocol: int = ..., *, - cert_reqs: int = ..., - check_hostname: bool = ..., - purpose: Any = ..., - certfile: Optional[str] = ..., - keyfile: Optional[str] = ..., - cafile: Optional[str] = ..., - capath: Optional[str] = ..., - cadata: Optional[str] = ...) -> SSLContext: ... - _create_default_https_context: Callable[..., SSLContext] + cadata: Union[Text, bytes, None] = ...) -> SSLContext: ... +_create_default_https_context: Callable[..., SSLContext] if sys.version_info >= (3, 3): def RAND_bytes(num: int) -> bytes: ... @@ -79,39 +87,35 @@ def get_server_certificate(addr: Tuple[str, int], ssl_version: int = ..., ca_certs: Optional[str] = ...) -> str: ... def DER_cert_to_PEM_cert(der_cert_bytes: bytes) -> str: ... def PEM_cert_to_DER_cert(pem_cert_string: str) -> bytes: ... -if sys.version_info < (3,) or sys.version_info >= (3, 4): - DefaultVerifyPaths = NamedTuple('DefaultVerifyPaths', - [('cafile', str), ('capath', str), - ('openssl_cafile_env', str), - ('openssl_cafile', str), - ('openssl_capath_env', str), - ('openssl_capath', str)]) - def get_default_verify_paths() -> DefaultVerifyPaths: ... +DefaultVerifyPaths = NamedTuple('DefaultVerifyPaths', + [('cafile', str), ('capath', str), + ('openssl_cafile_env', str), + ('openssl_cafile', str), + ('openssl_capath_env', str), + ('openssl_capath', str)]) +def get_default_verify_paths() -> DefaultVerifyPaths: ... if sys.platform == 'win32': - if sys.version_info < (3,) or sys.version_info >= (3, 4): - def enum_certificates(store_name: str) -> _EnumRetType: ... - def enum_crls(store_name: str) -> _EnumRetType: ... + def enum_certificates(store_name: str) -> _EnumRetType: ... + def enum_crls(store_name: str) -> _EnumRetType: ... CERT_NONE: int CERT_OPTIONAL: int CERT_REQUIRED: int -if sys.version_info < (3,) or sys.version_info >= (3, 4): - VERIFY_DEFAULT: int - VERIFY_CRL_CHECK_LEAF: int - VERIFY_CRL_CHECK_CHAIN: int - VERIFY_X509_STRICT: int - VERIFY_X509_TRUSTED_FIRST: int +VERIFY_DEFAULT: int +VERIFY_CRL_CHECK_LEAF: int +VERIFY_CRL_CHECK_CHAIN: int +VERIFY_X509_STRICT: int +VERIFY_X509_TRUSTED_FIRST: int PROTOCOL_SSLv23: int PROTOCOL_SSLv2: int PROTOCOL_SSLv3: int PROTOCOL_TLSv1: int -if sys.version_info < (3,) or sys.version_info >= (3, 4): - PROTOCOL_TLSv1_1: int - PROTOCOL_TLSv1_2: int +PROTOCOL_TLSv1_1: int +PROTOCOL_TLSv1_2: int if sys.version_info >= (3, 5): PROTOCOL_TLS: int if sys.version_info >= (3, 6): @@ -122,9 +126,8 @@ OP_ALL: int OP_NO_SSLv2: int OP_NO_SSLv3: int OP_NO_TLSv1: int -if sys.version_info < (3,) or sys.version_info >= (3, 4): - OP_NO_TLSv1_1: int - OP_NO_TLSv1_2: int +OP_NO_TLSv1_1: int +OP_NO_TLSv1_2: int OP_CIPHER_SERVER_PREFERENCE: int OP_SINGLE_DH_USE: int OP_SINGLE_ECDH_USE: int @@ -132,8 +135,7 @@ OP_NO_COMPRESSION: int if sys.version_info >= (3, 6): OP_NO_TICKET: int -if sys.version_info < (3,) or sys.version_info >= (3, 5): - HAS_ALPN: int +HAS_ALPN: int HAS_ECDH: bool HAS_SNI: bool HAS_NPN: bool @@ -143,41 +145,44 @@ OPENSSL_VERSION: str OPENSSL_VERSION_INFO: Tuple[int, int, int, int, int] OPENSSL_VERSION_NUMBER: int -if sys.version_info < (3,) or sys.version_info >= (3, 4): - ALERT_DESCRIPTION_HANDSHAKE_FAILURE: int - ALERT_DESCRIPTION_INTERNAL_ERROR: int - ALERT_DESCRIPTION_ACCESS_DENIED: int - ALERT_DESCRIPTION_BAD_CERTIFICATE: int - ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE: int - ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE: int - ALERT_DESCRIPTION_BAD_RECORD_MAC: int - ALERT_DESCRIPTION_CERTIFICATE_EXPIRED: int - ALERT_DESCRIPTION_CERTIFICATE_REVOKED: int - ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN: int - ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE: int - ALERT_DESCRIPTION_CLOSE_NOTIFY: int - ALERT_DESCRIPTION_DECODE_ERROR: int - ALERT_DESCRIPTION_DECOMPRESSION_FAILURE: int - ALERT_DESCRIPTION_DECRYPT_ERROR: int - ALERT_DESCRIPTION_ILLEGAL_PARAMETER: int - ALERT_DESCRIPTION_INSUFFICIENT_SECURITY: int - ALERT_DESCRIPTION_NO_RENEGOTIATION: int - ALERT_DESCRIPTION_PROTOCOL_VERSION: int - ALERT_DESCRIPTION_RECORD_OVERFLOW: int - ALERT_DESCRIPTION_UNEXPECTED_MESSAGE: int - ALERT_DESCRIPTION_UNKNOWN_CA: int - ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY: int - ALERT_DESCRIPTION_UNRECOGNIZED_NAME: int - ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE: int - ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION: int - ALERT_DESCRIPTION_USER_CANCELLED: int - -if sys.version_info < (3,) or sys.version_info >= (3, 4): - _PurposeType = NamedTuple('_PurposeType', [('nid', int), ('shortname', str), ('longname', str), ('oid', str)]) - class Purpose: - SERVER_AUTH: _PurposeType - CLIENT_AUTH: _PurposeType - +ALERT_DESCRIPTION_HANDSHAKE_FAILURE: int +ALERT_DESCRIPTION_INTERNAL_ERROR: int +ALERT_DESCRIPTION_ACCESS_DENIED: int +ALERT_DESCRIPTION_BAD_CERTIFICATE: int +ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE: int +ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE: int +ALERT_DESCRIPTION_BAD_RECORD_MAC: int +ALERT_DESCRIPTION_CERTIFICATE_EXPIRED: int +ALERT_DESCRIPTION_CERTIFICATE_REVOKED: int +ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN: int +ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE: int +ALERT_DESCRIPTION_CLOSE_NOTIFY: int +ALERT_DESCRIPTION_DECODE_ERROR: int +ALERT_DESCRIPTION_DECOMPRESSION_FAILURE: int +ALERT_DESCRIPTION_DECRYPT_ERROR: int +ALERT_DESCRIPTION_ILLEGAL_PARAMETER: int +ALERT_DESCRIPTION_INSUFFICIENT_SECURITY: int +ALERT_DESCRIPTION_NO_RENEGOTIATION: int +ALERT_DESCRIPTION_PROTOCOL_VERSION: int +ALERT_DESCRIPTION_RECORD_OVERFLOW: int +ALERT_DESCRIPTION_UNEXPECTED_MESSAGE: int +ALERT_DESCRIPTION_UNKNOWN_CA: int +ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY: int +ALERT_DESCRIPTION_UNRECOGNIZED_NAME: int +ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE: int +ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION: int +ALERT_DESCRIPTION_USER_CANCELLED: int + +if sys.version_info < (3,): + class _ASN1Object(NamedTuple('_ASN1Object', [('nid', int), ('shortname', str), ('longname', str), ('oid', str)])): ... + class Purpose(_ASN1Object): + SERVER_AUTH: ClassVar[Purpose] + CLIENT_AUTH: ClassVar[Purpose] +else: + class _ASN1Object(NamedTuple('_ASN1Object', [('nid', int), ('shortname', str), ('longname', str), ('oid', str)])): ... + class Purpose(_ASN1Object, enum.Enum): + SERVER_AUTH = ... + CLIENT_AUTH = ... class SSLSocket(socket.socket): context: SSLContext @@ -197,47 +202,52 @@ class SSLSocket(socket.socket): def shared_cipher(self) -> Optional[List[Tuple[str, int, int]]]: ... def compression(self) -> Optional[str]: ... def get_channel_binding(self, cb_type: str = ...) -> Optional[bytes]: ... - if sys.version_info < (3,) or sys.version_info >= (3, 5): - def selected_alpn_protocol(self) -> Optional[str]: ... + def selected_alpn_protocol(self) -> Optional[str]: ... def selected_npn_protocol(self) -> Optional[str]: ... def unwrap(self) -> socket.socket: ... - if sys.version_info < (3,) or sys.version_info >= (3, 5): - def version(self) -> Optional[str]: ... + def version(self) -> Optional[str]: ... def pending(self) -> int: ... +if sys.version_info >= (3, 7): + class TLSVersion(enum.IntEnum): + MINIMUM_SUPPORTED = ... + MAXIMUM_SUPPORTED = ... + SSLv3 = ... + TLSv1 = ... + TLSv1_1 = ... + TLSv1_2 = ... + TLSv1_3 = ... + + class SSLContext: - if sys.version_info < (3,) or sys.version_info >= (3, 4): - check_hostname: bool + check_hostname: bool options: int @property def protocol(self) -> int: ... - if sys.version_info < (3,) or sys.version_info >= (3, 4): - verify_flags: int + verify_flags: int verify_mode: int if sys.version_info >= (3, 5): def __init__(self, protocol: int = ...) -> None: ... else: def __init__(self, protocol: int) -> None: ... - if sys.version_info < (3,) or sys.version_info >= (3, 4): - def cert_store_stats(self) -> Dict[str, int]: ... - def load_cert_chain(self, certfile: str, keyfile: Optional[str] = ..., + def cert_store_stats(self) -> Dict[str, int]: ... + def load_cert_chain(self, certfile: _Path, keyfile: Optional[_Path] = ..., password: _PasswordType = ...) -> None: ... - if sys.version_info < (3,) or sys.version_info >= (3, 4): - def load_default_certs(self, purpose: _PurposeType = ...) -> None: ... - def load_verify_locations(self, cafile: Optional[str] = ..., - capath: Optional[str] = ..., - cadata: Union[str, bytes, None] = ...) -> None: ... - def get_ca_certs(self, - binary_form: bool = ...) -> Union[List[_PeerCertRetDictType], List[bytes]]: ... - else: - def load_verify_locations(self, - cafile: Optional[str] = ..., - capath: Optional[str] = ...) -> None: ... + def load_default_certs(self, purpose: Purpose = ...) -> None: ... + def load_verify_locations( + self, + cafile: Optional[str] = ..., + capath: Optional[str] = ..., + cadata: Union[Text, bytes, None] = ..., + ) -> None: ... + def get_ca_certs(self, binary_form: bool = ...) -> Union[List[_PeerCertRetDictType], List[bytes]]: ... def set_default_verify_paths(self) -> None: ... def set_ciphers(self, ciphers: str) -> None: ... - if sys.version_info < (3,) or sys.version_info >= (3, 5): - def set_alpn_protocols(self, protocols: List[str]) -> None: ... + def set_alpn_protocols(self, protocols: List[str]) -> None: ... + if sys.version_info >= (3, 7): + sni_callback: Optional[Callable[[SSLObject, str, SSLContext], Union[None, int]]] + sslobject_class: Type[SSLObject] def set_npn_protocols(self, protocols: List[str]) -> None: ... def set_servername_callback(self, server_name_callback: Optional[_SrvnmeCbType]) -> None: ... @@ -252,6 +262,9 @@ class SSLContext: server_side: bool = ..., server_hostname: Optional[str] = ...) -> SSLObject: ... def session_stats(self) -> Dict[str, int]: ... + if sys.version_info >= (3, 7): + maximum_version: TLSVersion + minimum_version: TLSVersion if sys.version_info >= (3, 5): @@ -290,6 +303,17 @@ if sys.version_info >= (3, 6): ticket_lifetime_hint: int has_ticket: bool + class VerifyFlags(enum.IntFlag): + VERIFY_DEFAULT: int + VERIFY_CRL_CHECK_LEAF: int + VERIFY_CRL_CHECK_CHAIN: int + VERIFY_X509_STRICT: int + VERIFY_X509_TRUSTED_FIRST: int + + class VerifyMode(enum.IntEnum): + CERT_NONE: int + CERT_OPTIONAL: int + CERT_REQUIRED: int # TODO below documented in cpython but not in docs.python.org # taken from python 3.4 diff --git a/stdlib/2and3/tarfile.pyi b/stdlib/2and3/tarfile.pyi index f5984949d1db..98523fc44f64 100644 --- a/stdlib/2and3/tarfile.pyi +++ b/stdlib/2and3/tarfile.pyi @@ -77,7 +77,7 @@ class TarFile(Iterable[TarInfo]): def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... + exc_tb: Optional[TracebackType]) -> None: ... def __iter__(self) -> Iterator[TarInfo]: ... @classmethod def open(cls, name: Optional[_Path] = ..., mode: str = ..., @@ -109,9 +109,6 @@ class TarFile(Iterable[TarInfo]): def extract(self, member: Union[str, TarInfo], path: _Path = ..., set_attrs: bool = ..., *, numeric_owner: bool = ...) -> None: ... - elif sys.version_info >= (3,): - def extract(self, member: Union[str, TarInfo], path: _Path = ..., - set_attrs: bool = ...) -> None: ... else: def extract(self, member: Union[str, TarInfo], path: _Path = ...) -> None: ... diff --git a/stdlib/2and3/threading.pyi b/stdlib/2and3/threading.pyi index 190f93407001..c8ed09611ec6 100644 --- a/stdlib/2and3/threading.pyi +++ b/stdlib/2and3/threading.pyi @@ -30,7 +30,7 @@ if sys.version_info >= (3, 4): def main_thread() -> Thread: ... def settrace(func: _TF) -> None: ... -def setprofile(func: _PF) -> None: ... +def setprofile(func: Optional[_PF]) -> None: ... def stack_size(size: int = ...) -> int: ... if sys.version_info >= (3,): @@ -53,14 +53,14 @@ class Thread: def __init__(self, group: None = ..., target: Optional[Callable[..., Any]] = ..., name: Optional[str] = ..., - args: Iterable = ..., + args: Iterable[Any] = ..., kwargs: Mapping[str, Any] = ..., *, daemon: Optional[bool] = ...) -> None: ... else: def __init__(self, group: None = ..., target: Optional[Callable[..., Any]] = ..., name: Optional[str] = ..., - args: Iterable = ..., + args: Iterable[Any] = ..., kwargs: Mapping[str, Any] = ...) -> None: ... def start(self) -> None: ... def run(self) -> None: ... @@ -81,7 +81,7 @@ class Lock: def __enter__(self) -> bool: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... + exc_tb: Optional[TracebackType]) -> Optional[bool]: ... if sys.version_info >= (3,): def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ... else: @@ -95,7 +95,7 @@ class _RLock: def __enter__(self) -> bool: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... + exc_tb: Optional[TracebackType]) -> Optional[bool]: ... if sys.version_info >= (3,): def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ... else: @@ -111,7 +111,7 @@ class Condition: def __enter__(self) -> bool: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... + exc_tb: Optional[TracebackType]) -> Optional[bool]: ... if sys.version_info >= (3,): def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ... else: @@ -131,7 +131,7 @@ class Semaphore: def __enter__(self) -> bool: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... + exc_tb: Optional[TracebackType]) -> Optional[bool]: ... if sys.version_info >= (3,): def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ... else: @@ -143,7 +143,7 @@ class BoundedSemaphore: def __enter__(self) -> bool: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... + exc_tb: Optional[TracebackType]) -> Optional[bool]: ... if sys.version_info >= (3,): def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ... else: diff --git a/stdlib/2and3/token.pyi b/stdlib/2and3/token.pyi index fa508629d394..c75f865e0262 100644 --- a/stdlib/2and3/token.pyi +++ b/stdlib/2and3/token.pyi @@ -65,6 +65,10 @@ ERRORTOKEN: int N_TOKENS: int NT_OFFSET: int tok_name: Dict[int, str] +if sys.version_info >= (3, 7): + COMMENT: int + NL: int + ENCODING: int def ISTERMINAL(x: int) -> bool: ... def ISNONTERMINAL(x: int) -> bool: ... diff --git a/stdlib/2and3/traceback.pyi b/stdlib/2and3/traceback.pyi index 7adc5eb7d5e7..e6744007ace6 100644 --- a/stdlib/2and3/traceback.pyi +++ b/stdlib/2and3/traceback.pyi @@ -72,8 +72,8 @@ if sys.version_info < (3,): if sys.version_info >= (3, 5): class TracebackException: - __cause__ = ... # type:TracebackException - __context__ = ... # type:TracebackException + __cause__: TracebackException + __context__: TracebackException __suppress_context__: bool stack: StackSummary exc_type: Type[BaseException] @@ -94,7 +94,7 @@ if sys.version_info >= (3, 5): def format(self, *, chain: bool = ...) -> Generator[str, None, None]: ... def format_exception_only(self) -> Generator[str, None, None]: ... - class FrameSummary(Iterable): + class FrameSummary(Iterable[Any]): filename: str lineno: int name: str diff --git a/stdlib/2and3/warnings.pyi b/stdlib/2and3/warnings.pyi index a44e43e0162d..d9ecec74f71e 100644 --- a/stdlib/2and3/warnings.pyi +++ b/stdlib/2and3/warnings.pyi @@ -1,11 +1,19 @@ # Stubs for warnings -from typing import Any, Dict, List, NamedTuple, Optional, TextIO, Tuple, Type, Union +from typing import Any, Dict, List, NamedTuple, Optional, overload, TextIO, Tuple, Type, Union from types import ModuleType, TracebackType -def warn(message: Union[str, Warning], category: Optional[Type[Warning]] = ..., - stacklevel: int = ...) -> None: ... -def warn_explicit(message: Union[str, Warning], category: Type[Warning], +@overload +def warn(message: str, category: Optional[Type[Warning]] = ..., stacklevel: int = ...) -> None: ... +@overload +def warn(message: Warning, category: Any = ..., stacklevel: int = ...) -> None: ... +@overload +def warn_explicit(message: str, category: Type[Warning], + filename: str, lineno: int, module: Optional[str] = ..., + registry: Optional[Dict[Union[str, Tuple[str, Type[Warning], int]], int]] = ..., + module_globals: Optional[Dict[str, Any]] = ...) -> None: ... +@overload +def warn_explicit(message: Warning, category: Any, filename: str, lineno: int, module: Optional[str] = ..., registry: Optional[Dict[Union[str, Tuple[str, Type[Warning], int]], int]] = ..., module_globals: Optional[Dict[str, Any]] = ...) -> None: ... @@ -35,4 +43,4 @@ class catch_warnings: def __enter__(self) -> Optional[List[_Record]]: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... + exc_tb: Optional[TracebackType]) -> None: ... diff --git a/stdlib/2and3/webbrowser.pyi b/stdlib/2and3/webbrowser.pyi index 7d1b4cb68336..111037571bf3 100644 --- a/stdlib/2and3/webbrowser.pyi +++ b/stdlib/2and3/webbrowser.pyi @@ -56,13 +56,12 @@ class Galeon(UnixBrowser): remote_action_newwin: str background: bool -if sys.version_info[:2] == (2, 7) or sys.version_info >= (3, 3): - class Chrome(UnixBrowser): - remote_args: List[str] - remote_action: str - remote_action_newwin: str - remote_action_newtab: str - background: bool +class Chrome(UnixBrowser): + remote_args: List[str] + remote_action: str + remote_action_newwin: str + remote_action_newtab: str + background: bool class Opera(UnixBrowser): raise_opts: List[str] diff --git a/stdlib/2and3/xml/etree/ElementPath.pyi b/stdlib/2and3/xml/etree/ElementPath.pyi index 1477b329caf6..1250f0da42dd 100644 --- a/stdlib/2and3/xml/etree/ElementPath.pyi +++ b/stdlib/2and3/xml/etree/ElementPath.pyi @@ -3,7 +3,7 @@ from typing import Pattern, Dict, Generator, Tuple, List, Union, TypeVar, Callable, Optional from xml.etree.ElementTree import Element -xpath_tokenizer_re: Pattern +xpath_tokenizer_re: Pattern[str] _token = Tuple[str, str] _next = Callable[[], _token] diff --git a/stdlib/2and3/xml/etree/ElementTree.pyi b/stdlib/2and3/xml/etree/ElementTree.pyi index d5f64b67a96e..0318bd8c2274 100644 --- a/stdlib/2and3/xml/etree/ElementTree.pyi +++ b/stdlib/2and3/xml/etree/ElementTree.pyi @@ -4,9 +4,16 @@ from typing import Any, Callable, Dict, Generator, IO, ItemsView, Iterable, Iter import io import sys +if sys.version_info < (3,) or sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + VERSION: str -class ParseError(SyntaxError): ... +class ParseError(SyntaxError): + code: int + position: Tuple[int, int] def iselement(element: object) -> bool: ... @@ -26,20 +33,15 @@ _parser_input_type = Union[bytes, Text] # there is a 'name' attribute.) _str_argument_type = Union[str, Text] -# Type for return values from individual tag/attr/text values and serialization +# Type for return values from individual tag/attr/text values if sys.version_info >= (3,): # note: in python3, everything comes out as str, yay: _str_result_type = str - # unfortunately, tostring and tostringlist can return either bytes or str - # depending on the value of `encoding` parameter. Client code knows best: - _tostring_result_type = Any else: # in python2, if the tag/attribute/text wasn't decode-able as ascii, it # comes out as a unicode string; otherwise it comes out as str. (see # _fixtext function in the source). Client code knows best: _str_result_type = Any - # On the bright side, tostring and tostringlist always return bytes: - _tostring_result_type = bytes class Element(MutableSequence[Element]): tag: _str_result_type @@ -53,8 +55,14 @@ class Element(MutableSequence[Element]): def extend(self, elements: Iterable[Element]) -> None: ... def find(self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> Optional[Element]: ... def findall(self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> List[Element]: ... - def findtext(self, path: _str_argument_type, default: Optional[_T] = ..., namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> Union[_T, _str_result_type]: ... - def get(self, key: _str_argument_type, default: Optional[_T] = ...) -> Union[_str_result_type, _T]: ... + @overload + def findtext(self, path: _str_argument_type, *, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> Optional[_str_result_type]: ... + @overload + def findtext(self, path: _str_argument_type, default: _T, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> Union[_T, _str_result_type]: ... + @overload + def get(self, key: _str_argument_type) -> Optional[_str_result_type]: ... + @overload + def get(self, key: _str_argument_type, default: _T) -> Union[_str_result_type, _T]: ... def getchildren(self) -> List[Element]: ... def getiterator(self, tag: Optional[_str_argument_type] = ...) -> List[Element]: ... if sys.version_info >= (3, 2): @@ -102,7 +110,10 @@ class ElementTree: def iter(self, tag: Optional[_str_argument_type] = ...) -> Generator[Element, None, None]: ... def getiterator(self, tag: Optional[_str_argument_type] = ...) -> List[Element]: ... def find(self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> Optional[Element]: ... - def findtext(self, path: _str_argument_type, default: Optional[_T] = ..., namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> Union[_T, _str_result_type]: ... + @overload + def findtext(self, path: _str_argument_type, *, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> Optional[_str_result_type]: ... + @overload + def findtext(self, path: _str_argument_type, default: _T, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> Union[_T, _str_result_type]: ... def findall(self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> List[Element]: ... def iterfind(self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...) -> List[Element]: ... if sys.version_info >= (3, 4): @@ -112,12 +123,22 @@ class ElementTree: def write_c14n(self, file: _file_or_filename) -> None: ... def register_namespace(prefix: _str_argument_type, uri: _str_argument_type) -> None: ... -if sys.version_info >= (3, 4): - def tostring(element: Element, encoding: Optional[str] = ..., method: Optional[str] = ..., *, short_empty_elements: bool = ...) -> _tostring_result_type: ... - def tostringlist(element: Element, encoding: Optional[str] = ..., method: Optional[str] = ..., *, short_empty_elements: bool = ...) -> List[_tostring_result_type]: ... +if sys.version_info >= (3,): + @overload + def tostring(element: Element, encoding: None = ..., method: Optional[str] = ..., *, short_empty_elements: bool = ...) -> bytes: ... + @overload + def tostring(element: Element, encoding: Literal["unicode"], method: Optional[str] = ..., *, short_empty_elements: bool = ...) -> str: ... + @overload + def tostring(element: Element, encoding: str, method: Optional[str] = ..., *, short_empty_elements: bool = ...) -> Any: ... + @overload + def tostringlist(element: Element, encoding: None = ..., method: Optional[str] = ..., *, short_empty_elements: bool = ...) -> List[bytes]: ... + @overload + def tostringlist(element: Element, encoding: Literal["unicode"], method: Optional[str] = ..., *, short_empty_elements: bool = ...) -> List[str]: ... + @overload + def tostringlist(element: Element, encoding: str, method: Optional[str] = ..., *, short_empty_elements: bool = ...) -> List[Any]: ... else: - def tostring(element: Element, encoding: Optional[str] = ..., method: Optional[str] = ...) -> _tostring_result_type: ... - def tostringlist(element: Element, encoding: Optional[str] = ..., method: Optional[str] = ...) -> List[_tostring_result_type]: ... + def tostring(element: Element, encoding: Optional[str] = ..., method: Optional[str] = ...) -> bytes: ... + def tostringlist(element: Element, encoding: Optional[str] = ..., method: Optional[str] = ...) -> List[bytes]: ... def dump(elem: Element) -> None: ... def parse(source: _file_or_filename, parser: Optional[XMLParser] = ...) -> ElementTree: ... def iterparse(source: _file_or_filename, events: Optional[Sequence[str]] = ..., parser: Optional[XMLParser] = ...) -> Iterator[Tuple[str, Any]]: ... diff --git a/stdlib/2and3/zipfile.pyi b/stdlib/2and3/zipfile.pyi index a06d3fd98928..a7737215d0dd 100644 --- a/stdlib/2and3/zipfile.pyi +++ b/stdlib/2and3/zipfile.pyi @@ -1,7 +1,8 @@ # Stubs for zipfile -from typing import Callable, Dict, IO, Iterable, List, Optional, Text, Tuple, Type, Union +from typing import Callable, Dict, IO, Iterable, List, Optional, Text, Tuple, Type, Union, Sequence, Pattern from types import TracebackType +import io import os import sys @@ -23,18 +24,39 @@ error = BadZipfile class LargeZipFile(Exception): ... +class ZipExtFile(io.BufferedIOBase): + MAX_N: int = ... + MIN_READ_SIZE: int = ... + + if sys.version_info < (3, 6): + PATTERN: Pattern[str] = ... + + if sys.version_info >= (3, 7): + MAX_SEEK_READ: int = ... + + newlines: Optional[List[bytes]] + mode: str + name: str + + def __init__(self, fileobj: IO[bytes], mode: str, zipinfo: ZipInfo, decrypter: Optional[Callable[[Sequence[int]], bytes]] = ..., close_fileobj: bool = ...) -> None: ... + def __repr__(self) -> str: ... + def peek(self, n: int = ...) -> bytes: ... + def read1(self, n: Optional[int]) -> bytes: ... # type: ignore + class ZipFile: + filename: Optional[Text] debug: int comment: bytes filelist: List[ZipInfo] fp: IO[bytes] NameToInfo: Dict[Text, ZipInfo] + start_dir: int # undocumented def __init__(self, file: Union[_Path, IO[bytes]], mode: Text = ..., compression: int = ..., allowZip64: bool = ...) -> None: ... def __enter__(self) -> ZipFile: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... + exc_tb: Optional[TracebackType]) -> None: ... def close(self) -> None: ... def getinfo(self, name: Text) -> ZipInfo: ... def infolist(self) -> List[ZipInfo]: ... diff --git a/stdlib/3.7/dataclasses.pyi b/stdlib/3.7/dataclasses.pyi index f8bcd52634df..e3bf1d1365b9 100644 --- a/stdlib/3.7/dataclasses.pyi +++ b/stdlib/3.7/dataclasses.pyi @@ -34,7 +34,7 @@ class Field(Generic[_T]): hash: Optional[bool] init: bool compare: bool - metadata: Optional[Mapping[str, Any]] + metadata: Mapping[str, Any] # NOTE: Actual return type is 'Field[_T]', but we want to help type checkers diff --git a/stdlib/3/_ast.pyi b/stdlib/3/_ast.pyi index 9f4284e64fa7..df2bf9a28633 100644 --- a/stdlib/3/_ast.pyi +++ b/stdlib/3/_ast.pyi @@ -269,7 +269,7 @@ class Bytes(expr): # Deprecated in 3.8; use Constant class NameConstant(expr): value: Any -if sys.version_info >= (3, 8): +if sys.version_info >= (3, 6): class Constant(expr): value: Any # None, str, bytes, bool, int, float, complex, Ellipsis kind: Optional[str] @@ -277,6 +277,7 @@ if sys.version_info >= (3, 8): s: Any n: complex +if sys.version_info >= (3, 8): class NamedExpr(expr): target: expr value: expr diff --git a/stdlib/3/_imp.pyi b/stdlib/3/_imp.pyi index 7015b3b0cb0e..1992e3bda119 100644 --- a/stdlib/3/_imp.pyi +++ b/stdlib/3/_imp.pyi @@ -4,10 +4,9 @@ import sys import types from typing import Any, List -if sys.version_info >= (3, 5): - from importlib.machinery import ModuleSpec - def create_builtin(spec: ModuleSpec) -> types.ModuleType: ... - def create_dynamic(spec: ModuleSpec, file: Any = ...) -> None: ... +from importlib.machinery import ModuleSpec +def create_builtin(spec: ModuleSpec) -> types.ModuleType: ... +def create_dynamic(spec: ModuleSpec, file: Any = ...) -> None: ... def acquire_lock() -> None: ... def exec_builtin(mod: types.ModuleType) -> int: ... diff --git a/stdlib/3/_operator.pyi b/stdlib/3/_operator.pyi index 6d08cd7efaf9..bd162ab9f207 100644 --- a/stdlib/3/_operator.pyi +++ b/stdlib/3/_operator.pyi @@ -57,8 +57,8 @@ from operator import ( itemgetter as itemgetter, attrgetter as attrgetter, methodcaller as methodcaller, + matmul as matmul, + imatmul as imatmul, ) -if sys.version_info >= (3, 5): - from operator import matmul as matmul, imatmul as imatmul def _compare_digest(a: AnyStr, b: AnyStr) -> bool: ... diff --git a/stdlib/3/_threading_local.pyi b/stdlib/3/_threading_local.pyi index a286d2dd54cc..638c93f8b05a 100644 --- a/stdlib/3/_threading_local.pyi +++ b/stdlib/3/_threading_local.pyi @@ -7,7 +7,7 @@ localdict = Dict[Any, Any] class _localimpl: key: str - dicts: Dict[int, Tuple[ReferenceType, localdict]] + dicts: Dict[int, Tuple[ReferenceType[Any], localdict]] def __init__(self) -> None: ... def get_dict(self) -> localdict: ... def create_dict(self) -> localdict: ... diff --git a/stdlib/3/_tracemalloc.pyi b/stdlib/3/_tracemalloc.pyi index 21d00332ad37..a46db2419f20 100644 --- a/stdlib/3/_tracemalloc.pyi +++ b/stdlib/3/_tracemalloc.pyi @@ -3,7 +3,7 @@ # for a more precise manual annotation of this module. # Feel free to edit the source below, but remove this header when you do. -from typing import Any +from typing import Any, Tuple def _get_object_traceback(*args, **kwargs) -> Any: ... @@ -14,7 +14,7 @@ def clear_traces() -> None: ... def get_traceback_limit() -> int: ... -def get_traced_memory() -> tuple: ... +def get_traced_memory() -> Tuple[Any, ...]: ... def get_tracemalloc_memory() -> Any: ... diff --git a/stdlib/3/_warnings.pyi b/stdlib/3/_warnings.pyi index 6529c40b9993..c055b2a1d080 100644 --- a/stdlib/3/_warnings.pyi +++ b/stdlib/3/_warnings.pyi @@ -1,11 +1,11 @@ -from typing import Any, List, Optional, Type +from typing import Any, Dict, List, Optional, Tuple, Type _defaultaction: str -_onceregistry: dict -filters: List[tuple] +_onceregistry: Dict[Any, Any] +filters: List[Tuple[Any, ...]] def warn(message: Warning, category: Optional[Type[Warning]] = ..., stacklevel: int = ...) -> None: ... def warn_explicit(message: Warning, category: Optional[Type[Warning]], filename: str, lineno: int, - module: Any = ..., registry: dict = ..., - module_globals: dict = ...) -> None: ... + module: Any = ..., registry: Dict[Any, Any] = ..., + module_globals: Dict[Any, Any] = ...) -> None: ... diff --git a/stdlib/3/_winapi.pyi b/stdlib/3/_winapi.pyi index af6c9231b05c..18a1ee937394 100644 --- a/stdlib/3/_winapi.pyi +++ b/stdlib/3/_winapi.pyi @@ -1,5 +1,11 @@ +import sys from typing import Any, Union, Tuple, Optional, overload, Dict, NoReturn, Sequence +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + CREATE_NEW_CONSOLE: int CREATE_NEW_PROCESS_GROUP: int DUPLICATE_CLOSE_SOURCE: int @@ -46,11 +52,12 @@ WAIT_TIMEOUT: int def CloseHandle(handle: int) -> None: ... -# TODO: once literal types are supported, overload with Literal[True/False] @overload -def ConnectNamedPipe(handle: int, overlapped: Union[int, bool]) -> Any: ... +def ConnectNamedPipe(handle: int, overlapped: Literal[True]) -> Overlapped: ... +@overload +def ConnectNamedPipe(handle: int, overlapped: Literal[False] = ...) -> None: ... @overload -def ConnectNamedPipe(handle: int) -> None: ... +def ConnectNamedPipe(handle: int, overlapped: bool) -> Any: ... def CreateFile(file_name: str, desired_access: int, share_mode: int, security_attributes: int, creation_disposition: int, flags_and_attributes: int, template_file: int) -> int: ... def CreateJunction(src_path: str, dest_path: str) -> None: ... diff --git a/stdlib/3/ast.pyi b/stdlib/3/ast.pyi index 090d5f8aec84..8e89b2486d94 100644 --- a/stdlib/3/ast.pyi +++ b/stdlib/3/ast.pyi @@ -1,11 +1,9 @@ -# Python 3.5 ast - import sys # Rename typing to _typing, as not to conflict with typing imported # from _ast below when loaded in an unorthodox way by the Dropbox # internal Bazel integration. import typing as _typing -from typing import Any, Iterator, Optional, Union, TypeVar +from typing import overload, Any, Iterator, Optional, Union, TypeVar # The same unorthodox Bazel integration causes issues with sys, which # is imported in both modules. unfortunately we can't just rename sys, @@ -13,6 +11,11 @@ from typing import Any, Iterator, Optional, Union, TypeVar # sys. from _ast import * # type: ignore +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + class NodeVisitor(): def visit(self, node: AST) -> Any: ... def generic_visit(self, node: AST) -> Any: ... @@ -23,9 +26,18 @@ class NodeTransformer(NodeVisitor): _T = TypeVar('_T', bound=AST) if sys.version_info >= (3, 8): + @overload + def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: Literal["exec"] = ..., + type_comments: bool = ..., feature_version: int = ...) -> Module: ... + + @overload def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ..., type_comments: bool = ..., feature_version: int = ...) -> AST: ... else: + @overload + def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: Literal["exec"] = ...) -> Module: ... + + @overload def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ...) -> AST: ... def copy_location(new_node: _T, old_node: AST) -> _T: ... diff --git a/stdlib/3/asyncio/__init__.pyi b/stdlib/3/asyncio/__init__.pyi index b98c2d1c8bd6..885dfce099d3 100644 --- a/stdlib/3/asyncio/__init__.pyi +++ b/stdlib/3/asyncio/__init__.pyi @@ -54,7 +54,10 @@ from asyncio.tasks import ( wait_for as wait_for, Task as Task, ) -from asyncio.base_events import BaseEventLoop as BaseEventLoop +from asyncio.base_events import ( + BaseEventLoop as BaseEventLoop, + Server as Server +) from asyncio.events import ( AbstractEventLoopPolicy as AbstractEventLoopPolicy, AbstractEventLoop as AbstractEventLoop, @@ -84,14 +87,11 @@ from asyncio.locks import ( BoundedSemaphore as BoundedSemaphore, ) -if sys.version_info < (3, 5): - from asyncio.queues import JoinableQueue as JoinableQueue -else: - from asyncio.futures import isfuture as isfuture - from asyncio.events import ( - _set_running_loop as _set_running_loop, - _get_running_loop as _get_running_loop, - ) +from asyncio.futures import isfuture as isfuture +from asyncio.events import ( + _set_running_loop as _set_running_loop, + _get_running_loop as _get_running_loop, +) if sys.platform != 'win32': from asyncio.streams import ( open_unix_connection as open_unix_connection, diff --git a/stdlib/3/asyncio/base_events.pyi b/stdlib/3/asyncio/base_events.pyi index 2262a67f8b3c..8a959a9ee0dc 100644 --- a/stdlib/3/asyncio/base_events.pyi +++ b/stdlib/3/asyncio/base_events.pyi @@ -1,8 +1,9 @@ import selectors -from socket import socket +from socket import socket, _Address, _RetAddress import ssl import sys -from typing import Any, Awaitable, Callable, Dict, Generator, List, Optional, Sequence, Tuple, TypeVar, Union, overload +from typing import Any, Awaitable, Callable, Dict, Generator, IO, List, Optional, Sequence, Tuple, TypeVar, Union, overload +from abc import ABCMeta from asyncio.futures import Future from asyncio.coroutines import coroutine from asyncio.events import AbstractEventLoop, AbstractServer, Handle, TimerHandle @@ -17,7 +18,9 @@ _ProtocolFactory = Callable[[], BaseProtocol] _SSLContext = Union[bool, None, ssl.SSLContext] _TransProtPair = Tuple[BaseTransport, BaseProtocol] -class BaseEventLoop(AbstractEventLoop): +class Server(AbstractServer): ... + +class BaseEventLoop(AbstractEventLoop, metaclass=ABCMeta): def run_forever(self) -> None: ... # Can't use a union, see mypy issue # 1873. @@ -39,8 +42,7 @@ class BaseEventLoop(AbstractEventLoop): def call_at(self, when: float, callback: Callable[..., Any], *args: Any) -> TimerHandle: ... def time(self) -> float: ... # Future methods - if sys.version_info >= (3, 5): - def create_future(self) -> Future[Any]: ... + def create_future(self) -> Future[Any]: ... # Tasks methods def create_task(self, coro: Union[Awaitable[_T], Generator[Any, None, _T]]) -> Task[_T]: ... def set_task_factory(self, factory: Optional[Callable[[AbstractEventLoop, Generator[Any, None, _T]], Future[_T]]]) -> None: ... @@ -59,38 +61,64 @@ class BaseEventLoop(AbstractEventLoop): family: int = ..., type: int = ..., proto: int = ..., flags: int = ...) -> Generator[Any, None, List[Tuple[int, int, int, str, Tuple[Any, ...]]]]: ... @coroutine - def getnameinfo(self, sockaddr: tuple, flags: int = ...) -> Generator[Any, None, Tuple[str, int]]: ... - @overload - @coroutine - def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *, - ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: None = ..., - local_addr: Optional[str] = ..., server_hostname: Optional[str] = ...) -> Generator[Any, None, _TransProtPair]: ... - @overload - @coroutine - def create_connection(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, - ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: socket, - local_addr: None = ..., server_hostname: Optional[str] = ...) -> Generator[Any, None, _TransProtPair]: ... - @overload - @coroutine - def create_server(self, protocol_factory: _ProtocolFactory, host: Optional[Union[str, Sequence[str]]] = ..., port: int = ..., *, - family: int = ..., flags: int = ..., - sock: None = ..., backlog: int = ..., ssl: _SSLContext = ..., - reuse_address: Optional[bool] = ..., - reuse_port: Optional[bool] = ...) -> Generator[Any, None, AbstractServer]: ... - @overload - @coroutine - def create_server(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, - family: int = ..., flags: int = ..., - sock: socket, backlog: int = ..., ssl: _SSLContext = ..., - reuse_address: Optional[bool] = ..., - reuse_port: Optional[bool] = ...) -> Generator[Any, None, AbstractServer]: ... - @coroutine - def create_unix_connection(self, protocol_factory: _ProtocolFactory, path: str, *, - ssl: _SSLContext = ..., sock: Optional[socket] = ..., - server_hostname: str = ...) -> Generator[Any, None, _TransProtPair]: ... - @coroutine - def create_unix_server(self, protocol_factory: _ProtocolFactory, path: str, *, - sock: Optional[socket] = ..., backlog: int = ..., ssl: _SSLContext = ...) -> Generator[Any, None, AbstractServer]: ... + def getnameinfo(self, sockaddr: Tuple[Any, ...], flags: int = ...) -> Generator[Any, None, Tuple[str, int]]: ... + if sys.version_info >= (3, 7): + async def sock_sendfile(self, sock: socket, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *, + fallback: bool = ...) -> int: ... + @overload + async def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *, + ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., + sock: None = ..., local_addr: Optional[str] = ..., server_hostname: Optional[str] = ..., + ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ... + @overload + async def create_connection(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, + ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., + sock: socket, local_addr: None = ..., server_hostname: Optional[str] = ..., + ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ... + @overload + async def create_server(self, protocol_factory: _ProtocolFactory, host: Optional[Union[str, Sequence[str]]] = ..., + port: int = ..., *, family: int = ..., flags: int = ..., sock: None = ..., backlog: int = ..., + ssl: _SSLContext = ..., reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ..., + ssl_handshake_timeout: Optional[float] = ..., start_serving: bool = ...) -> Server: ... + @overload + async def create_server(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, + family: int = ..., flags: int = ..., sock: socket = ..., backlog: int = ..., + ssl: _SSLContext = ..., reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ..., + ssl_handshake_timeout: Optional[float] = ..., start_serving: bool = ...) -> Server: ... + async def connect_accepted_socket(self, protocol_factory: _ProtocolFactory, sock: socket, *, ssl: _SSLContext = ..., + ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ... + async def sendfile(self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *, + fallback: bool = ...) -> int: ... + async def start_tls(self, transport: BaseTransport, protocol: BaseProtocol, sslcontext: ssl.SSLContext, *, + server_side: bool = ..., server_hostname: Optional[str] = ..., + ssl_handshake_timeout: Optional[float] = ...) -> BaseTransport: ... + else: + @overload + @coroutine + def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *, + ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: None = ..., + local_addr: Optional[str] = ..., server_hostname: Optional[str] = ...) -> Generator[Any, None, _TransProtPair]: ... + @overload + @coroutine + def create_connection(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, + ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: socket, + local_addr: None = ..., server_hostname: Optional[str] = ...) -> Generator[Any, None, _TransProtPair]: ... + @overload + @coroutine + def create_server(self, protocol_factory: _ProtocolFactory, host: Optional[Union[str, Sequence[str]]] = ..., port: int = ..., *, + family: int = ..., flags: int = ..., + sock: None = ..., backlog: int = ..., ssl: _SSLContext = ..., + reuse_address: Optional[bool] = ..., + reuse_port: Optional[bool] = ...) -> Generator[Any, None, Server]: ... + @overload + @coroutine + def create_server(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, + family: int = ..., flags: int = ..., + sock: socket, backlog: int = ..., ssl: _SSLContext = ..., + reuse_address: Optional[bool] = ..., + reuse_port: Optional[bool] = ...) -> Generator[Any, None, Server]: ... + @coroutine + def connect_accepted_socket(self, protocol_factory: _ProtocolFactory, sock: socket, *, ssl: _SSLContext = ...) -> Generator[Any, None, _TransProtPair]: ... @coroutine def create_datagram_endpoint(self, protocol_factory: _ProtocolFactory, local_addr: Optional[Tuple[str, int]] = ..., remote_addr: Optional[Tuple[str, int]] = ..., *, @@ -98,8 +126,6 @@ class BaseEventLoop(AbstractEventLoop): reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ..., allow_broadcast: Optional[bool] = ..., sock: Optional[socket] = ...) -> Generator[Any, None, _TransProtPair]: ... - @coroutine - def connect_accepted_socket(self, protocol_factory: _ProtocolFactory, sock: socket, *, ssl: _SSLContext = ...) -> Generator[Any, None, _TransProtPair]: ... # Pipes and subprocesses. @coroutine def connect_read_pipe(self, protocol_factory: _ProtocolFactory, pipe: Any) -> Generator[Any, None, _TransProtPair]: ... @@ -117,22 +143,24 @@ class BaseEventLoop(AbstractEventLoop): def remove_reader(self, fd: selectors._FileObject) -> None: ... def add_writer(self, fd: selectors._FileObject, callback: Callable[..., Any], *args: Any) -> None: ... def remove_writer(self, fd: selectors._FileObject) -> None: ... - # Completion based I/O methods returning Futures. - @coroutine - def sock_recv(self, sock: socket, nbytes: int) -> Generator[Any, None, bytes]: ... - @coroutine - def sock_sendall(self, sock: socket, data: bytes) -> Generator[Any, None, None]: ... - @coroutine - def sock_connect(self, sock: socket, address: str) -> Generator[Any, None, None]: ... - @coroutine - def sock_accept(self, sock: socket) -> Generator[Any, None, Tuple[socket, Any]]: ... + # Completion based I/O methods returning Futures prior to 3.7 + if sys.version_info >= (3, 7): + async def sock_recv(self, sock: socket, nbytes: int) -> bytes: ... + async def sock_recv_into(self, sock: socket, buf: bytearray) -> int: ... + async def sock_sendall(self, sock: socket, data: bytes) -> None: ... + async def sock_connect(self, sock: socket, address: _Address) -> None: ... + async def sock_accept(self, sock: socket) -> Tuple[socket, _RetAddress]: ... + else: + def sock_recv(self, sock: socket, nbytes: int) -> Future[bytes]: ... + def sock_sendall(self, sock: socket, data: bytes) -> Future[None]: ... + def sock_connect(self, sock: socket, address: _Address) -> Future[None]: ... + def sock_accept(self, sock: socket) -> Future[Tuple[socket, _RetAddress]]: ... # Signal handling. def add_signal_handler(self, sig: int, callback: Callable[..., Any], *args: Any) -> None: ... def remove_signal_handler(self, sig: int) -> None: ... # Error handlers. def set_exception_handler(self, handler: Optional[_ExceptionHandler]) -> None: ... - if sys.version_info >= (3, 5): - def get_exception_handler(self) -> Optional[_ExceptionHandler]: ... + def get_exception_handler(self) -> Optional[_ExceptionHandler]: ... def default_exception_handler(self, context: _Context) -> None: ... def call_exception_handler(self, context: _Context) -> None: ... # Debug flag management. diff --git a/stdlib/3/asyncio/events.pyi b/stdlib/3/asyncio/events.pyi index c81d027efc32..66f7c9f9e134 100644 --- a/stdlib/3/asyncio/events.pyi +++ b/stdlib/3/asyncio/events.pyi @@ -1,8 +1,8 @@ import selectors -from socket import socket +from socket import socket, _Address, _RetAddress import ssl import sys -from typing import Any, Awaitable, Callable, Dict, Generator, List, Optional, Sequence, Tuple, TypeVar, Union, overload +from typing import Any, Awaitable, Callable, Dict, Generator, IO, List, Optional, Sequence, Tuple, TypeVar, Union, overload from abc import ABCMeta, abstractmethod from asyncio.futures import Future from asyncio.coroutines import coroutine @@ -26,6 +26,7 @@ class Handle: def __repr__(self) -> str: ... def cancel(self) -> None: ... def _run(self) -> None: ... + def cancelled(self) -> bool: ... class TimerHandle(Handle): def __init__(self, when: float, callback: Callable[..., Any], args: List[Any], @@ -35,6 +36,11 @@ class TimerHandle(Handle): class AbstractServer: sockets: Optional[List[socket]] def close(self) -> None: ... + if sys.version_info >= (3, 7): + def get_loop(self) -> AbstractEventLoop: ... + def is_serving(self) -> bool: ... + async def start_serving(self) -> None: ... + async def serve_forever(self) -> None: ... @coroutine def wait_closed(self) -> Generator[Any, None, None]: ... @@ -73,9 +79,8 @@ class AbstractEventLoop(metaclass=ABCMeta): @abstractmethod def time(self) -> float: ... # Future methods - if sys.version_info >= (3, 5): - @abstractmethod - def create_future(self) -> Future[Any]: ... + @abstractmethod + def create_future(self) -> Future[Any]: ... # Tasks methods @abstractmethod def create_task(self, coro: Union[Awaitable[_T], Generator[Any, None, _T]]) -> Task[_T]: ... @@ -102,44 +107,94 @@ class AbstractEventLoop(metaclass=ABCMeta): flags: int = ...) -> Generator[Any, None, List[Tuple[int, int, int, str, Tuple[Any, ...]]]]: ... @abstractmethod @coroutine - def getnameinfo(self, sockaddr: tuple, flags: int = ...) -> Generator[Any, None, Tuple[str, int]]: ... - @overload - @abstractmethod - @coroutine - def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *, - ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: None = ..., - local_addr: Optional[str] = ..., server_hostname: Optional[str] = ...) -> Generator[Any, None, _TransProtPair]: ... - @overload - @abstractmethod - @coroutine - def create_connection(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, - ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: socket, - local_addr: None = ..., server_hostname: Optional[str] = ...) -> Generator[Any, None, _TransProtPair]: ... - @overload - @abstractmethod - @coroutine - def create_server(self, protocol_factory: _ProtocolFactory, host: Optional[Union[str, Sequence[str]]] = ..., port: int = ..., *, - family: int = ..., flags: int = ..., - sock: None = ..., backlog: int = ..., ssl: _SSLContext = ..., - reuse_address: Optional[bool] = ..., - reuse_port: Optional[bool] = ...) -> Generator[Any, None, AbstractServer]: ... - @overload - @abstractmethod - @coroutine - def create_server(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, - family: int = ..., flags: int = ..., - sock: socket, backlog: int = ..., ssl: _SSLContext = ..., - reuse_address: Optional[bool] = ..., - reuse_port: Optional[bool] = ...) -> Generator[Any, None, AbstractServer]: ... - @abstractmethod - @coroutine - def create_unix_connection(self, protocol_factory: _ProtocolFactory, path: str, *, - ssl: _SSLContext = ..., sock: Optional[socket] = ..., - server_hostname: str = ...) -> Generator[Any, None, _TransProtPair]: ... - @abstractmethod - @coroutine - def create_unix_server(self, protocol_factory: _ProtocolFactory, path: str, *, - sock: Optional[socket] = ..., backlog: int = ..., ssl: _SSLContext = ...) -> Generator[Any, None, AbstractServer]: ... + def getnameinfo(self, sockaddr: Tuple[Any, ...], flags: int = ...) -> Generator[Any, None, Tuple[str, int]]: ... + if sys.version_info >= (3, 7): + @abstractmethod + async def sock_sendfile(self, sock: socket, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *, + fallback: bool = ...) -> int: ... + @overload + @abstractmethod + async def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *, + ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., + sock: None = ..., local_addr: Optional[str] = ..., server_hostname: Optional[str] = ..., + ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ... + @overload + @abstractmethod + async def create_connection(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, + ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., + sock: socket, local_addr: None = ..., server_hostname: Optional[str] = ..., + ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ... + @overload + @abstractmethod + async def create_server(self, protocol_factory: _ProtocolFactory, host: Optional[Union[str, Sequence[str]]] = ..., + port: int = ..., *, family: int = ..., flags: int = ..., sock: None = ..., backlog: int = ..., + ssl: _SSLContext = ..., reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ..., + ssl_handshake_timeout: Optional[float] = ..., start_serving: bool = ...) -> AbstractServer: ... + @overload + @abstractmethod + async def create_server(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, + family: int = ..., flags: int = ..., sock: socket = ..., backlog: int = ..., + ssl: _SSLContext = ..., reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ..., + ssl_handshake_timeout: Optional[float] = ..., start_serving: bool = ...) -> AbstractServer: ... + @abstractmethod + async def create_unix_connection(self, protocol_factory: _ProtocolFactory, path: str, *, ssl: _SSLContext = ..., + sock: Optional[socket] = ..., server_hostname: str = ..., + ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ... + @abstractmethod + async def create_unix_server(self, protocol_factory: _ProtocolFactory, path: str, *, sock: Optional[socket] = ..., + backlog: int = ..., ssl: _SSLContext = ..., ssl_handshake_timeout: Optional[float] = ..., + start_serving: bool = ...) -> AbstractServer: ... + @abstractmethod + async def connect_accepted_socket(self, protocol_factory: _ProtocolFactory, sock: socket, *, ssl: _SSLContext = ..., + ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ... + @abstractmethod + async def sendfile(self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *, + fallback: bool = ...) -> int: ... + @abstractmethod + async def start_tls(self, transport: BaseTransport, protocol: BaseProtocol, sslcontext: ssl.SSLContext, *, + server_side: bool = ..., server_hostname: Optional[str] = ..., + ssl_handshake_timeout: Optional[float] = ...) -> BaseTransport: ... + else: + @overload + @abstractmethod + @coroutine + def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *, + ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: None = ..., + local_addr: Optional[str] = ..., server_hostname: Optional[str] = ...) -> Generator[Any, None, _TransProtPair]: ... + @overload + @abstractmethod + @coroutine + def create_connection(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, + ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: socket, + local_addr: None = ..., server_hostname: Optional[str] = ...) -> Generator[Any, None, _TransProtPair]: ... + @overload + @abstractmethod + @coroutine + def create_server(self, protocol_factory: _ProtocolFactory, host: Optional[Union[str, Sequence[str]]] = ..., port: int = ..., *, + family: int = ..., flags: int = ..., + sock: None = ..., backlog: int = ..., ssl: _SSLContext = ..., + reuse_address: Optional[bool] = ..., + reuse_port: Optional[bool] = ...) -> Generator[Any, None, AbstractServer]: ... + @overload + @abstractmethod + @coroutine + def create_server(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, + family: int = ..., flags: int = ..., + sock: socket, backlog: int = ..., ssl: _SSLContext = ..., + reuse_address: Optional[bool] = ..., + reuse_port: Optional[bool] = ...) -> Generator[Any, None, AbstractServer]: ... + @abstractmethod + @coroutine + def create_unix_connection(self, protocol_factory: _ProtocolFactory, path: str, *, + ssl: _SSLContext = ..., sock: Optional[socket] = ..., + server_hostname: str = ...) -> Generator[Any, None, _TransProtPair]: ... + @abstractmethod + @coroutine + def create_unix_server(self, protocol_factory: _ProtocolFactory, path: str, *, + sock: Optional[socket] = ..., backlog: int = ..., ssl: _SSLContext = ...) -> Generator[Any, None, AbstractServer]: ... + @abstractmethod + @coroutine + def connect_accepted_socket(self, protocol_factory: _ProtocolFactory, sock: socket, *, ssl: _SSLContext = ...) -> Generator[Any, None, _TransProtPair]: ... @abstractmethod @coroutine def create_datagram_endpoint(self, protocol_factory: _ProtocolFactory, @@ -148,9 +203,6 @@ class AbstractEventLoop(metaclass=ABCMeta): reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ..., allow_broadcast: Optional[bool] = ..., sock: Optional[socket] = ...) -> Generator[Any, None, _TransProtPair]: ... - @abstractmethod - @coroutine - def connect_accepted_socket(self, protocol_factory: _ProtocolFactory, sock: socket, *, ssl: _SSLContext = ...) -> Generator[Any, None, _TransProtPair]: ... # Pipes and subprocesses. @abstractmethod @coroutine @@ -176,19 +228,27 @@ class AbstractEventLoop(metaclass=ABCMeta): def add_writer(self, fd: selectors._FileObject, callback: Callable[..., Any], *args: Any) -> None: ... @abstractmethod def remove_writer(self, fd: selectors._FileObject) -> None: ... - # Completion based I/O methods returning Futures. - @abstractmethod - @coroutine - def sock_recv(self, sock: socket, nbytes: int) -> Generator[Any, None, bytes]: ... - @abstractmethod - @coroutine - def sock_sendall(self, sock: socket, data: bytes) -> Generator[Any, None, None]: ... - @abstractmethod - @coroutine - def sock_connect(self, sock: socket, address: str) -> Generator[Any, None, None]: ... - @abstractmethod - @coroutine - def sock_accept(self, sock: socket) -> Generator[Any, None, Tuple[socket, Any]]: ... + # Completion based I/O methods returning Futures prior to 3.7 + if sys.version_info >= (3, 7): + @abstractmethod + async def sock_recv(self, sock: socket, nbytes: int) -> bytes: ... + @abstractmethod + async def sock_recv_into(self, sock: socket, buf: bytearray) -> int: ... + @abstractmethod + async def sock_sendall(self, sock: socket, data: bytes) -> None: ... + @abstractmethod + async def sock_connect(self, sock: socket, address: _Address) -> None: ... + @abstractmethod + async def sock_accept(self, sock: socket) -> Tuple[socket, _RetAddress]: ... + else: + @abstractmethod + def sock_recv(self, sock: socket, nbytes: int) -> Future[bytes]: ... + @abstractmethod + def sock_sendall(self, sock: socket, data: bytes) -> Future[None]: ... + @abstractmethod + def sock_connect(self, sock: socket, address: _Address) -> Future[None]: ... + @abstractmethod + def sock_accept(self, sock: socket) -> Future[Tuple[socket, _RetAddress]]: ... # Signal handling. @abstractmethod def add_signal_handler(self, sig: int, callback: Callable[..., Any], *args: Any) -> None: ... @@ -197,9 +257,8 @@ class AbstractEventLoop(metaclass=ABCMeta): # Error handlers. @abstractmethod def set_exception_handler(self, handler: Optional[_ExceptionHandler]) -> None: ... - if sys.version_info >= (3, 5): - @abstractmethod - def get_exception_handler(self) -> Optional[_ExceptionHandler]: ... + @abstractmethod + def get_exception_handler(self) -> Optional[_ExceptionHandler]: ... @abstractmethod def default_exception_handler(self, context: _Context) -> None: ... @abstractmethod diff --git a/stdlib/3/asyncio/futures.pyi b/stdlib/3/asyncio/futures.pyi index ed2e4a0c951c..37bd02c30fcd 100644 --- a/stdlib/3/asyncio/futures.pyi +++ b/stdlib/3/asyncio/futures.pyi @@ -14,7 +14,7 @@ if sys.version_info >= (3, 7): __all__: List[str] _T = TypeVar('_T') -_S = TypeVar('_S', bound=Future) +_S = TypeVar('_S') class InvalidStateError(Error): ... @@ -26,8 +26,7 @@ class _TracebackLogger: def clear(self) -> None: ... def __del__(self) -> None: ... -if sys.version_info >= (3, 5): - def isfuture(obj: object) -> bool: ... +def isfuture(obj: object) -> bool: ... class Future(Awaitable[_T], Iterable[_T]): _state: str diff --git a/stdlib/3/asyncio/protocols.pyi b/stdlib/3/asyncio/protocols.pyi index bb258e119697..40592382d7e2 100644 --- a/stdlib/3/asyncio/protocols.pyi +++ b/stdlib/3/asyncio/protocols.pyi @@ -14,6 +14,10 @@ class Protocol(BaseProtocol): def data_received(self, data: bytes) -> None: ... def eof_received(self) -> Optional[bool]: ... +class BufferedProtocol(Protocol): + def get_buffer(self, sizehint: int) -> bytearray: ... + def buffer_updated(self, nbytes: int) -> None: ... + class DatagramProtocol(BaseProtocol): def datagram_received(self, data: Union[bytes, Text], addr: Tuple[str, int]) -> None: ... def error_received(self, exc: Exception) -> None: ... diff --git a/stdlib/3/asyncio/queues.pyi b/stdlib/3/asyncio/queues.pyi index dc4e9efa1f83..243a74d54201 100644 --- a/stdlib/3/asyncio/queues.pyi +++ b/stdlib/3/asyncio/queues.pyi @@ -42,9 +42,3 @@ class PriorityQueue(Queue[_T]): ... class LifoQueue(Queue[_T]): ... - -if sys.version_info < (3, 5): - class JoinableQueue(Queue[_T]): - def task_done(self) -> None: ... - @coroutine - def join(self) -> Generator[Any, None, bool]: ... diff --git a/stdlib/3/asyncio/tasks.pyi b/stdlib/3/asyncio/tasks.pyi index 6fe13f57eb5e..05b590eb0430 100644 --- a/stdlib/3/asyncio/tasks.pyi +++ b/stdlib/3/asyncio/tasks.pyi @@ -7,6 +7,11 @@ from types import FrameType from .events import AbstractEventLoop from .futures import Future +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + __all__: List[str] _T = TypeVar('_T') @@ -21,48 +26,78 @@ FIRST_EXCEPTION: str FIRST_COMPLETED: str ALL_COMPLETED: str -def as_completed(fs: Sequence[_FutureT[_T]], *, loop: AbstractEventLoop = ..., +def as_completed(fs: Iterable[_FutureT[_T]], *, loop: Optional[AbstractEventLoop] = ..., timeout: Optional[float] = ...) -> Iterator[Future[_T]]: ... def ensure_future(coro_or_future: _FutureT[_T], *, loop: Optional[AbstractEventLoop] = ...) -> Future[_T]: ... # Prior to Python 3.7 'async' was an alias for 'ensure_future'. # It became a keyword in 3.7. + +# `gather()` actually returns a list with length equal to the number +# of tasks passed; however, Tuple is used similar to the annotation for +# zip() because typing does not support variadic type variables. See +# typing PR #1550 for discussion. @overload def gather(coro_or_future1: _FutureT[_T1], - *, loop: AbstractEventLoop = ..., return_exceptions: bool = ...) -> Future[Tuple[_T1]]: ... + *, loop: Optional[AbstractEventLoop] = ..., return_exceptions: Literal[False] = ...) -> Future[Tuple[_T1]]: ... @overload def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], - *, loop: AbstractEventLoop = ..., return_exceptions: bool = ...) -> Future[Tuple[_T1, _T2]]: ... + *, loop: Optional[AbstractEventLoop] = ..., return_exceptions: Literal[False] = ...) -> Future[Tuple[_T1, _T2]]: ... @overload def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], coro_or_future3: _FutureT[_T3], - *, loop: AbstractEventLoop = ..., return_exceptions: bool = ...) -> Future[Tuple[_T1, _T2, _T3]]: ... + *, loop: Optional[AbstractEventLoop] = ..., + return_exceptions: Literal[False] = ...) -> Future[Tuple[_T1, _T2, _T3]]: ... @overload def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], coro_or_future3: _FutureT[_T3], coro_or_future4: _FutureT[_T4], - *, loop: AbstractEventLoop = ..., return_exceptions: bool = ...) -> Future[Tuple[_T1, _T2, _T3, _T4]]: ... + *, loop: Optional[AbstractEventLoop] = ..., + return_exceptions: Literal[False] = ...) -> Future[Tuple[_T1, _T2, _T3, _T4]]: ... @overload def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], coro_or_future3: _FutureT[_T3], coro_or_future4: _FutureT[_T4], coro_or_future5: _FutureT[_T5], - *, loop: AbstractEventLoop = ..., return_exceptions: bool = ...) -> Future[Tuple[_T1, _T2, _T3, _T4, _T5]]: ... + *, loop: Optional[AbstractEventLoop] = ..., + return_exceptions: Literal[False] = ...) -> Future[Tuple[_T1, _T2, _T3, _T4, _T5]]: ... @overload def gather(coro_or_future1: _FutureT[Any], coro_or_future2: _FutureT[Any], coro_or_future3: _FutureT[Any], coro_or_future4: _FutureT[Any], coro_or_future5: _FutureT[Any], coro_or_future6: _FutureT[Any], *coros_or_futures: _FutureT[Any], - loop: AbstractEventLoop = ..., return_exceptions: bool = ...) -> Future[Tuple[Any, ...]]: ... + loop: Optional[AbstractEventLoop] = ..., return_exceptions: bool = ...) -> Future[List[Any]]: ... +@overload +def gather(coro_or_future1: _FutureT[_T1], + *, loop: Optional[AbstractEventLoop] = ..., + return_exceptions: bool = ...) -> Future[Tuple[Union[_T1, BaseException]]]: ... +@overload +def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], + *, loop: Optional[AbstractEventLoop] = ..., + return_exceptions: bool = ...) -> Future[Tuple[Union[_T1, BaseException], Union[_T2, BaseException]]]: ... +@overload +def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], coro_or_future3: _FutureT[_T3], + *, loop: Optional[AbstractEventLoop] = ..., return_exceptions: bool = ...) -> Future[ + Tuple[Union[_T1, BaseException], Union[_T2, BaseException], Union[_T3, BaseException]]]: ... +@overload +def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], coro_or_future3: _FutureT[_T3], + coro_or_future4: _FutureT[_T4], + *, loop: Optional[AbstractEventLoop] = ..., return_exceptions: bool = ...) -> Future[ + Tuple[Union[_T1, BaseException], Union[_T2, BaseException], Union[_T3, BaseException], Union[_T4, BaseException]]]: ... +@overload +def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], coro_or_future3: _FutureT[_T3], + coro_or_future4: _FutureT[_T4], coro_or_future5: _FutureT[_T5], + *, loop: Optional[AbstractEventLoop] = ..., return_exceptions: bool = ...) -> Future[ + Tuple[Union[_T1, BaseException], Union[_T2, BaseException], Union[_T3, BaseException], Union[_T4, BaseException], Union[_T5, BaseException]]]: ... def run_coroutine_threadsafe(coro: _FutureT[_T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ... -def shield(arg: _FutureT[_T], *, loop: AbstractEventLoop = ...) -> Future[_T]: ... -def sleep(delay: float, result: _T = ..., loop: AbstractEventLoop = ...) -> Future[_T]: ... -def wait(fs: Iterable[_FutureT[_T]], *, loop: AbstractEventLoop = ..., timeout: Optional[float] = ..., +def shield(arg: _FutureT[_T], *, loop: Optional[AbstractEventLoop] = ...) -> Future[_T]: ... +def sleep(delay: float, result: _T = ..., loop: Optional[AbstractEventLoop] = ...) -> Future[_T]: ... +def wait(fs: Iterable[_FutureT[_T]], *, loop: Optional[AbstractEventLoop] = ..., timeout: Optional[float] = ..., return_when: str = ...) -> Future[Tuple[Set[Future[_T]], Set[Future[_T]]]]: ... def wait_for(fut: _FutureT[_T], timeout: Optional[float], - *, loop: AbstractEventLoop = ...) -> Future[_T]: ... + *, loop: Optional[AbstractEventLoop] = ...) -> Future[_T]: ... class Task(Future[_T], Generic[_T]): @classmethod - def current_task(cls, loop: Optional[AbstractEventLoop] = ...) -> Task: ... + def current_task(cls, loop: Optional[AbstractEventLoop] = ...) -> Task[Any]: ... @classmethod - def all_tasks(cls, loop: Optional[AbstractEventLoop] = ...) -> Set[Task]: ... + def all_tasks(cls, loop: Optional[AbstractEventLoop] = ...) -> Set[Task[Any]]: ... def __init__(self, coro: Union[Generator[Any, None, _T], Awaitable[_T]], *, loop: AbstractEventLoop = ...) -> None: ... def __repr__(self) -> str: ... def get_stack(self, *, limit: int = ...) -> List[FrameType]: ... @@ -72,6 +107,6 @@ class Task(Future[_T], Generic[_T]): def _wakeup(self, future: Future[Any]) -> None: ... if sys.version_info >= (3, 7): - def all_tasks(loop: Optional[AbstractEventLoop] = ...) -> Set[Task]: ... - def create_task(coro: Union[Generator[Any, None, _T], Awaitable[_T]]) -> Task: ... - def current_task(loop: Optional[AbstractEventLoop] = ...) -> Optional[Task]: ... + def all_tasks(loop: Optional[AbstractEventLoop] = ...) -> Set[Task[Any]]: ... + def create_task(coro: Union[Generator[Any, None, _T], Awaitable[_T]]) -> Task[Any]: ... + def current_task(loop: Optional[AbstractEventLoop] = ...) -> Optional[Task[Any]]: ... diff --git a/stdlib/3/asyncio/transports.pyi b/stdlib/3/asyncio/transports.pyi index 9ea6688d7593..ea6ab4adb67b 100644 --- a/stdlib/3/asyncio/transports.pyi +++ b/stdlib/3/asyncio/transports.pyi @@ -1,4 +1,6 @@ +import sys from typing import Dict, Any, TypeVar, Mapping, List, Optional, Tuple +from asyncio.protocols import BaseProtocol __all__: List[str] @@ -7,8 +9,13 @@ class BaseTransport: def get_extra_info(self, name: Any, default: Any = ...) -> Any: ... def is_closing(self) -> bool: ... def close(self) -> None: ... + if sys.version_info >= (3, 5): + def set_protocol(self, protocol: BaseProtocol) -> None: ... + def get_protocol(self) -> BaseProtocol: ... class ReadTransport(BaseTransport): + if sys.version_info >= (3, 7): + def is_reading(self) -> bool: ... def pause_reading(self) -> None: ... def resume_reading(self) -> None: ... diff --git a/stdlib/3/collections/__init__.pyi b/stdlib/3/collections/__init__.pyi index 524ff6f8f4e3..46d3644dc60a 100644 --- a/stdlib/3/collections/__init__.pyi +++ b/stdlib/3/collections/__init__.pyi @@ -9,8 +9,12 @@ from typing import ( from . import abc from typing import ( + AsyncIterable as AsyncIterable, + AsyncIterator as AsyncIterator, + Awaitable as Awaitable, Callable as Callable, Container as Container, + Coroutine as Coroutine, Hashable as Hashable, Iterable as Iterable, Iterator as Iterator, @@ -34,13 +38,6 @@ if sys.version_info >= (3, 6): Collection as Collection, AsyncGenerator as AsyncGenerator, ) -if sys.version_info >= (3, 5): - from typing import ( - Awaitable as Awaitable, - Coroutine as Coroutine, - AsyncIterable as AsyncIterable, - AsyncIterator as AsyncIterator, - ) _S = TypeVar('_S') _T = TypeVar('_T') @@ -50,16 +47,27 @@ _VT = TypeVar('_VT') # namedtuple is special-cased in the type checker; the initializer is ignored. if sys.version_info >= (3, 7): - def namedtuple(typename: str, field_names: Union[str, Iterable[str]], *, - rename: bool = ..., module: Optional[str] = ..., defaults: Optional[Iterable[Any]] = ...) -> Type[tuple]: ... + def namedtuple( + typename: str, + field_names: Union[str, Iterable[str]], + *, + rename: bool = ..., + module: Optional[str] = ..., + defaults: Optional[Iterable[Any]] = ..., + ) -> Type[Tuple[Any, ...]]: ... elif sys.version_info >= (3, 6): - def namedtuple(typename: str, field_names: Union[str, Iterable[str]], *, - verbose: bool = ..., rename: bool = ..., module: Optional[str] = ...) -> Type[tuple]: ... + def namedtuple( + typename: str, + field_names: Union[str, Iterable[str]], + *, + verbose: bool = ..., + rename: bool = ..., + module: Optional[str] = ..., + ) -> Type[Tuple[Any, ...]]: ... else: - def namedtuple(typename: str, field_names: Union[str, Iterable[str]], - verbose: bool = ..., rename: bool = ...) -> Type[tuple]: ... - -_UserDictT = TypeVar('_UserDictT', bound=UserDict) + def namedtuple( + typename: str, field_names: Union[str, Iterable[str]], verbose: bool = ..., rename: bool = ..., + ) -> Type[Tuple[Any, ...]]: ... class UserDict(MutableMapping[_KT, _VT]): data: Dict[_KT, _VT] @@ -70,11 +78,9 @@ class UserDict(MutableMapping[_KT, _VT]): def __delitem__(self, key: _KT) -> None: ... def __iter__(self) -> Iterator[_KT]: ... def __contains__(self, key: object) -> bool: ... - def copy(self: _UserDictT) -> _UserDictT: ... + def copy(self: _S) -> _S: ... @classmethod - def fromkeys(cls: Type[_UserDictT], iterable: Iterable[_KT], value: Optional[_VT] = ...) -> _UserDictT: ... - -_UserListT = TypeVar('_UserListT', bound=UserList) + def fromkeys(cls: Type[_S], iterable: Iterable[_KT], value: Optional[_VT] = ...) -> _S: ... class UserList(MutableSequence[_T]): data: List[_T] @@ -94,16 +100,16 @@ class UserList(MutableSequence[_T]): @overload def __setitem__(self, i: slice, o: Iterable[_T]) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... - def __add__(self: _UserListT, other: Iterable[_T]) -> _UserListT: ... - def __iadd__(self: _UserListT, other: Iterable[_T]) -> _UserListT: ... - def __mul__(self: _UserListT, n: int) -> _UserListT: ... - def __imul__(self: _UserListT, n: int) -> _UserListT: ... + def __add__(self: _S, other: Iterable[_T]) -> _S: ... + def __iadd__(self: _S, other: Iterable[_T]) -> _S: ... + def __mul__(self: _S, n: int) -> _S: ... + def __imul__(self: _S, n: int) -> _S: ... def append(self, item: _T) -> None: ... def insert(self, i: int, item: _T) -> None: ... def pop(self, i: int = ...) -> _T: ... def remove(self, item: _T) -> None: ... def clear(self) -> None: ... - def copy(self: _UserListT) -> _UserListT: ... + def copy(self: _S) -> _S: ... def count(self, item: _T) -> int: ... def index(self, item: _T, *args: Any) -> int: ... def reverse(self) -> None: ... @@ -118,8 +124,7 @@ class UserString(Sequence[str]): def __int__(self) -> int: ... def __float__(self) -> float: ... def __complex__(self) -> complex: ... - if sys.version_info >= (3, 5): - def __getnewargs__(self) -> Tuple[str]: ... + def __getnewargs__(self) -> Tuple[str]: ... def __lt__(self, string: Union[str, UserString]) -> bool: ... def __le__(self, string: Union[str, UserString]) -> bool: ... def __gt__(self, string: Union[str, UserString]) -> bool: ... @@ -132,8 +137,7 @@ class UserString(Sequence[str]): def __mul__(self: _UserStringT, n: int) -> _UserStringT: ... def __mod__(self: _UserStringT, args: Any) -> _UserStringT: ... def capitalize(self: _UserStringT) -> _UserStringT: ... - if sys.version_info >= (3, 5): - def casefold(self: _UserStringT) -> _UserStringT: ... + def casefold(self: _UserStringT) -> _UserStringT: ... def center(self: _UserStringT, width: int, *args: Any) -> _UserStringT: ... def count(self, sub: Union[str, UserString], start: int = ..., end: int = ...) -> int: ... def encode(self: _UserStringT, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> _UserStringT: ... @@ -141,8 +145,7 @@ class UserString(Sequence[str]): def expandtabs(self: _UserStringT, tabsize: int = ...) -> _UserStringT: ... def find(self, sub: Union[str, UserString], start: int = ..., end: int = ...) -> int: ... def format(self, *args: Any, **kwds: Any) -> str: ... - if sys.version_info >= (3, 5): - def format_map(self, mapping: Mapping[str, Any]) -> str: ... + def format_map(self, mapping: Mapping[str, Any]) -> str: ... def index(self, sub: str, start: int = ..., end: int = ...) -> int: ... def isalpha(self) -> bool: ... def isalnum(self) -> bool: ... @@ -151,8 +154,7 @@ class UserString(Sequence[str]): def isidentifier(self) -> bool: ... def islower(self) -> bool: ... def isnumeric(self) -> bool: ... - if sys.version_info >= (3, 5): - def isprintable(self) -> bool: ... + def isprintable(self) -> bool: ... def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... @@ -160,13 +162,12 @@ class UserString(Sequence[str]): def ljust(self: _UserStringT, width: int, *args: Any) -> _UserStringT: ... def lower(self: _UserStringT) -> _UserStringT: ... def lstrip(self: _UserStringT, chars: Optional[str] = ...) -> _UserStringT: ... - if sys.version_info >= (3, 5): - @staticmethod - @overload - def maketrans(x: Union[Dict[int, _T], Dict[str, _T], Dict[Union[str, int], _T]]) -> Dict[int, _T]: ... - @staticmethod - @overload - def maketrans(x: str, y: str, z: str = ...) -> Dict[int, Union[int, None]]: ... + @staticmethod + @overload + def maketrans(x: Union[Dict[int, _T], Dict[str, _T], Dict[Union[str, int], _T]]) -> Dict[int, _T]: ... + @staticmethod + @overload + def maketrans(x: str, y: str, z: str = ...) -> Dict[int, Union[int, None]]: ... def partition(self, sep: str) -> Tuple[str, str, str]: ... def replace(self: _UserStringT, old: Union[str, UserString], new: Union[str, UserString], maxsplit: int = ...) -> _UserStringT: ... def rfind(self, sub: Union[str, UserString], start: int = ..., end: int = ...) -> int: ... @@ -197,8 +198,7 @@ class deque(MutableSequence[_T], Generic[_T]): def append(self, x: _T) -> None: ... def appendleft(self, x: _T) -> None: ... def clear(self) -> None: ... - if sys.version_info >= (3, 5): - def copy(self) -> deque[_T]: ... + def copy(self) -> deque[_T]: ... def count(self, x: _T) -> int: ... def extend(self, iterable: Iterable[_T]) -> None: ... def extendleft(self, iterable: Iterable[_T]) -> None: ... @@ -238,12 +238,9 @@ class deque(MutableSequence[_T], Generic[_T]): def __iadd__(self: _S, iterable: Iterable[_T]) -> _S: ... - if sys.version_info >= (3, 5): - def __add__(self, other: deque[_T]) -> deque[_T]: ... - def __mul__(self, other: int) -> deque[_T]: ... - def __imul__(self, other: int) -> None: ... - -_CounterT = TypeVar('_CounterT', bound=Counter) + def __add__(self, other: deque[_T]) -> deque[_T]: ... + def __mul__(self, other: int) -> deque[_T]: ... + def __imul__(self, other: int) -> None: ... class Counter(Dict[_T, int], Generic[_T]): @overload @@ -252,7 +249,7 @@ class Counter(Dict[_T, int], Generic[_T]): def __init__(self, mapping: Mapping[_T, int]) -> None: ... @overload def __init__(self, iterable: Iterable[_T]) -> None: ... - def copy(self: _CounterT) -> _CounterT: ... + def copy(self: _S) -> _S: ... def elements(self) -> Iterator[_T]: ... def most_common(self, n: Optional[int] = ...) -> List[Tuple[_T, int]]: ... @@ -285,8 +282,6 @@ class Counter(Dict[_T, int], Generic[_T]): def __iand__(self, other: Counter[_T]) -> Counter[_T]: ... def __ior__(self, other: Counter[_T]) -> Counter[_T]: ... -_OrderedDictT = TypeVar('_OrderedDictT', bound=OrderedDict) - class _OrderedDictKeysView(KeysView[_KT], Reversible[_KT]): def __reversed__(self) -> Iterator[_KT]: ... class _OrderedDictItemsView(ItemsView[_KT, _VT], Reversible[Tuple[_KT, _VT]]): @@ -297,14 +292,12 @@ class _OrderedDictValuesView(ValuesView[_VT], Reversible[_VT]): class OrderedDict(Dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]): def popitem(self, last: bool = ...) -> Tuple[_KT, _VT]: ... def move_to_end(self, key: _KT, last: bool = ...) -> None: ... - def copy(self: _OrderedDictT) -> _OrderedDictT: ... + def copy(self: _S) -> _S: ... def __reversed__(self) -> Iterator[_KT]: ... def keys(self) -> _OrderedDictKeysView[_KT]: ... def items(self) -> _OrderedDictItemsView[_KT, _VT]: ... def values(self) -> _OrderedDictValuesView[_VT]: ... -_DefaultDictT = TypeVar('_DefaultDictT', bound=defaultdict) - class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): default_factory: Optional[Callable[[], _VT]] @@ -328,7 +321,7 @@ class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... def __missing__(self, key: _KT) -> _VT: ... # TODO __reversed__ - def copy(self: _DefaultDictT) -> _DefaultDictT: ... + def copy(self: _S) -> _S: ... class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __init__(self, *maps: Mapping[_KT, _VT]) -> None: ... diff --git a/stdlib/3/collections/abc.pyi b/stdlib/3/collections/abc.pyi index a9577285ce81..11718438832b 100644 --- a/stdlib/3/collections/abc.pyi +++ b/stdlib/3/collections/abc.pyi @@ -4,7 +4,13 @@ import sys from . import ( + AsyncIterable as AsyncIterable, + AsyncIterator as AsyncIterator, + Awaitable as Awaitable, + ByteString as ByteString, Container as Container, + Coroutine as Coroutine, + Generator as Generator, Hashable as Hashable, Iterable as Iterable, Iterator as Iterator, @@ -22,16 +28,6 @@ from . import ( ValuesView as ValuesView, ) -if sys.version_info >= (3, 5): - from . import ( - Generator as Generator, - ByteString as ByteString, - Awaitable as Awaitable, - Coroutine as Coroutine, - AsyncIterable as AsyncIterable, - AsyncIterator as AsyncIterator, - ) - if sys.version_info >= (3, 6): from . import ( Collection as Collection, diff --git a/stdlib/3/compileall.pyi b/stdlib/3/compileall.pyi index 8d2731c05ed9..276cb5bef304 100644 --- a/stdlib/3/compileall.pyi +++ b/stdlib/3/compileall.pyi @@ -2,7 +2,7 @@ import os import sys -from typing import Optional, Union, Pattern +from typing import Any, Optional, Union, Pattern if sys.version_info < (3, 6): _Path = Union[str, bytes] @@ -12,9 +12,24 @@ else: _SuccessType = int # rx can be any object with a 'search' method; once we have Protocols we can change the type -if sys.version_info < (3, 5): - def compile_dir(dir: _Path, maxlevels: int = ..., ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern] = ..., quiet: int = ..., legacy: bool = ..., optimize: int = ...) -> _SuccessType: ... -else: - def compile_dir(dir: _Path, maxlevels: int = ..., ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern] = ..., quiet: int = ..., legacy: bool = ..., optimize: int = ..., workers: int = ...) -> _SuccessType: ... -def compile_file(fullname: _Path, ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern] = ..., quiet: int = ..., legacy: bool = ..., optimize: int = ...) -> _SuccessType: ... +def compile_dir( + dir: _Path, + maxlevels: int = ..., + ddir: Optional[_Path] = ..., + force: bool = ..., + rx: Optional[Pattern[Any]] = ..., + quiet: int = ..., + legacy: bool = ..., + optimize: int = ..., + workers: int = ..., +) -> _SuccessType: ... +def compile_file( + fullname: _Path, + ddir: Optional[_Path] = ..., + force: bool = ..., + rx: Optional[Pattern[Any]] = ..., + quiet: int = ..., + legacy: bool = ..., + optimize: int = ..., +) -> _SuccessType: ... def compile_path(skip_curdir: bool = ..., maxlevels: int = ..., force: bool = ..., quiet: int = ..., legacy: bool = ..., optimize: int = ...) -> _SuccessType: ... diff --git a/stdlib/3/concurrent/futures/_base.pyi b/stdlib/3/concurrent/futures/_base.pyi index 95189a741199..00ff41d76959 100644 --- a/stdlib/3/concurrent/futures/_base.pyi +++ b/stdlib/3/concurrent/futures/_base.pyi @@ -1,21 +1,26 @@ -from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set, NamedTuple +import threading +from logging import Logger +from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set, List from types import TracebackType import sys FIRST_COMPLETED: str FIRST_EXCEPTION: str ALL_COMPLETED: str -PENDING: Any -RUNNING: Any -CANCELLED: Any -CANCELLED_AND_NOTIFIED: Any -FINISHED: Any -LOGGER: Any +PENDING: str +RUNNING: str +CANCELLED: str +CANCELLED_AND_NOTIFIED: str +FINISHED: str +LOGGER: Logger class Error(Exception): ... class CancelledError(Error): ... class TimeoutError(Error): ... +if sys.version_info >= (3, 7): + class BrokenExecutor(RuntimeError): ... + _T = TypeVar('_T') class Future(Generic[_T]): @@ -48,9 +53,48 @@ class Executor: def map(self, func: Callable[..., _T], *iterables: Iterable[Any], timeout: Optional[float] = ...,) -> Iterator[_T]: ... def shutdown(self, wait: bool = ...) -> None: ... def __enter__(self: _T) -> _T: ... - def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: ... + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> Optional[bool]: ... def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> Iterator[Future[_T]]: ... def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Set[Future[_T]], Set[Future[_T]]]: ... + +class _Waiter: + event: threading.Event + finished_futures: List[Future[Any]] + def __init__(self) -> None: ... + def add_result(self, future: Future[Any]) -> None: ... + def add_exception(self, future: Future[Any]) -> None: ... + def add_cancelled(self, future: Future[Any]) -> None: ... + + +class _AsCompletedWaiter(_Waiter): + lock: threading.Lock + def __init__(self) -> None: ... + def add_result(self, future: Future[Any]) -> None: ... + def add_exception(self, future: Future[Any]) -> None: ... + def add_cancelled(self, future: Future[Any]) -> None: ... + + +class _FirstCompletedWaiter(_Waiter): + def add_result(self, future: Future[Any]) -> None: ... + def add_exception(self, future: Future[Any]) -> None: ... + def add_cancelled(self, future: Future[Any]) -> None: ... + + +class _AllCompletedWaiter(_Waiter): + num_pending_calls: int + stop_on_exception: bool + lock: threading.Lock + def __init__(self, num_pending_calls: int, stop_on_exception: bool) -> None: ... + def add_result(self, future: Future[Any]) -> None: ... + def add_exception(self, future: Future[Any]) -> None: ... + def add_cancelled(self, future: Future[Any]) -> None: ... + + +class _AcquireFutures: + futures: Iterable[Future[Any]] + def __init__(self, futures: Iterable[Future[Any]]) -> None: ... + def __enter__(self) -> None: ... + def __exit__(self, *args: Any) -> None: ... diff --git a/stdlib/3/concurrent/futures/process.pyi b/stdlib/3/concurrent/futures/process.pyi index ba0cd61a6170..ca22879c02fe 100644 --- a/stdlib/3/concurrent/futures/process.pyi +++ b/stdlib/3/concurrent/futures/process.pyi @@ -1,5 +1,5 @@ from typing import Any, Callable, Optional, Tuple -from ._base import Future, Executor +from ._base import Executor import sys EXTRA_QUEUED_CALLS: Any @@ -8,8 +8,11 @@ if sys.version_info >= (3,): class BrokenProcessPool(RuntimeError): ... if sys.version_info >= (3, 7): + from multiprocessing.context import BaseContext + class ProcessPoolExecutor(Executor): def __init__(self, max_workers: Optional[int] = ..., + mp_context: Optional[BaseContext] = ..., initializer: Optional[Callable[..., None]] = ..., initargs: Tuple[Any, ...] = ...) -> None: ... else: diff --git a/stdlib/3/concurrent/futures/thread.pyi b/stdlib/3/concurrent/futures/thread.pyi index 983594dc728f..82c8ddd03d94 100644 --- a/stdlib/3/concurrent/futures/thread.pyi +++ b/stdlib/3/concurrent/futures/thread.pyi @@ -1,7 +1,13 @@ -from typing import Any, Callable, Optional, Tuple +from typing import Any, Callable, Iterable, Mapping, Optional, Tuple, TypeVar, Generic from ._base import Executor, Future import sys +if sys.version_info >= (3, 7): + from ._base import BrokenExecutor + class BrokenThreadPool(BrokenExecutor): ... + +_S = TypeVar('_S') + class ThreadPoolExecutor(Executor): if sys.version_info >= (3, 7): def __init__(self, max_workers: Optional[int] = ..., @@ -13,3 +19,12 @@ class ThreadPoolExecutor(Executor): thread_name_prefix: str = ...) -> None: ... else: def __init__(self, max_workers: Optional[int] = ...) -> None: ... + + +class _WorkItem(Generic[_S]): + future: Future[_S] + fn: Callable[..., _S] + args: Iterable[Any] + kwargs: Mapping[str, Any] + def __init__(self, future: Future[_S], fn: Callable[..., _S], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ... + def run(self) -> None: ... diff --git a/stdlib/3/configparser.pyi b/stdlib/3/configparser.pyi index 17501c1e9e6c..8b87e06453b9 100644 --- a/stdlib/3/configparser.pyi +++ b/stdlib/3/configparser.pyi @@ -4,7 +4,7 @@ import sys from typing import (AbstractSet, MutableMapping, Mapping, Dict, Sequence, List, Union, Iterable, Iterator, Callable, Any, IO, overload, - Optional, Pattern, Type, TypeVar) + Optional, Pattern, Type, TypeVar, ClassVar) # Types only used in type comments only from typing import Optional, Tuple # noqa @@ -57,6 +57,7 @@ class LegacyInterpolation(Interpolation): ... class RawConfigParser(_parser): + BOOLEAN_STATES: ClassVar[Mapping[str, bool]] = ... # Undocumented def __init__(self, defaults: Optional[_section] = ..., dict_type: Type[Mapping[str, str]] = ..., @@ -176,7 +177,7 @@ class SectionProxy(MutableMapping[str, str]): def __getattr__(self, key: str) -> Callable[..., Any]: ... class ConverterMapping(MutableMapping[str, Optional[_converter]]): - GETTERCRE: Pattern + GETTERCRE: Pattern[Any] def __init__(self, parser: RawConfigParser) -> None: ... def __getitem__(self, key: str) -> _converter: ... def __setitem__(self, key: str, value: Optional[_converter]) -> None: ... diff --git a/stdlib/3/email/generator.pyi b/stdlib/3/email/generator.pyi index 81e733b7a960..2cf3942d390b 100644 --- a/stdlib/3/email/generator.pyi +++ b/stdlib/3/email/generator.pyi @@ -1,6 +1,6 @@ # Stubs for email.generator (Python 3.4) -from typing import TextIO, Optional +from typing import BinaryIO, TextIO, Optional from email.message import Message from email.policy import Policy @@ -14,9 +14,9 @@ class Generator: linesep: Optional[str] = ...) -> None: ... class BytesGenerator: - def clone(self, fp: TextIO) -> Generator: ... + def clone(self, fp: BinaryIO) -> BytesGenerator: ... def write(self, s: str) -> None: ... - def __init__(self, outfp: TextIO, mangle_from_: bool = ..., + def __init__(self, outfp: BinaryIO, mangle_from_: bool = ..., maxheaderlen: int = ..., *, policy: Policy = ...) -> None: ... def flatten(self, msg: Message, unixfrom: bool = ..., diff --git a/stdlib/3/email/message.pyi b/stdlib/3/email/message.pyi index 09fbdda7a38b..88aef3efef06 100644 --- a/stdlib/3/email/message.pyi +++ b/stdlib/3/email/message.pyi @@ -63,8 +63,7 @@ class Message: def get_content_charset(self, failobj: _T = ...) -> Union[_T, str]: ... def get_charsets(self, failobj: _T = ...) -> Union[_T, List[str]]: ... def walk(self) -> Generator[Message, None, None]: ... - if sys.version_info >= (3, 5): - def get_content_disposition(self) -> Optional[str]: ... + def get_content_disposition(self) -> Optional[str]: ... def as_string(self, unixfrom: bool = ..., maxheaderlen: int = ..., policy: Optional[Policy] = ...) -> str: ... def as_bytes(self, unixfrom: bool = ..., diff --git a/stdlib/3/email/policy.pyi b/stdlib/3/email/policy.pyi index e47e643f90af..581cf58913f5 100644 --- a/stdlib/3/email/policy.pyi +++ b/stdlib/3/email/policy.pyi @@ -13,8 +13,7 @@ class Policy: linesep: str cte_type: str raise_on_defect: bool - if sys.version_info >= (3, 5): - mange_from: bool + mange_from: bool def __init__(self, **kw: Any) -> None: ... def clone(self, **kw: Any) -> Policy: ... def handle_defect(self, obj: Message, diff --git a/stdlib/3/faulthandler.pyi b/stdlib/3/faulthandler.pyi index 1a87c9cf9e8c..736a4539c727 100644 --- a/stdlib/3/faulthandler.pyi +++ b/stdlib/3/faulthandler.pyi @@ -1,21 +1,15 @@ import sys from typing import Union, Protocol - class _HasFileno(Protocol): def fileno(self) -> int: ... - -if sys.version_info >= (3, 5): - _File = Union[_HasFileno, int] -else: - _File = _HasFileno - +_File = Union[_HasFileno, int] def cancel_dump_traceback_later() -> None: ... def disable() -> None: ... def dump_traceback(file: _File = ..., all_threads: bool = ...) -> None: ... -def dump_traceback_later(timeout: int, repeat: bool = ..., file: _File = ..., exit: bool = ...) -> None: ... +def dump_traceback_later(timeout: float, repeat: bool = ..., file: _File = ..., exit: bool = ...) -> None: ... def enable(file: _File = ..., all_threads: bool = ...) -> None: ... def is_enabled() -> bool: ... if sys.platform != "win32": diff --git a/stdlib/3/functools.pyi b/stdlib/3/functools.pyi index 409e84b3c466..ce89e7173154 100644 --- a/stdlib/3/functools.pyi +++ b/stdlib/3/functools.pyi @@ -4,10 +4,6 @@ from typing import Any, Callable, Generic, Dict, Iterable, Mapping, Optional, Se _AnyCallable = Callable[..., Any] _T = TypeVar("_T") -_T2 = TypeVar("_T2") -_T3 = TypeVar("_T3") -_T4 = TypeVar("_T4") -_T5 = TypeVar("_T5") _S = TypeVar("_S") @overload def reduce(function: Callable[[_T, _S], _T], @@ -44,75 +40,12 @@ def wraps(wrapped: _AnyCallable, assigned: Sequence[str] = ..., updated: Sequenc def total_ordering(cls: type) -> type: ... def cmp_to_key(mycmp: Callable[[_T, _T], int]) -> Callable[[_T], Any]: ... -@overload -def partial(__func: Callable[[_T], _S], __arg: _T) -> Callable[[], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2], _S], __arg: _T) -> Callable[[_T2], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3], _S], __arg: _T) -> Callable[[_T2, _T3], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4], _S], __arg: _T) -> Callable[[_T2, _T3, _T4], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4, _T5], _S], __arg: _T) -> Callable[[_T2, _T3, _T4, _T5], _S]: ... - -@overload -def partial(__func: Callable[[_T, _T2], _S], - __arg1: _T, - __arg2: _T2) -> Callable[[], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3], _S], - __arg1: _T, - __arg2: _T2) -> Callable[[_T3], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4], _S], - __arg1: _T, - __arg2: _T2) -> Callable[[_T3, _T4], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4, _T5], _S], - __arg1: _T, - __arg2: _T2) -> Callable[[_T3, _T4, _T5], _S]: ... - -@overload -def partial(__func: Callable[[_T, _T2, _T3], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3) -> Callable[[], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3) -> Callable[[_T4], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4, _T5], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3) -> Callable[[_T4, _T5], _S]: ... - -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3, - __arg4: _T4) -> Callable[[], _S]: ... -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4, _T5], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3, - __arg4: _T4) -> Callable[[_T5], _S]: ... - -@overload -def partial(__func: Callable[[_T, _T2, _T3, _T4, _T5], _S], - __arg1: _T, - __arg2: _T2, - __arg3: _T3, - __arg4: _T4, - __arg5: _T5) -> Callable[[], _S]: ... - -@overload -def partial(__func: Callable[..., _S], - *args: Any, - **kwargs: Any) -> Callable[..., _S]: ... +class partial(Generic[_T]): + func: Callable[..., _T] + args: Tuple[Any, ...] + keywords: Dict[str, Any] + def __init__(self, func: Callable[..., _T], *args: Any, **kwargs: Any) -> None: ... + def __call__(self, *args: Any, **kwargs: Any) -> _T: ... # With protocols, this could change into a generic protocol that defines __get__ and returns _T _Descriptor = Any diff --git a/stdlib/3/gettext.pyi b/stdlib/3/gettext.pyi index eeb9b09768f9..4b5398a46f20 100644 --- a/stdlib/3/gettext.pyi +++ b/stdlib/3/gettext.pyi @@ -1,9 +1,14 @@ -# Stubs for gettext (Python 3.4) +import sys +from typing import overload, Any, Container, IO, Iterable, Optional, Type, TypeVar -from typing import Any, IO, List, Optional, Union, Callable +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal class NullTranslations: def __init__(self, fp: IO[str] = ...) -> None: ... + def _parse(self, fp: IO[str]) -> None: ... def add_fallback(self, fallback: NullTranslations) -> None: ... def gettext(self, message: str) -> str: ... def lgettext(self, message: str) -> str: ... @@ -12,26 +17,33 @@ class NullTranslations: def info(self) -> Any: ... def charset(self) -> Any: ... def output_charset(self) -> Any: ... - def set_output_charset(self, charset: Any) -> None: ... - def install(self, names: List[str] = ...) -> None: ... + def set_output_charset(self, charset: str) -> None: ... + def install(self, names: Optional[Container[str]] = ...) -> None: ... class GNUTranslations(NullTranslations): LE_MAGIC: int BE_MAGIC: int -def find(domain: str, localedir: str = ..., languages: List[str] = ..., - all: bool = ...): ... - -def translation(domain: str, localedir: str = ..., languages: List[str] = ..., - class_: Callable[[IO[str]], NullTranslations] = ..., - fallback: bool = ..., codeset: Any = ...) -> NullTranslations: ... - -def install(domain: str, localedir: str = ..., codeset: Any = ..., - names: List[str] = ...): ... - -def textdomain(domain: str = ...) -> str: ... -def bindtextdomain(domain: str, localedir: str = ...) -> str: ... -def bind_textdomain_codeset(domain: str, codeset: str = ...) -> str: ... +def find(domain: str, localedir: Optional[str] = ..., languages: Optional[Iterable[str]] = ..., + all: bool = ...) -> Any: ... + +_T = TypeVar('_T') +@overload +def translation(domain: str, localedir: Optional[str] = ..., languages: Optional[Iterable[str]] = ..., + class_: None = ..., fallback: bool = ..., codeset: Optional[str] = ...) -> NullTranslations: ... +@overload +def translation(domain: str, localedir: Optional[str] = ..., languages: Optional[Iterable[str]] = ..., + class_: Type[_T] = ..., fallback: Literal[False] = ..., codeset: Optional[str] = ...) -> _T: ... +@overload +def translation(domain: str, localedir: Optional[str] = ..., languages: Optional[Iterable[str]] = ..., + class_: Type[_T] = ..., fallback: Literal[True] = ..., codeset: Optional[str] = ...) -> Any: ... + +def install(domain: str, localedir: Optional[str] = ..., codeset: Optional[str] = ..., + names: Optional[Container[str]] = ...) -> None: ... + +def textdomain(domain: Optional[str] = ...) -> str: ... +def bindtextdomain(domain: str, localedir: Optional[str] = ...) -> str: ... +def bind_textdomain_codeset(domain: str, codeset: Optional[str] = ...) -> str: ... def dgettext(domain: str, message: str) -> str: ... def ldgettext(domain: str, message: str) -> str: ... def dngettext(domain: str, singular: str, plural: str, n: int) -> str: ... diff --git a/stdlib/3/glob.pyi b/stdlib/3/glob.pyi index 22ee20569339..5e73a79712a1 100644 --- a/stdlib/3/glob.pyi +++ b/stdlib/3/glob.pyi @@ -11,12 +11,8 @@ else: def glob1(dirname: AnyStr, pattern: AnyStr) -> List[AnyStr]: ... -if sys.version_info >= (3, 5): - def glob(pathname: AnyStr, *, recursive: bool = ...) -> List[AnyStr]: ... - def iglob(pathname: AnyStr, *, recursive: bool = ...) -> Iterator[AnyStr]: ... -else: - def glob(pathname: AnyStr) -> List[AnyStr]: ... - def iglob(pathname: AnyStr) -> Iterator[AnyStr]: ... +def glob(pathname: AnyStr, *, recursive: bool = ...) -> List[AnyStr]: ... +def iglob(pathname: AnyStr, *, recursive: bool = ...) -> Iterator[AnyStr]: ... def escape(pathname: AnyStr) -> AnyStr: ... diff --git a/stdlib/3/heapq.pyi b/stdlib/3/heapq.pyi index 5c49dfac1e98..0764da5183a5 100644 --- a/stdlib/3/heapq.pyi +++ b/stdlib/3/heapq.pyi @@ -12,11 +12,7 @@ def heappop(heap: List[_T]) -> _T: ... def heappushpop(heap: List[_T], item: _T) -> _T: ... def heapify(x: List[_T]) -> None: ... def heapreplace(heap: List[_T], item: _T) -> _T: ... -if sys.version_info >= (3, 5): - def merge(*iterables: Iterable[_T], key: Callable[[_T], Any] = ..., - reverse: bool = ...) -> Iterable[_T]: ... -else: - def merge(*iterables: Iterable[_T]) -> Iterable[_T]: ... +def merge(*iterables: Iterable[_T], key: Callable[[_T], Any] = ..., reverse: bool = ...) -> Iterable[_T]: ... def nlargest(n: int, iterable: Iterable[_T], key: Optional[Callable[[_T], Any]] = ...) -> List[_T]: ... def nsmallest(n: int, iterable: Iterable[_T], diff --git a/stdlib/3/html/entities.pyi b/stdlib/3/html/entities.pyi index e8ce9f650bd7..97d9b2d320bc 100644 --- a/stdlib/3/html/entities.pyi +++ b/stdlib/3/html/entities.pyi @@ -1,6 +1,6 @@ -from typing import Any +from typing import Dict -name2codepoint: Any -html5: Any -codepoint2name: Any -entitydefs: Any +name2codepoint: Dict[str, int] +html5: Dict[str, str] +codepoint2name: Dict[int, str] +entitydefs: Dict[str, str] diff --git a/stdlib/3/html/parser.pyi b/stdlib/3/html/parser.pyi index 4b10331be99f..55b99ea3407f 100644 --- a/stdlib/3/html/parser.pyi +++ b/stdlib/3/html/parser.pyi @@ -3,16 +3,12 @@ from _markupbase import ParserBase import sys class HTMLParser(ParserBase): - if sys.version_info >= (3, 5): - def __init__(self, *, convert_charrefs: bool = ...) -> None: ... - else: - def __init__(self, strict: bool = ..., *, - convert_charrefs: bool = ...) -> None: ... + def __init__(self, *, convert_charrefs: bool = ...) -> None: ... def feed(self, feed: str) -> None: ... def close(self) -> None: ... def reset(self) -> None: ... def getpos(self) -> Tuple[int, int]: ... - def get_starttag_text(self) -> str: ... + def get_starttag_text(self) -> Optional[str]: ... def handle_starttag(self, tag: str, attrs: List[Tuple[str, Optional[str]]]) -> None: ... @@ -26,6 +22,3 @@ class HTMLParser(ParserBase): def handle_decl(self, decl: str) -> None: ... def handle_pi(self, data: str) -> None: ... def unknown_decl(self, data: str) -> None: ... - -if sys.version_info < (3, 5): - class HTMLParseError(Exception): ... diff --git a/stdlib/3/http/__init__.pyi b/stdlib/3/http/__init__.pyi index 580250b3c7e2..8e12f7997d76 100644 --- a/stdlib/3/http/__init__.pyi +++ b/stdlib/3/http/__init__.pyi @@ -1,69 +1,67 @@ import sys - from enum import IntEnum -if sys.version_info >= (3, 5): - class HTTPStatus(IntEnum): - - def __init__(self, *a) -> None: ... - - phrase: str - description: str - - CONTINUE = ... - SWITCHING_PROTOCOLS = ... - PROCESSING = ... - OK = ... - CREATED = ... - ACCEPTED = ... - NON_AUTHORITATIVE_INFORMATION = ... - NO_CONTENT = ... - RESET_CONTENT = ... - PARTIAL_CONTENT = ... - MULTI_STATUS = ... - ALREADY_REPORTED = ... - IM_USED = ... - MULTIPLE_CHOICES = ... - MOVED_PERMANENTLY = ... - FOUND = ... - SEE_OTHER = ... - NOT_MODIFIED = ... - USE_PROXY = ... - TEMPORARY_REDIRECT = ... - PERMANENT_REDIRECT = ... - BAD_REQUEST = ... - UNAUTHORIZED = ... - PAYMENT_REQUIRED = ... - FORBIDDEN = ... - NOT_FOUND = ... - METHOD_NOT_ALLOWED = ... - NOT_ACCEPTABLE = ... - PROXY_AUTHENTICATION_REQUIRED = ... - REQUEST_TIMEOUT = ... - CONFLICT = ... - GONE = ... - LENGTH_REQUIRED = ... - PRECONDITION_FAILED = ... - REQUEST_ENTITY_TOO_LARGE = ... - REQUEST_URI_TOO_LONG = ... - UNSUPPORTED_MEDIA_TYPE = ... - REQUESTED_RANGE_NOT_SATISFIABLE = ... - EXPECTATION_FAILED = ... - UNPROCESSABLE_ENTITY = ... - LOCKED = ... - FAILED_DEPENDENCY = ... - UPGRADE_REQUIRED = ... - PRECONDITION_REQUIRED = ... - TOO_MANY_REQUESTS = ... - REQUEST_HEADER_FIELDS_TOO_LARGE = ... - INTERNAL_SERVER_ERROR = ... - NOT_IMPLEMENTED = ... - BAD_GATEWAY = ... - SERVICE_UNAVAILABLE = ... - GATEWAY_TIMEOUT = ... - HTTP_VERSION_NOT_SUPPORTED = ... - VARIANT_ALSO_NEGOTIATES = ... - INSUFFICIENT_STORAGE = ... - LOOP_DETECTED = ... - NOT_EXTENDED = ... - NETWORK_AUTHENTICATION_REQUIRED = ... +class HTTPStatus(IntEnum): + @property + def phrase(self) -> str: ... + @property + def description(self) -> str: ... + CONTINUE: int + SWITCHING_PROTOCOLS: int + PROCESSING: int + OK: int + CREATED: int + ACCEPTED: int + NON_AUTHORITATIVE_INFORMATION: int + NO_CONTENT: int + RESET_CONTENT: int + PARTIAL_CONTENT: int + MULTI_STATUS: int + ALREADY_REPORTED: int + IM_USED: int + MULTIPLE_CHOICES: int + MOVED_PERMANENTLY: int + FOUND: int + SEE_OTHER: int + NOT_MODIFIED: int + USE_PROXY: int + TEMPORARY_REDIRECT: int + PERMANENT_REDIRECT: int + BAD_REQUEST: int + UNAUTHORIZED: int + PAYMENT_REQUIRED: int + FORBIDDEN: int + NOT_FOUND: int + METHOD_NOT_ALLOWED: int + NOT_ACCEPTABLE: int + PROXY_AUTHENTICATION_REQUIRED: int + REQUEST_TIMEOUT: int + CONFLICT: int + GONE: int + LENGTH_REQUIRED: int + PRECONDITION_FAILED: int + REQUEST_ENTITY_TOO_LARGE: int + REQUEST_URI_TOO_LONG: int + UNSUPPORTED_MEDIA_TYPE: int + REQUESTED_RANGE_NOT_SATISFIABLE: int + EXPECTATION_FAILED: int + UNPROCESSABLE_ENTITY: int + LOCKED: int + FAILED_DEPENDENCY: int + UPGRADE_REQUIRED: int + PRECONDITION_REQUIRED: int + TOO_MANY_REQUESTS: int + REQUEST_HEADER_FIELDS_TOO_LARGE: int + INTERNAL_SERVER_ERROR: int + NOT_IMPLEMENTED: int + BAD_GATEWAY: int + SERVICE_UNAVAILABLE: int + GATEWAY_TIMEOUT: int + HTTP_VERSION_NOT_SUPPORTED: int + VARIANT_ALSO_NEGOTIATES: int + INSUFFICIENT_STORAGE: int + LOOP_DETECTED: int + NOT_EXTENDED: int + NETWORK_AUTHENTICATION_REQUIRED: int + if sys.version_info >= (3, 7): + MISDIRECTED_REQUEST: int diff --git a/stdlib/3/http/client.pyi b/stdlib/3/http/client.pyi index 5528b0150865..ee57f16a8f29 100644 --- a/stdlib/3/http/client.pyi +++ b/stdlib/3/http/client.pyi @@ -80,90 +80,63 @@ responses: Dict[int, str] class HTTPMessage(email.message.Message): ... -if sys.version_info >= (3, 5): - # Ignore errors to work around python/mypy#5027 - class HTTPResponse(io.BufferedIOBase, BinaryIO): # type: ignore - msg: HTTPMessage - headers: HTTPMessage - version: int - debuglevel: int - closed: bool - status: int - reason: str - def __init__(self, sock: socket, debuglevel: int = ..., - method: Optional[str] = ..., url: Optional[str] = ...) -> None: ... - def read(self, amt: Optional[int] = ...) -> bytes: ... - @overload - def getheader(self, name: str) -> Optional[str]: ... - @overload - def getheader(self, name: str, default: _T) -> Union[str, _T]: ... - def getheaders(self) -> List[Tuple[str, str]]: ... - def fileno(self) -> int: ... - def isclosed(self) -> bool: ... - def __iter__(self) -> Iterator[bytes]: ... - def __enter__(self) -> HTTPResponse: ... - def __exit__(self, exc_type: Optional[Type[BaseException]], - exc_val: Optional[BaseException], - exc_tb: Optional[types.TracebackType]) -> bool: ... - def info(self) -> email.message.Message: ... - def geturl(self) -> str: ... - def getcode(self) -> int: ... - def begin(self) -> None: ... -else: - class HTTPResponse(io.RawIOBase, BinaryIO): # type: ignore - msg: HTTPMessage - headers: HTTPMessage - version: int - debuglevel: int - closed: bool - status: int - reason: str - def read(self, amt: Optional[int] = ...) -> bytes: ... - def readinto(self, b: bytearray) -> int: ... - @overload - def getheader(self, name: str) -> Optional[str]: ... - @overload - def getheader(self, name: str, default: _T) -> Union[str, _T]: ... - def getheaders(self) -> List[Tuple[str, str]]: ... - def fileno(self) -> int: ... - def __iter__(self) -> Iterator[bytes]: ... - def __enter__(self) -> HTTPResponse: ... - def __exit__(self, exc_type: Optional[Type[BaseException]], - exc_val: Optional[BaseException], - exc_tb: Optional[types.TracebackType]) -> bool: ... - def info(self) -> email.message.Message: ... - def geturl(self) -> str: ... - def getcode(self) -> int: ... - def begin(self) -> None: ... +class HTTPResponse(io.BufferedIOBase, BinaryIO): + msg: HTTPMessage + headers: HTTPMessage + version: int + debuglevel: int + closed: bool + status: int + reason: str + def __init__(self, sock: socket, debuglevel: int = ..., + method: Optional[str] = ..., url: Optional[str] = ...) -> None: ... + def read(self, amt: Optional[int] = ...) -> bytes: ... + @overload + def getheader(self, name: str) -> Optional[str]: ... + @overload + def getheader(self, name: str, default: _T) -> Union[str, _T]: ... + def getheaders(self) -> List[Tuple[str, str]]: ... + def fileno(self) -> int: ... + def isclosed(self) -> bool: ... + def __iter__(self) -> Iterator[bytes]: ... + def __enter__(self) -> HTTPResponse: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[types.TracebackType]) -> Optional[bool]: ... + def info(self) -> email.message.Message: ... + def geturl(self) -> str: ... + def getcode(self) -> int: ... + def begin(self) -> None: ... # This is an API stub only for the class below, not a class itself. # urllib.request uses it for a parameter. -class HTTPConnectionProtocol(Protocol): +class _HTTPConnectionProtocol(Protocol): if sys.version_info >= (3, 7): def __call__(self, host: str, port: Optional[int] = ..., - timeout: int = ..., + timeout: float = ..., source_address: Optional[Tuple[str, int]] = ..., blocksize: int = ...): ... else: def __call__(self, host: str, port: Optional[int] = ..., - timeout: int = ..., + timeout: float = ..., source_address: Optional[Tuple[str, int]] = ...): ... class HTTPConnection: - host: str = ... - port: int = ... + timeout: float + host: str + port: int if sys.version_info >= (3, 7): def __init__( self, host: str, port: Optional[int] = ..., - timeout: int = ..., + timeout: float = ..., source_address: Optional[Tuple[str, int]] = ..., blocksize: int = ... ) -> None: ... else: def __init__( self, host: str, port: Optional[int] = ..., - timeout: int = ..., + timeout: float = ..., source_address: Optional[Tuple[str, int]] = ... ) -> None: ... if sys.version_info >= (3, 6): @@ -181,7 +154,7 @@ class HTTPConnection: headers: Optional[Mapping[str, str]] = ...) -> None: ... def connect(self) -> None: ... def close(self) -> None: ... - def putrequest(self, request: str, selector: str, skip_host: bool = ..., + def putrequest(self, method: str, url: str, skip_host: bool = ..., skip_accept_encoding: bool = ...) -> None: ... def putheader(self, header: str, *argument: str) -> None: ... if sys.version_info >= (3, 6): @@ -196,7 +169,7 @@ class HTTPSConnection(HTTPConnection): host: str, port: Optional[int] = ..., key_file: Optional[str] = ..., cert_file: Optional[str] = ..., - timeout: int = ..., + timeout: float = ..., source_address: Optional[Tuple[str, int]] = ..., *, context: Optional[ssl.SSLContext] = ..., check_hostname: Optional[bool] = ...) -> None: ... @@ -219,5 +192,4 @@ class ResponseNotReady(ImproperConnectionState): ... class BadStatusLine(HTTPException): ... class LineTooLong(HTTPException): ... -if sys.version_info >= (3, 5): - class RemoteDisconnected(ConnectionResetError, BadStatusLine): ... +class RemoteDisconnected(ConnectionResetError, BadStatusLine): ... diff --git a/stdlib/3/http/cookiejar.pyi b/stdlib/3/http/cookiejar.pyi index 25701ea7341f..9e31fb994cd4 100644 --- a/stdlib/3/http/cookiejar.pyi +++ b/stdlib/3/http/cookiejar.pyi @@ -37,8 +37,9 @@ class FileCookieJar(CookieJar): ignore_expires: bool = ...) -> None: ... class MozillaCookieJar(FileCookieJar): ... -class LWPCookieJar(FileCookieJar): ... +class LWPCookieJar(FileCookieJar): + def as_lwp_str(self, ignore_discard: bool = ..., ignore_expires: bool = ...) -> str: ... # undocumented class CookiePolicy: netscape: bool diff --git a/stdlib/3/http/cookies.pyi b/stdlib/3/http/cookies.pyi index 5e5d58a00583..dfd6df88cba1 100644 --- a/stdlib/3/http/cookies.pyi +++ b/stdlib/3/http/cookies.pyi @@ -1,13 +1,13 @@ # Stubs for http.cookies (Python 3.5) -from typing import Generic, Dict, List, Mapping, MutableMapping, Optional, TypeVar, Union +from typing import Generic, Dict, List, Mapping, MutableMapping, Optional, TypeVar, Union, Any -_DataType = Union[str, Mapping[str, Union[str, Morsel]]] +_DataType = Union[str, Mapping[str, Union[str, Morsel[Any]]]] _T = TypeVar('_T') class CookieError(Exception): ... -class Morsel(Dict[str, str], Generic[_T]): +class Morsel(Dict[str, Any], Generic[_T]): value: str coded_value: _T key: str @@ -18,7 +18,7 @@ class Morsel(Dict[str, str], Generic[_T]): def js_output(self, attrs: Optional[List[str]] = ...) -> str: ... def OutputString(self, attrs: Optional[List[str]] = ...) -> str: ... -class BaseCookie(Dict[str, Morsel], Generic[_T]): +class BaseCookie(Dict[str, Morsel[_T]], Generic[_T]): def __init__(self, input: Optional[_DataType] = ...) -> None: ... def value_decode(self, val: str) -> _T: ... def value_encode(self, val: _T) -> str: ... @@ -26,6 +26,6 @@ class BaseCookie(Dict[str, Morsel], Generic[_T]): sep: str = ...) -> str: ... def js_output(self, attrs: Optional[List[str]] = ...) -> str: ... def load(self, rawdata: _DataType) -> None: ... - def __setitem__(self, key: str, value: Union[str, Morsel]) -> None: ... + def __setitem__(self, key: str, value: Union[str, Morsel[_T]]) -> None: ... -class SimpleCookie(BaseCookie): ... +class SimpleCookie(BaseCookie[_T], Generic[_T]): ... diff --git a/stdlib/3/http/server.pyi b/stdlib/3/http/server.pyi index 7a7729f87275..954c076a23d3 100644 --- a/stdlib/3/http/server.pyi +++ b/stdlib/3/http/server.pyi @@ -1,7 +1,7 @@ # Stubs for http.server (Python 3.4) import sys -from typing import Any, BinaryIO, Dict, List, Mapping, Optional, Tuple, Union +from typing import Any, BinaryIO, ClassVar, Dict, List, Mapping, Optional, Sequence, Tuple, Union import socketserver import email.message @@ -14,6 +14,10 @@ class HTTPServer(socketserver.TCPServer): def __init__(self, server_address: Tuple[str, int], RequestHandlerClass: type) -> None: ... +if sys.version_info >= (3, 7): + class ThreadingHTTPServer(socketserver.ThreadingMixIn, HTTPServer): + daemon_threads: bool # undocumented + class BaseHTTPRequestHandler: client_address: Tuple[str, int] server: socketserver.BaseServer @@ -32,6 +36,8 @@ class BaseHTTPRequestHandler: protocol_version: str MessageClass: type responses: Mapping[int, Tuple[str, str]] + weekdayname: ClassVar[Sequence[str]] = ... # Undocumented + monthname: ClassVar[Sequence[Optional[str]]] = ... # Undocumented def __init__(self, request: bytes, client_address: Tuple[str, int], server: socketserver.BaseServer) -> None: ... def handle(self) -> None: ... @@ -54,6 +60,7 @@ class BaseHTTPRequestHandler: def date_time_string(self, timestamp: Optional[int] = ...) -> str: ... def log_date_time_string(self) -> str: ... def address_string(self) -> str: ... + def parse_request(self) -> bool: ... # Undocumented class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): extensions_map: Dict[str, str] diff --git a/stdlib/3/imp.pyi b/stdlib/3/imp.pyi index 33440910a1c0..9ba615021548 100644 --- a/stdlib/3/imp.pyi +++ b/stdlib/3/imp.pyi @@ -9,8 +9,7 @@ from _imp import (lock_held as lock_held, acquire_lock as acquire_lock, release_ get_frozen_object as get_frozen_object, is_frozen_package as is_frozen_package, init_frozen as init_frozen, is_builtin as is_builtin, is_frozen as is_frozen) -if sys.version_info >= (3, 5): - from _imp import create_dynamic as create_dynamic +from _imp import create_dynamic as create_dynamic _T = TypeVar('_T') diff --git a/stdlib/3/importlib/abc.pyi b/stdlib/3/importlib/abc.pyi index a86e194dda56..709ba44f723b 100644 --- a/stdlib/3/importlib/abc.pyi +++ b/stdlib/3/importlib/abc.pyi @@ -32,13 +32,8 @@ class InspectLoader(Loader): @abstractmethod def get_source(self, fullname: str) -> Optional[str]: ... def exec_module(self, module: types.ModuleType) -> None: ... - if sys.version_info < (3, 5): - def source_to_code(self, data: Union[bytes, str], - path: str = ...) -> types.CodeType: ... - else: - @staticmethod - def source_to_code(data: Union[bytes, str], - path: str = ...) -> types.CodeType: ... + @staticmethod + def source_to_code(data: Union[bytes, str], path: str = ...) -> types.CodeType: ... class ExecutionLoader(InspectLoader): @abstractmethod diff --git a/stdlib/3/importlib/util.pyi b/stdlib/3/importlib/util.pyi index 706a5dd94027..878d0652ee81 100644 --- a/stdlib/3/importlib/util.pyi +++ b/stdlib/3/importlib/util.pyi @@ -2,7 +2,7 @@ import importlib.abc import importlib.machinery import sys import types -from typing import Any, Callable, List, Optional +from typing import Any, Callable, List, Optional, Union def module_for_loader( fxn: Callable[..., types.ModuleType] @@ -30,24 +30,24 @@ def spec_from_loader( origin: Optional[str] = ..., loader_state: Optional[Any] = ..., is_package: Optional[bool] = ... ) -> importlib.machinery.ModuleSpec: ... + +if sys.version_info >= (3, 6): + import os + _Path = Union[str, bytes, os.PathLike] +else: + _Path = str + def spec_from_file_location( - name: str, location: str, *, + name: str, location: _Path, *, loader: Optional[importlib.abc.Loader] = ..., submodule_search_locations: Optional[List[str]] = ... ) -> importlib.machinery.ModuleSpec: ... -if sys.version_info >= (3, 5): - def module_from_spec( - spec: importlib.machinery.ModuleSpec - ) -> types.ModuleType: ... - - class LazyLoader(importlib.abc.Loader): - def __init__(self, loader: importlib.abc.Loader) -> None: ... - @classmethod - def factory( - cls, loader: importlib.abc.Loader - ) -> Callable[..., LazyLoader]: ... - def create_module( - self, spec: importlib.machinery.ModuleSpec - ) -> Optional[types.ModuleType]: ... - def exec_module(self, module: types.ModuleType) -> None: ... +def module_from_spec(spec: importlib.machinery.ModuleSpec) -> types.ModuleType: ... + +class LazyLoader(importlib.abc.Loader): + def __init__(self, loader: importlib.abc.Loader) -> None: ... + @classmethod + def factory(cls, loader: importlib.abc.Loader) -> Callable[..., LazyLoader]: ... + def create_module(self, spec: importlib.machinery.ModuleSpec) -> Optional[types.ModuleType]: ... + def exec_module(self, module: types.ModuleType) -> None: ... diff --git a/stdlib/3/inspect.pyi b/stdlib/3/inspect.pyi index 61737158e0e4..099041551d94 100644 --- a/stdlib/3/inspect.pyi +++ b/stdlib/3/inspect.pyi @@ -1,8 +1,10 @@ import sys from typing import (AbstractSet, Any, Callable, Dict, Generator, List, Mapping, - NamedTuple, Optional, Sequence, Tuple, Union, + NamedTuple, Optional, Sequence, Tuple, Type, Union, ) -from types import CodeType, FrameType, ModuleType, TracebackType +from types import (CodeType, FrameType, FunctionType, MethodType, ModuleType, + TracebackType, + ) from collections import OrderedDict # @@ -28,9 +30,8 @@ CO_VARKEYWORDS: int CO_NESTED: int CO_GENERATOR: int CO_NOFREE: int -if sys.version_info >= (3, 5): - CO_COROUTINE: int - CO_ITERABLE_COROUTINE: int +CO_COROUTINE: int +CO_ITERABLE_COROUTINE: int if sys.version_info >= (3, 6): CO_ASYNC_GENERATOR: int TPFLAGS_IS_ABSTRACT: int @@ -55,10 +56,9 @@ def isfunction(object: object) -> bool: ... def isgeneratorfunction(object: object) -> bool: ... def isgenerator(object: object) -> bool: ... -if sys.version_info >= (3, 5): - def iscoroutinefunction(object: object) -> bool: ... - def iscoroutine(object: object) -> bool: ... - def isawaitable(object: object) -> bool: ... +def iscoroutinefunction(object: object) -> bool: ... +def iscoroutine(object: object) -> bool: ... +def isawaitable(object: object) -> bool: ... if sys.version_info >= (3, 6): def isasyncgenfunction(object: object) -> bool: ... def isasyncgen(object: object) -> bool: ... @@ -77,20 +77,18 @@ def ismemberdescriptor(object: object) -> bool: ... # # Retrieving source code # -def findsource(object: object) -> Tuple[List[str], int]: ... -def getabsfile(object: object) -> str: ... +_SourceObjectType = Union[ModuleType, Type[Any], MethodType, FunctionType, TracebackType, FrameType, CodeType, Callable[..., Any]] + +def findsource(object: _SourceObjectType) -> Tuple[List[str], int]: ... +def getabsfile(object: _SourceObjectType) -> str: ... def getblock(lines: Sequence[str]) -> Sequence[str]: ... -def getdoc(object: object) -> str: ... -def getcomments(object: object) -> str: ... -def getfile(object: object) -> str: ... -def getmodule(object: object) -> ModuleType: ... -def getsourcefile(object: object) -> str: ... -# TODO restrict to "module, class, method, function, traceback, frame, -# or code object" -def getsourcelines(object: object) -> Tuple[List[str], int]: ... -# TODO restrict to "a module, class, method, function, traceback, frame, -# or code object" -def getsource(object: object) -> str: ... +def getdoc(object: object) -> Optional[str]: ... +def getcomments(object: object) -> Optional[str]: ... +def getfile(object: _SourceObjectType) -> str: ... +def getmodule(object: object) -> Optional[ModuleType]: ... +def getsourcefile(object: _SourceObjectType) -> Optional[str]: ... +def getsourcelines(object: _SourceObjectType) -> Tuple[List[str], int]: ... +def getsource(object: _SourceObjectType) -> str: ... def cleandoc(doc: str) -> str: ... def indentsize(line: str) -> int: ... @@ -122,12 +120,8 @@ class Signature: parameters: Optional[Sequence[Parameter]] = ..., return_annotation: Any = ...) -> Signature: ... - if sys.version_info >= (3, 5): - @classmethod - def from_callable(cls, - obj: Callable[..., Any], - *, - follow_wrapped: bool = ...) -> Signature: ... + @classmethod + def from_callable(cls, obj: Callable[..., Any], *, follow_wrapped: bool = ...) -> Signature: ... # The name is the same as the enum's name in CPython class _ParameterKind: ... @@ -164,8 +158,7 @@ class BoundArguments: kwargs: Dict[str, Any] signature: Signature - if sys.version_info >= (3, 5): - def apply_defaults(self) -> None: ... + def apply_defaults(self) -> None: ... # @@ -180,7 +173,7 @@ def getclasstree(classes: List[type], unique: bool = ...) -> Any: ... ArgSpec = NamedTuple('ArgSpec', [('args', List[str]), ('varargs', str), ('keywords', str), - ('defaults', tuple), + ('defaults', Tuple[Any, ...]), ]) Arguments = NamedTuple('Arguments', [('args', List[str]), @@ -194,7 +187,7 @@ def getargspec(func: object) -> ArgSpec: ... FullArgSpec = NamedTuple('FullArgSpec', [('args', List[str]), ('varargs', Optional[str]), ('varkw', Optional[str]), - ('defaults', tuple), + ('defaults', Tuple[Any, ...]), ('kwonlyargs', List[str]), ('kwonlydefaults', Dict[str, Any]), ('annotations', Dict[str, Any]), @@ -264,8 +257,8 @@ Traceback = NamedTuple( ('filename', str), ('lineno', int), ('function', str), - ('code_context', List[str]), - ('index', int), + ('code_context', Optional[List[str]]), + ('index', Optional[int]), ] ) @@ -274,8 +267,8 @@ FrameInfo = NamedTuple('FrameInfo', [('frame', FrameType), ('filename', str), ('lineno', int), ('function', str), - ('code_context', List[str]), - ('index', int), + ('code_context', Optional[List[str]]), + ('index', Optional[int]), ]) def getframeinfo(frame: Union[FrameType, TracebackType], context: int = ...) -> Traceback: ... @@ -306,19 +299,17 @@ GEN_SUSPENDED: str GEN_CLOSED: str def getgeneratorstate(generator: Generator[Any, Any, Any]) -> str: ... -if sys.version_info >= (3, 5): - CORO_CREATED: str - CORO_RUNNING: str - CORO_SUSPENDED: str - CORO_CLOSED: str - # TODO can we be more specific than "object"? - def getcoroutinestate(coroutine: object) -> str: ... +CORO_CREATED: str +CORO_RUNNING: str +CORO_SUSPENDED: str +CORO_CLOSED: str +# TODO can we be more specific than "object"? +def getcoroutinestate(coroutine: object) -> str: ... def getgeneratorlocals(generator: Generator[Any, Any, Any]) -> Dict[str, Any]: ... -if sys.version_info >= (3, 5): - # TODO can we be more specific than "object"? - def getcoroutinelocals(coroutine: object) -> Dict[str, Any]: ... +# TODO can we be more specific than "object"? +def getcoroutinelocals(coroutine: object) -> Dict[str, Any]: ... Attribute = NamedTuple('Attribute', [('name', str), ('kind', str), diff --git a/stdlib/3/io.pyi b/stdlib/3/io.pyi index 903fab2f6f93..351d5be86d2c 100644 --- a/stdlib/3/io.pyi +++ b/stdlib/3/io.pyi @@ -16,7 +16,7 @@ SEEK_SET: int SEEK_CUR: int SEEK_END: int -_T = TypeVar('_T', bound='IOBase') +_T = TypeVar('_T', bound=IOBase) open = builtins.open @@ -28,7 +28,7 @@ class IOBase: def __next__(self) -> bytes: ... def __enter__(self: _T) -> _T: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... + exc_tb: Optional[TracebackType]) -> Optional[bool]: ... def close(self) -> None: ... def fileno(self) -> int: ... def flush(self) -> None: ... @@ -45,6 +45,7 @@ class IOBase: def __del__(self) -> None: ... @property def closed(self) -> bool: ... + def _checkClosed(self, msg: Optional[str] = ...) -> None: ... # undocumented class RawIOBase(IOBase): def readall(self) -> bytes: ... @@ -56,8 +57,7 @@ class BufferedIOBase(IOBase): def detach(self) -> RawIOBase: ... def readinto(self, b: _bytearray_like) -> int: ... def write(self, b: Union[bytes, bytearray]) -> int: ... - if sys.version_info >= (3, 5): - def readinto1(self, b: _bytearray_like) -> int: ... + def readinto1(self, b: _bytearray_like) -> int: ... def read(self, size: Optional[int] = ...) -> bytes: ... def read1(self, size: int = ...) -> bytes: ... @@ -87,7 +87,7 @@ class BytesIO(BinaryIO): def __next__(self) -> bytes: ... def __enter__(self) -> BytesIO: ... def __exit__(self, t: Optional[Type[BaseException]] = ..., value: Optional[BaseException] = ..., - traceback: Optional[TracebackType] = ...) -> bool: ... + traceback: Optional[TracebackType] = ...) -> Optional[bool]: ... def close(self) -> None: ... def fileno(self) -> int: ... def flush(self) -> None: ... @@ -109,8 +109,7 @@ class BytesIO(BinaryIO): def detach(self) -> RawIOBase: ... def readinto(self, b: _bytearray_like) -> int: ... def write(self, b: Union[bytes, bytearray]) -> int: ... - if sys.version_info >= (3, 5): - def readinto1(self, b: _bytearray_like) -> int: ... + def readinto1(self, b: _bytearray_like) -> int: ... def read(self, size: Optional[int] = ...) -> bytes: ... def read1(self, size: int = ...) -> bytes: ... @@ -159,7 +158,7 @@ class TextIOWrapper(TextIO): def __init__( self, buffer: IO[bytes], - encoding: str = ..., + encoding: Optional[str] = ..., errors: Optional[str] = ..., newline: Optional[str] = ..., line_buffering: bool = ..., @@ -167,7 +166,7 @@ class TextIOWrapper(TextIO): ) -> None: ... # copied from IOBase def __exit__(self, t: Optional[Type[BaseException]] = ..., value: Optional[BaseException] = ..., - traceback: Optional[TracebackType] = ...) -> bool: ... + traceback: Optional[TracebackType] = ...) -> Optional[bool]: ... def close(self) -> None: ... def fileno(self) -> int: ... def flush(self) -> None: ... @@ -207,4 +206,6 @@ class StringIO(TextIOWrapper): def __enter__(self) -> StringIO: ... class IncrementalNewlineDecoder(codecs.IncrementalDecoder): - def decode(self, input: bytes, final: bool = ...) -> str: ... + def __init__(self, decoder: Optional[codecs.IncrementalDecoder], + translate: bool, errors: str = ...) -> None: ... + def decode(self, input: Union[bytes, str], final: bool = ...) -> str: ... diff --git a/stdlib/3/ipaddress.pyi b/stdlib/3/ipaddress.pyi index f706330b6426..3d507f41b911 100644 --- a/stdlib/3/ipaddress.pyi +++ b/stdlib/3/ipaddress.pyi @@ -1,4 +1,3 @@ -import sys from typing import (Any, Container, Generic, Iterable, Iterator, Optional, overload, SupportsInt, Tuple, TypeVar) @@ -25,9 +24,8 @@ class _IPAddressBase: def compressed(self) -> str: ... @property def exploded(self) -> str: ... - if sys.version_info >= (3, 5): - @property - def reverse_pointer(self) -> str: ... + @property + def reverse_pointer(self) -> str: ... @property def version(self) -> int: ... @@ -56,7 +54,7 @@ class _BaseAddress(_IPAddressBase, SupportsInt): @property def packed(self) -> bytes: ... -class _BaseNetwork(_IPAddressBase, Container, Iterable[_A], Generic[_A]): +class _BaseNetwork(_IPAddressBase, Container[_A], Iterable[_A], Generic[_A]): network_address: _A netmask: _A def __init__(self, address: object, strict: bool = ...) -> None: ... diff --git a/stdlib/3/json/__init__.pyi b/stdlib/3/json/__init__.pyi index 620b239b46c8..2f6374e3ba6a 100644 --- a/stdlib/3/json/__init__.pyi +++ b/stdlib/3/json/__init__.pyi @@ -1,17 +1,16 @@ import sys -from typing import Any, IO, Optional, Tuple, Callable, Dict, List, Union, Protocol +from typing import Any, IO, Optional, Tuple, Callable, Dict, List, Union, Protocol, Type from .decoder import JSONDecoder as JSONDecoder from .encoder import JSONEncoder as JSONEncoder -if sys.version_info >= (3, 5): - from .decoder import JSONDecodeError as JSONDecodeError +from .decoder import JSONDecodeError as JSONDecodeError def dumps(obj: Any, skipkeys: bool = ..., ensure_ascii: bool = ..., check_circular: bool = ..., allow_nan: bool = ..., - cls: Any = ..., + cls: Optional[Type[JSONEncoder]] = ..., indent: Union[None, int, str] = ..., separators: Optional[Tuple[str, str]] = ..., default: Optional[Callable[[Any], Any]] = ..., @@ -24,7 +23,7 @@ def dump(obj: Any, ensure_ascii: bool = ..., check_circular: bool = ..., allow_nan: bool = ..., - cls: Any = ..., + cls: Optional[Type[JSONEncoder]] = ..., indent: Union[None, int, str] = ..., separators: Optional[Tuple[str, str]] = ..., default: Optional[Callable[[Any], Any]] = ..., @@ -37,8 +36,8 @@ else: _LoadsString = str def loads(s: _LoadsString, encoding: Any = ..., # ignored and deprecated - cls: Any = ..., - object_hook: Optional[Callable[[Dict], Any]] = ..., + cls: Optional[Type[JSONDecoder]] = ..., + object_hook: Optional[Callable[[Dict[Any, Any]], Any]] = ..., parse_float: Optional[Callable[[str], Any]] = ..., parse_int: Optional[Callable[[str], Any]] = ..., parse_constant: Optional[Callable[[str], Any]] = ..., @@ -49,8 +48,8 @@ class _Reader(Protocol): def read(self) -> _LoadsString: ... def load(fp: _Reader, - cls: Any = ..., - object_hook: Optional[Callable[[Dict], Any]] = ..., + cls: Optional[Type[JSONDecoder]] = ..., + object_hook: Optional[Callable[[Dict[Any, Any]], Any]] = ..., parse_float: Optional[Callable[[str], Any]] = ..., parse_int: Optional[Callable[[str], Any]] = ..., parse_constant: Optional[Callable[[str], Any]] = ..., diff --git a/stdlib/3/json/decoder.pyi b/stdlib/3/json/decoder.pyi index 8e30c1e73359..1acb84af8b0e 100644 --- a/stdlib/3/json/decoder.pyi +++ b/stdlib/3/json/decoder.pyi @@ -1,14 +1,13 @@ import sys from typing import Any, Callable, Dict, List, Optional, Tuple -if sys.version_info >= (3, 5): - class JSONDecodeError(ValueError): - msg: str - doc: str - pos: int - lineno: int - colno: int - def __init__(self, msg: str, doc: str, pos: int) -> None: ... +class JSONDecodeError(ValueError): + msg: str + doc: str + pos: int + lineno: int + colno: int + def __init__(self, msg: str, doc: str, pos: int) -> None: ... class JSONDecoder: object_hook: Callable[[Dict[str, Any]], Any] diff --git a/stdlib/3/json/encoder.pyi b/stdlib/3/json/encoder.pyi index e35f344b2f40..63f5ffebe7df 100644 --- a/stdlib/3/json/encoder.pyi +++ b/stdlib/3/json/encoder.pyi @@ -14,7 +14,7 @@ class JSONEncoder: def __init__(self, skipkeys: bool = ..., ensure_ascii: bool = ..., check_circular: bool = ..., allow_nan: bool = ..., sort_keys: bool = ..., indent: Optional[int] = ..., separators: Optional[Tuple[str, str]] = ..., - default: Optional[Callable] = ...) -> None: ... + default: Optional[Callable[..., Any]] = ...) -> None: ... def default(self, o: Any) -> Any: ... def encode(self, o: Any) -> str: ... diff --git a/stdlib/3/lzma.pyi b/stdlib/3/lzma.pyi index cd0a088b442b..37009c813cee 100644 --- a/stdlib/3/lzma.pyi +++ b/stdlib/3/lzma.pyi @@ -49,9 +49,8 @@ class LZMADecompressor(object): def eof(self) -> bool: ... @property def unused_data(self) -> bytes: ... - if sys.version_info >= (3, 5): - @property - def needs_input(self) -> bool: ... + @property + def needs_input(self) -> bool: ... # from _lzma.c class LZMACompressor(object): diff --git a/stdlib/3/multiprocessing/__init__.pyi b/stdlib/3/multiprocessing/__init__.pyi index e5fad0a5afc9..e2513f3bd75e 100644 --- a/stdlib/3/multiprocessing/__init__.pyi +++ b/stdlib/3/multiprocessing/__init__.pyi @@ -2,9 +2,10 @@ from typing import ( Any, Callable, ContextManager, Iterable, Mapping, Optional, Dict, List, - Union, Sequence, Tuple + Union, Sequence, Tuple, Type, overload ) +from ctypes import _CData from logging import Logger from multiprocessing import connection, pool, spawn, synchronize from multiprocessing.context import ( @@ -25,7 +26,7 @@ import sys # Sychronization primitives _LockLike = Union[synchronize.Lock, synchronize.RLock] def Barrier(parties: int, - action: Optional[Callable] = ..., + action: Optional[Callable[..., Any]] = ..., timeout: Optional[float] = ...) -> synchronize.Barrier: ... def BoundedSemaphore(value: int = ...) -> synchronize.BoundedSemaphore: ... def Condition(lock: Optional[_LockLike] = ...) -> synchronize.Condition: ... @@ -51,7 +52,7 @@ class Process(): # TODO: set type of group to None def __init__(self, group: Any = ..., - target: Optional[Callable] = ..., + target: Optional[Callable[..., Any]] = ..., name: Optional[str] = ..., args: Iterable[Any] = ..., kwargs: Mapping[Any, Any] = ..., @@ -66,10 +67,30 @@ class Process(): def is_alive(self) -> bool: ... def join(self, timeout: Optional[float] = ...) -> None: ... +class Array(): + value: Any = ... + + def __init__(self, typecode_or_type: Union[str, Type[_CData]], size_or_initializer: Union[int, Sequence[Any]], *, lock: Union[bool, _LockLike] = ...) -> None: ... + def acquire(self) -> bool: ... + def release(self) -> bool: ... + def get_lock(self) -> _LockLike: ... + def get_obj(self) -> Any: ... + + @overload + def __getitem__(self, key: int) -> Any: ... + @overload + def __getitem__(self, key: slice) -> List[Any]: ... + def __getslice__(self, start: int, stop: int) -> Any: ... + def __setitem__(self, key: int, value: Any) -> None: ... + + class Value(): value: Any = ... - def __init__(self, typecode_or_type: str, *args: Any, lock: Union[bool, _LockLike] = ...) -> None: ... + def __init__(self, typecode_or_type: Union[str, Type[_CData]], *args: Any, lock: Union[bool, _LockLike] = ...) -> None: ... def get_lock(self) -> _LockLike: ... + def get_obj(self) -> Any: ... + def acquire(self) -> bool: ... + def release(self) -> bool: ... # ----- multiprocessing function stubs ----- def active_children() -> List[Process]: ... diff --git a/stdlib/3/multiprocessing/context.pyi b/stdlib/3/multiprocessing/context.pyi index dada9b3ea93a..2cdeb07d14cc 100644 --- a/stdlib/3/multiprocessing/context.pyi +++ b/stdlib/3/multiprocessing/context.pyi @@ -41,7 +41,7 @@ class BaseContext(object): def Barrier(self, parties: int, - action: Optional[Callable] = ..., + action: Optional[Callable[..., Any]] = ..., timeout: Optional[float] = ...) -> synchronize.Barrier: ... def BoundedSemaphore(self, value: int = ...) -> synchronize.BoundedSemaphore: ... @@ -52,9 +52,9 @@ class BaseContext(object): def RLock(self) -> synchronize.RLock: ... def Semaphore(self, value: int = ...) -> synchronize.Semaphore: ... - def Queue(self, maxsize: int = ...) -> queues.Queue: ... - def JoinableQueue(self, maxsize: int = ...) -> queues.JoinableQueue: ... - def SimpleQueue(self) -> queues.SimpleQueue: ... + def Queue(self, maxsize: int = ...) -> queues.Queue[Any]: ... + def JoinableQueue(self, maxsize: int = ...) -> queues.JoinableQueue[Any]: ... + def SimpleQueue(self) -> queues.SimpleQueue[Any]: ... def Pool( self, processes: Optional[int] = ..., @@ -65,7 +65,7 @@ class BaseContext(object): def Process( self, group: Any = ..., - target: Optional[Callable] = ..., + target: Optional[Callable[..., Any]] = ..., name: Optional[str] = ..., args: Iterable[Any] = ..., kwargs: Mapping[Any, Any] = ..., diff --git a/stdlib/3/multiprocessing/dummy/__init__.pyi b/stdlib/3/multiprocessing/dummy/__init__.pyi index c169d2d0e853..2a995cda633a 100644 --- a/stdlib/3/multiprocessing/dummy/__init__.pyi +++ b/stdlib/3/multiprocessing/dummy/__init__.pyi @@ -14,7 +14,7 @@ JoinableQueue = Queue class DummyProcess(threading.Thread): - _children: weakref.WeakKeyDictionary + _children: weakref.WeakKeyDictionary[Any, Any] _parent: threading.Thread _pid: None _start_called: int @@ -33,10 +33,10 @@ class Value(object): def __init__(self, typecode, value, lock=...) -> None: ... -def Array(typecode, sequence, lock=...) -> array.array: ... +def Array(typecode, sequence, lock=...) -> array.array[Any]: ... def Manager() -> Any: ... def Pool(processes=..., initializer=..., initargs=...) -> Any: ... -def active_children() -> List: ... +def active_children() -> List[Any]: ... def current_process() -> threading.Thread: ... def freeze_support() -> None: ... def shutdown() -> None: ... diff --git a/stdlib/3/multiprocessing/dummy/connection.pyi b/stdlib/3/multiprocessing/dummy/connection.pyi index 3baaf286f24a..537750e19f3b 100644 --- a/stdlib/3/multiprocessing/dummy/connection.pyi +++ b/stdlib/3/multiprocessing/dummy/connection.pyi @@ -21,9 +21,9 @@ class Connection(object): def poll(self, timeout: float = ...) -> bool: ... class Listener(object): - _backlog_queue: Optional[Queue] + _backlog_queue: Optional[Queue[Any]] @property - def address(self) -> Optional[Queue]: ... + def address(self) -> Optional[Queue[Any]]: ... def __enter__(self: _TListener) -> _TListener: ... def __exit__(self, exc_type, exc_value, exc_tb) -> None: ... def __init__(self, address=..., family=..., backlog=...) -> None: ... diff --git a/stdlib/3/multiprocessing/managers.pyi b/stdlib/3/multiprocessing/managers.pyi index a5ec399d74cc..7522d0ae437f 100644 --- a/stdlib/3/multiprocessing/managers.pyi +++ b/stdlib/3/multiprocessing/managers.pyi @@ -5,7 +5,7 @@ import queue import threading from typing import ( - Any, Callable, ContextManager, Dict, Iterable, List, Mapping, Optional, + Any, Callable, ContextManager, Dict, Iterable, Generic, List, Mapping, Optional, Sequence, Tuple, TypeVar, Union, ) @@ -17,11 +17,18 @@ class Namespace: ... _Namespace = Namespace +class BaseProxy: ... + +class ValueProxy(BaseProxy, Generic[_T]): + def get(self) -> _T: ... + def set(self, value: _T) -> None: ... + value: _T + class BaseManager(ContextManager[BaseManager]): address: Union[str, Tuple[str, int]] def connect(self) -> None: ... @classmethod - def register(cls, typeid: str, callable: Optional[Callable] = ..., + def register(cls, typeid: str, callable: Optional[Callable[..., Any]] = ..., proxytype: Any = ..., exposed: Optional[Sequence[str]] = ..., method_to_typeid: Optional[Mapping[str, str]] = ..., @@ -30,17 +37,17 @@ class BaseManager(ContextManager[BaseManager]): def start(self, initializer: Optional[Callable[..., Any]] = ..., initargs: Iterable[Any] = ...) -> None: ... -class SyncManager(BaseManager): +class SyncManager(BaseManager, ContextManager[SyncManager]): def BoundedSemaphore(self, value: Any = ...) -> threading.BoundedSemaphore: ... def Condition(self, lock: Any = ...) -> threading.Condition: ... def Event(self) -> threading.Event: ... def Lock(self) -> threading.Lock: ... def Namespace(self) -> _Namespace: ... - def Queue(self, maxsize: int = ...) -> queue.Queue: ... + def Queue(self, maxsize: int = ...) -> queue.Queue[Any]: ... def RLock(self) -> threading.RLock: ... def Semaphore(self, value: Any = ...) -> threading.Semaphore: ... def Array(self, typecode: Any, sequence: Sequence[_T]) -> Sequence[_T]: ... - def Value(self, typecode: Any, value: _T) -> _T: ... + def Value(self, typecode: Any, value: _T) -> ValueProxy[_T]: ... def dict(self, sequence: Mapping[_KT, _VT] = ...) -> Dict[_KT, _VT]: ... def list(self, sequence: Sequence[_T] = ...) -> List[_T]: ... diff --git a/stdlib/3/multiprocessing/pool.pyi b/stdlib/3/multiprocessing/pool.pyi index 469d83ad301a..3782a3f1dc4b 100644 --- a/stdlib/3/multiprocessing/pool.pyi +++ b/stdlib/3/multiprocessing/pool.pyi @@ -4,7 +4,7 @@ from typing import ( ) from types import TracebackType -_PT = TypeVar('_PT', bound='Pool') +_PT = TypeVar('_PT', bound=Pool) _S = TypeVar('_S') _T = TypeVar('_T') @@ -17,14 +17,14 @@ class ApplyResult(Generic[_T]): # alias created during issue #17805 AsyncResult = ApplyResult -_IMIT = TypeVar('_IMIT', bound=IMapIterator) +class MapResult(ApplyResult[List[_T]]): ... class IMapIterator(Iterator[_T]): - def __iter__(self: _IMIT) -> _IMIT: ... + def __iter__(self: _S) -> _S: ... def next(self, timeout: Optional[float] = ...) -> _T: ... def __next__(self, timeout: Optional[float] = ...) -> _T: ... -class IMapUnorderedIterator(IMapIterator): ... +class IMapUnorderedIterator(IMapIterator[_T]): ... class Pool(ContextManager[Pool]): def __init__(self, processes: Optional[int] = ..., @@ -50,7 +50,7 @@ class Pool(ContextManager[Pool]): iterable: Iterable[_S] = ..., chunksize: Optional[int] = ..., callback: Optional[Callable[[_T], None]] = ..., - error_callback: Optional[Callable[[BaseException], None]] = ...) -> AsyncResult[List[_T]]: ... + error_callback: Optional[Callable[[BaseException], None]] = ...) -> MapResult[List[_T]]: ... def imap(self, func: Callable[[_S], _T], iterable: Iterable[_S] = ..., diff --git a/stdlib/3/multiprocessing/synchronize.pyi b/stdlib/3/multiprocessing/synchronize.pyi index 9b226810e628..224485b317ba 100644 --- a/stdlib/3/multiprocessing/synchronize.pyi +++ b/stdlib/3/multiprocessing/synchronize.pyi @@ -1,4 +1,4 @@ -from typing import Callable, ContextManager, Optional, Union +from typing import Any, Callable, ContextManager, Optional, Union from multiprocessing.context import BaseContext import threading @@ -9,7 +9,7 @@ _LockLike = Union[Lock, RLock] class Barrier(threading.Barrier): def __init__(self, parties: int, - action: Optional[Callable] = ..., + action: Optional[Callable[..., Any]] = ..., timeout: Optional[float] = ..., * ctx: BaseContext) -> None: ... diff --git a/stdlib/3/os/__init__.pyi b/stdlib/3/os/__init__.pyi index b71792687e56..085000a0922f 100644 --- a/stdlib/3/os/__init__.pyi +++ b/stdlib/3/os/__init__.pyi @@ -2,6 +2,7 @@ # Ron Murawski from io import TextIOWrapper as _TextIOWrapper +from posix import listdir as listdir, times_result import sys from typing import ( Mapping, MutableMapping, Dict, List, Any, Tuple, IO, Iterable, Iterator, NoReturn, overload, Union, AnyStr, @@ -16,75 +17,72 @@ _T = TypeVar('_T') # ----- os variables ----- -if sys.version_info >= (3, 2): - supports_bytes_environ: bool - -if sys.version_info >= (3, 3): - supports_dir_fd: Set[Callable[..., Any]] - supports_fd: Set[Callable[..., Any]] - supports_effective_ids: Set[Callable[..., Any]] - supports_follow_symlinks: Set[Callable[..., Any]] - - if sys.platform != 'win32': - # Unix only - PRIO_PROCESS: int - PRIO_PGRP: int - PRIO_USER: int - - F_LOCK: int - F_TLOCK: int - F_ULOCK: int - F_TEST: int - - POSIX_FADV_NORMAL: int - POSIX_FADV_SEQUENTIAL: int - POSIX_FADV_RANDOM: int - POSIX_FADV_NOREUSE: int - POSIX_FADV_WILLNEED: int - POSIX_FADV_DONTNEED: int - - SF_NODISKIO: int - SF_MNOWAIT: int - SF_SYNC: int - - XATTR_SIZE_MAX: int # Linux only - XATTR_CREATE: int # Linux only - XATTR_REPLACE: int # Linux only - - P_PID: int - P_PGID: int - P_ALL: int - - WEXITED: int - WSTOPPED: int - WNOWAIT: int - - CLD_EXITED: int - CLD_DUMPED: int - CLD_TRAPPED: int - CLD_CONTINUED: int - - SCHED_OTHER: int # some flavors of Unix - SCHED_BATCH: int # some flavors of Unix - SCHED_IDLE: int # some flavors of Unix - SCHED_SPORADIC: int # some flavors of Unix - SCHED_FIFO: int # some flavors of Unix - SCHED_RR: int # some flavors of Unix - SCHED_RESET_ON_FORK: int # some flavors of Unix - - RTLD_LAZY: int - RTLD_NOW: int - RTLD_GLOBAL: int - RTLD_LOCAL: int - RTLD_NODELETE: int - RTLD_NOLOAD: int - RTLD_DEEPBIND: int +supports_bytes_environ: bool +supports_dir_fd: Set[Callable[..., Any]] +supports_fd: Set[Callable[..., Any]] +supports_effective_ids: Set[Callable[..., Any]] +supports_follow_symlinks: Set[Callable[..., Any]] + +if sys.platform != 'win32': + # Unix only + PRIO_PROCESS: int + PRIO_PGRP: int + PRIO_USER: int + + F_LOCK: int + F_TLOCK: int + F_ULOCK: int + F_TEST: int + + POSIX_FADV_NORMAL: int + POSIX_FADV_SEQUENTIAL: int + POSIX_FADV_RANDOM: int + POSIX_FADV_NOREUSE: int + POSIX_FADV_WILLNEED: int + POSIX_FADV_DONTNEED: int + + SF_NODISKIO: int + SF_MNOWAIT: int + SF_SYNC: int + + XATTR_SIZE_MAX: int # Linux only + XATTR_CREATE: int # Linux only + XATTR_REPLACE: int # Linux only + + P_PID: int + P_PGID: int + P_ALL: int + + WEXITED: int + WSTOPPED: int + WNOWAIT: int + + CLD_EXITED: int + CLD_DUMPED: int + CLD_TRAPPED: int + CLD_CONTINUED: int + + SCHED_OTHER: int # some flavors of Unix + SCHED_BATCH: int # some flavors of Unix + SCHED_IDLE: int # some flavors of Unix + SCHED_SPORADIC: int # some flavors of Unix + SCHED_FIFO: int # some flavors of Unix + SCHED_RR: int # some flavors of Unix + SCHED_RESET_ON_FORK: int # some flavors of Unix + +RTLD_LAZY: int +RTLD_NOW: int +RTLD_GLOBAL: int +RTLD_LOCAL: int +RTLD_NODELETE: int +RTLD_NOLOAD: int +RTLD_DEEPBIND: int SEEK_SET: int SEEK_CUR: int SEEK_END: int -if sys.version_info >= (3, 3) and sys.platform != 'win32': +if sys.platform != 'win32': SEEK_DATA: int # some flavors of Unix SEEK_HOLE: int # some flavors of Unix @@ -104,8 +102,7 @@ O_SYNC: int # Unix only O_NDELAY: int # Unix only O_NONBLOCK: int # Unix only O_NOCTTY: int # Unix only -if sys.version_info >= (3, 3): - O_CLOEXEC: int # Unix only +O_CLOEXEC: int # Unix only O_SHLOCK: int # Unix only O_EXLOCK: int # Unix only O_BINARY: int # Windows only @@ -120,9 +117,8 @@ O_DIRECT: int # Gnu extension if in C library O_DIRECTORY: int # Gnu extension if in C library O_NOFOLLOW: int # Gnu extension if in C library O_NOATIME: int # Gnu extension if in C library -if sys.version_info >= (3, 4): - O_PATH: int # Gnu extension if in C library - O_TMPFILE: int # Gnu extension if in C library +O_PATH: int # Gnu extension if in C library +O_TMPFILE: int # Gnu extension if in C library O_LARGEFILE: int # Gnu extension if in C library curdir: str @@ -153,8 +149,7 @@ class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]): def __len__(self) -> int: ... environ: _Environ[str] -if sys.version_info >= (3, 2): - environb: _Environ[bytes] +environb: _Environ[bytes] if sys.platform != 'win32': confstr_names: Dict[str, int] @@ -242,10 +237,7 @@ if sys.version_info >= (3, 6): from builtins import _PathLike as PathLike # See comment in builtins _PathType = path._PathType -if sys.version_info >= (3, 3): - _FdOrPathType = Union[int, _PathType] -else: - _FdOrPathType = _PathType +_FdOrPathType = Union[int, _PathType] if sys.version_info >= (3, 6): class DirEntry(PathLike[AnyStr]): @@ -261,7 +253,7 @@ if sys.version_info >= (3, 6): def stat(self, *, follow_symlinks: bool = ...) -> stat_result: ... def __fspath__(self) -> AnyStr: ... -elif sys.version_info >= (3, 5): +else: class DirEntry(Generic[AnyStr]): # This is what the scandir interator yields # The constructor is hidden @@ -290,12 +282,12 @@ if sys.platform != 'win32': # ----- os function stubs ----- if sys.version_info >= (3, 6): - def fsencode(filename: Union[str, bytes, PathLike]) -> bytes: ... + def fsencode(filename: Union[str, bytes, PathLike[Any]]) -> bytes: ... else: def fsencode(filename: Union[str, bytes]) -> bytes: ... if sys.version_info >= (3, 6): - def fsdecode(filename: Union[str, bytes, PathLike]) -> str: ... + def fsdecode(filename: Union[str, bytes, PathLike[Any]]) -> str: ... else: def fsdecode(filename: Union[str, bytes]) -> str: ... @@ -305,7 +297,7 @@ if sys.version_info >= (3, 6): @overload def fspath(path: bytes) -> bytes: ... @overload - def fspath(path: PathLike) -> Any: ... + def fspath(path: PathLike[Any]) -> Any: ... def get_exec_path(env: Optional[Mapping[str, str]] = ...) -> List[str]: ... # NOTE: get_exec_path(): returns List[bytes] when env not None @@ -321,15 +313,13 @@ if sys.platform != 'win32': def getegid() -> int: ... def geteuid() -> int: ... def getgid() -> int: ... - if sys.version_info >= (3, 3): - def getgrouplist(user: str, gid: int) -> List[int]: ... + def getgrouplist(user: str, gid: int) -> List[int]: ... def getgroups() -> List[int]: ... # Unix only, behaves differently on Mac def initgroups(username: str, gid: int) -> None: ... def getpgid(pid: int) -> int: ... def getpgrp() -> int: ... - if sys.version_info >= (3, 3): - def getpriority(which: int, who: int) -> int: ... - def setpriority(which: int, who: int, priority: int) -> None: ... + def getpriority(which: int, who: int) -> int: ... + def setpriority(which: int, who: int, priority: int) -> None: ... def getresuid() -> Tuple[int, int, int]: ... def getresgid() -> Tuple[int, int, int]: ... def getuid() -> int: ... @@ -346,11 +336,8 @@ if sys.platform != 'win32': def getsid(pid: int) -> int: ... def setsid() -> None: ... def setuid(uid: int) -> None: ... - if sys.version_info >= (3, 3): - from posix import uname_result - def uname() -> uname_result: ... - else: - def uname() -> Tuple[str, str, str, str, str]: ... + from posix import uname_result + def uname() -> uname_result: ... @overload def getenv(key: Text) -> Optional[str]: ... @@ -369,17 +356,12 @@ def device_encoding(fd: int) -> Optional[str]: ... def dup(fd: int) -> int: ... if sys.version_info >= (3, 7): def dup2(fd: int, fd2: int, inheritable: bool = ...) -> int: ... -elif sys.version_info >= (3, 4): - def dup2(fd: int, fd2: int, inheritable: bool = ...) -> None: ... else: - def dup2(fd: int, fd2: int) -> None: ... + def dup2(fd: int, fd2: int, inheritable: bool = ...) -> None: ... def fstat(fd: int) -> stat_result: ... def fsync(fd: int) -> None: ... def lseek(fd: int, pos: int, how: int) -> int: ... -if sys.version_info >= (3, 3): - def open(file: _PathType, flags: int, mode: int = ..., *, dir_fd: Optional[int] = ...) -> int: ... -else: - def open(file: _PathType, flags: int, mode: int = ...) -> int: ... +def open(file: _PathType, flags: int, mode: int = ..., *, dir_fd: Optional[int] = ...) -> int: ... def pipe() -> Tuple[int, int]: ... def read(fd: int, n: int) -> bytes: ... @@ -391,33 +373,29 @@ if sys.platform != 'win32': def fpathconf(fd: int, name: Union[str, int]) -> int: ... def fstatvfs(fd: int) -> statvfs_result: ... def ftruncate(fd: int, length: int) -> None: ... - if sys.version_info >= (3, 5): - def get_blocking(fd: int) -> bool: ... - def set_blocking(fd: int, blocking: bool) -> None: ... + def get_blocking(fd: int) -> bool: ... + def set_blocking(fd: int, blocking: bool) -> None: ... def isatty(fd: int) -> bool: ... - if sys.version_info >= (3, 3): - def lockf(__fd: int, __cmd: int, __length: int) -> None: ... + def lockf(__fd: int, __cmd: int, __length: int) -> None: ... def openpty() -> Tuple[int, int]: ... # some flavors of Unix - if sys.version_info >= (3, 3): - def pipe2(flags: int) -> Tuple[int, int]: ... # some flavors of Unix - def posix_fallocate(fd: int, offset: int, length: int) -> None: ... - def posix_fadvise(fd: int, offset: int, length: int, advice: int) -> None: ... - def pread(fd: int, buffersize: int, offset: int) -> bytes: ... - def pwrite(fd: int, string: bytes, offset: int) -> int: ... - @overload - def sendfile(__out_fd: int, __in_fd: int, offset: Optional[int], count: int) -> int: ... - @overload - def sendfile(__out_fd: int, __in_fd: int, offset: int, count: int, - headers: Sequence[bytes] = ..., trailers: Sequence[bytes] = ..., flags: int = ...) -> int: ... # FreeBSD and Mac OS X only - def readv(fd: int, buffers: Sequence[bytearray]) -> int: ... - def writev(fd: int, buffers: Sequence[bytes]) -> int: ... + def pipe2(flags: int) -> Tuple[int, int]: ... # some flavors of Unix + def posix_fallocate(fd: int, offset: int, length: int) -> None: ... + def posix_fadvise(fd: int, offset: int, length: int, advice: int) -> None: ... + def pread(fd: int, buffersize: int, offset: int) -> bytes: ... + def pwrite(fd: int, string: bytes, offset: int) -> int: ... + @overload + def sendfile(__out_fd: int, __in_fd: int, offset: Optional[int], count: int) -> int: ... + @overload + def sendfile(__out_fd: int, __in_fd: int, offset: int, count: int, + headers: Sequence[bytes] = ..., trailers: Sequence[bytes] = ..., flags: int = ...) -> int: ... # FreeBSD and Mac OS X only + def readv(fd: int, buffers: Sequence[bytearray]) -> int: ... + def writev(fd: int, buffers: Sequence[bytes]) -> int: ... terminal_size = NamedTuple('terminal_size', [('columns', int), ('lines', int)]) def get_terminal_size(fd: int = ...) -> terminal_size: ... -if sys.version_info >= (3, 4): - def get_inheritable(fd: int) -> bool: ... - def set_inheritable(fd: int, inheritable: bool) -> None: ... +def get_inheritable(fd: int) -> bool: ... +def set_inheritable(fd: int, inheritable: bool) -> None: ... if sys.platform != 'win32': # Unix only @@ -425,81 +403,43 @@ if sys.platform != 'win32': def tcsetpgrp(fd: int, pg: int) -> None: ... def ttyname(fd: int) -> str: ... def write(fd: int, string: bytes) -> int: ... -if sys.version_info >= (3, 3): - def access(path: _FdOrPathType, mode: int, *, dir_fd: Optional[int] = ..., - effective_ids: bool = ..., follow_symlinks: bool = ...) -> bool: ... -else: - def access(path: _PathType, mode: int) -> bool: ... +def access( + path: _FdOrPathType, + mode: int, + *, + dir_fd: Optional[int] = ..., + effective_ids: bool = ..., + follow_symlinks: bool = ..., +) -> bool: ... def chdir(path: _FdOrPathType) -> None: ... def fchdir(fd: int) -> None: ... def getcwd() -> str: ... def getcwdb() -> bytes: ... -if sys.version_info >= (3, 3): - def chmod(path: _FdOrPathType, mode: int, *, dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> None: ... - if sys.platform != 'win32': - def chflags(path: _PathType, flags: int, follow_symlinks: bool = ...) -> None: ... # some flavors of Unix - def chown(path: _FdOrPathType, uid: int, gid: int, *, dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> None: ... # Unix only -else: - def chmod(path: _PathType, mode: int) -> None: ... - if sys.platform != 'win32': - def chflags(path: _PathType, flags: int) -> None: ... # Some flavors of Unix - def chown(path: _PathType, uid: int, gid: int) -> None: ... # Unix only +def chmod(path: _FdOrPathType, mode: int, *, dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> None: ... +if sys.platform != 'win32': + def chflags(path: _PathType, flags: int, follow_symlinks: bool = ...) -> None: ... # some flavors of Unix + def chown(path: _FdOrPathType, uid: int, gid: int, *, dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> None: ... # Unix only if sys.platform != 'win32': # Unix only def chroot(path: _PathType) -> None: ... def lchflags(path: _PathType, flags: int) -> None: ... def lchmod(path: _PathType, mode: int) -> None: ... def lchown(path: _PathType, uid: int, gid: int) -> None: ... -if sys.version_info >= (3, 3): - def link(src: _PathType, link_name: _PathType, *, src_dir_fd: Optional[int] = ..., - dst_dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> None: ... -else: - def link(src: _PathType, link_name: _PathType) -> None: ... - -if sys.version_info >= (3, 6): - @overload - def listdir(path: Optional[str] = ...) -> List[str]: ... - @overload - def listdir(path: bytes) -> List[bytes]: ... - @overload - def listdir(path: int) -> List[str]: ... - @overload - def listdir(path: PathLike[str]) -> List[str]: ... -elif sys.version_info >= (3, 3): - @overload - def listdir(path: Optional[str] = ...) -> List[str]: ... - @overload - def listdir(path: bytes) -> List[bytes]: ... - @overload - def listdir(path: int) -> List[str]: ... -else: - @overload - def listdir(path: Optional[str] = ...) -> List[str]: ... - @overload - def listdir(path: bytes) -> List[bytes]: ... - -if sys.version_info >= (3, 3): - def lstat(path: _PathType, *, dir_fd: Optional[int] = ...) -> stat_result: ... - def mkdir(path: _PathType, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ... - if sys.platform != 'win32': - def mkfifo(path: _PathType, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ... # Unix only -else: - def lstat(path: _PathType) -> stat_result: ... - def mkdir(path: _PathType, mode: int = ...) -> None: ... - if sys.platform != 'win32': - def mkfifo(path: _PathType, mode: int = ...) -> None: ... # Unix only -if sys.version_info >= (3, 4): - def makedirs(name: _PathType, mode: int = ..., exist_ok: bool = ...) -> None: ... -else: - def makedirs(path: _PathType, mode: int = ..., exist_ok: bool = ...) -> None: ... -if sys.version_info >= (3, 4): - def mknod(path: _PathType, mode: int = ..., device: int = ..., - *, dir_fd: Optional[int] = ...) -> None: ... -elif sys.version_info >= (3, 3): - def mknod(filename: _PathType, mode: int = ..., device: int = ..., - *, dir_fd: Optional[int] = ...) -> None: ... -else: - def mknod(filename: _PathType, mode: int = ..., device: int = ...) -> None: ... +def link( + src: _PathType, + link_name: _PathType, + *, + src_dir_fd: Optional[int] = ..., + dst_dir_fd: Optional[int] = ..., + follow_symlinks: bool = ..., +) -> None: ... + +def lstat(path: _PathType, *, dir_fd: Optional[int] = ...) -> stat_result: ... +def mkdir(path: _PathType, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ... +if sys.platform != 'win32': + def mkfifo(path: _PathType, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ... # Unix only +def makedirs(name: _PathType, mode: int = ..., exist_ok: bool = ...) -> None: ... +def mknod(path: _PathType, mode: int = ..., device: int = ..., *, dir_fd: Optional[int] = ...) -> None: ... def major(device: int) -> int: ... def minor(device: int) -> int: ... def makedev(major: int, minor: int) -> int: ... @@ -507,30 +447,14 @@ if sys.platform != 'win32': def pathconf(path: _FdOrPathType, name: Union[str, int]) -> int: ... # Unix only if sys.version_info >= (3, 6): def readlink(path: Union[AnyStr, PathLike[AnyStr]], *, dir_fd: Optional[int] = ...) -> AnyStr: ... -elif sys.version_info >= (3, 3): - def readlink(path: AnyStr, *, dir_fd: Optional[int] = ...) -> AnyStr: ... -else: - def readlink(path: AnyStr) -> AnyStr: ... -if sys.version_info >= (3, 3): - def remove(path: _PathType, *, dir_fd: Optional[int] = ...) -> None: ... else: - def remove(path: _PathType) -> None: ... -if sys.version_info >= (3, 4): - def removedirs(name: _PathType) -> None: ... -else: - def removedirs(path: _PathType) -> None: ... -if sys.version_info >= (3, 3): - def rename(src: _PathType, dst: _PathType, *, - src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ...) -> None: ... -else: - def rename(src: _PathType, dst: _PathType) -> None: ... + def readlink(path: AnyStr, *, dir_fd: Optional[int] = ...) -> AnyStr: ... +def remove(path: _PathType, *, dir_fd: Optional[int] = ...) -> None: ... +def removedirs(name: _PathType) -> None: ... +def rename(src: _PathType, dst: _PathType, *, src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ...) -> None: ... def renames(old: _PathType, new: _PathType) -> None: ... -if sys.version_info >= (3, 3): - def replace(src: _PathType, dst: _PathType, *, - src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ...) -> None: ... - def rmdir(path: _PathType, *, dir_fd: Optional[int] = ...) -> None: ... -else: - def rmdir(path: _PathType) -> None: ... +def replace(src: _PathType, dst: _PathType, *, src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ...) -> None: ... +def rmdir(path: _PathType, *, dir_fd: Optional[int] = ...) -> None: ... if sys.version_info >= (3, 7): class _ScandirIterator(Iterator[DirEntry[AnyStr]], ContextManager[_ScandirIterator[AnyStr]]): def __next__(self) -> DirEntry[AnyStr]: ... @@ -549,16 +473,12 @@ elif sys.version_info >= (3, 6): def scandir() -> _ScandirIterator[str]: ... @overload def scandir(path: Union[AnyStr, PathLike[AnyStr]]) -> _ScandirIterator[AnyStr]: ... -elif sys.version_info >= (3, 5): +else: @overload def scandir() -> Iterator[DirEntry[str]]: ... @overload def scandir(path: AnyStr) -> Iterator[DirEntry[AnyStr]]: ... -if sys.version_info >= (3, 3): - def stat(path: _FdOrPathType, *, dir_fd: Optional[int] = ..., - follow_symlinks: bool = ...) -> stat_result: ... -else: - def stat(path: _PathType) -> stat_result: ... +def stat(path: _FdOrPathType, *, dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> stat_result: ... if sys.version_info < (3, 7): @overload def stat_float_times() -> bool: ... @@ -566,49 +486,54 @@ if sys.version_info < (3, 7): def stat_float_times(__newvalue: bool) -> None: ... if sys.platform != 'win32': def statvfs(path: _FdOrPathType) -> statvfs_result: ... # Unix only -if sys.version_info >= (3, 3): - def symlink(source: _PathType, link_name: _PathType, - target_is_directory: bool = ..., *, dir_fd: Optional[int] = ...) -> None: ... - if sys.platform != 'win32': - def sync() -> None: ... # Unix only - def truncate(path: _FdOrPathType, length: int) -> None: ... # Unix only up to version 3.4 - def unlink(path: _PathType, *, dir_fd: Optional[int] = ...) -> None: ... - def utime(path: _FdOrPathType, times: Optional[Union[Tuple[int, int], Tuple[float, float]]] = ..., *, - ns: Tuple[int, int] = ..., dir_fd: Optional[int] = ..., - follow_symlinks: bool = ...) -> None: ... -else: - def symlink(source: _PathType, link_name: _PathType, - target_is_directory: bool = ...) -> None: - ... # final argument in Windows only - def unlink(path: _PathType) -> None: ... - def utime(path: _PathType, times: Optional[Tuple[float, float]]) -> None: ... +def symlink( + source: _PathType, + link_name: _PathType, + target_is_directory: bool = ..., + *, + dir_fd: Optional[int] = ..., +) -> None: ... +if sys.platform != 'win32': + def sync() -> None: ... # Unix only +def truncate(path: _FdOrPathType, length: int) -> None: ... # Unix only up to version 3.4 +def unlink(path: _PathType, *, dir_fd: Optional[int] = ...) -> None: ... +def utime( + path: _FdOrPathType, + times: Optional[Union[Tuple[int, int], Tuple[float, float]]] = ..., + *, + ns: Tuple[int, int] = ..., + dir_fd: Optional[int] = ..., + follow_symlinks: bool = ..., +) -> None: ... + +_OnError = Callable[[OSError], Any] if sys.version_info >= (3, 6): def walk(top: Union[AnyStr, PathLike[AnyStr]], topdown: bool = ..., - onerror: Optional[Callable[[OSError], Any]] = ..., + onerror: Optional[_OnError] = ..., followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr], List[AnyStr]]]: ... else: - def walk(top: AnyStr, topdown: bool = ..., onerror: Optional[Callable[[OSError], Any]] = ..., + def walk(top: AnyStr, topdown: bool = ..., onerror: Optional[_OnError] = ..., followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr], List[AnyStr]]]: ... -if sys.platform != 'win32' and sys.version_info >= (3, 3): +if sys.platform != 'win32': if sys.version_info >= (3, 7): @overload def fwalk(top: Union[str, PathLike[str]] = ..., topdown: bool = ..., - onerror: Optional[Callable] = ..., *, follow_symlinks: bool = ..., + onerror: Optional[_OnError] = ..., *, follow_symlinks: bool = ..., dir_fd: Optional[int] = ...) -> Iterator[Tuple[str, List[str], List[str], int]]: ... @overload def fwalk(top: bytes, topdown: bool = ..., - onerror: Optional[Callable] = ..., *, follow_symlinks: bool = ..., + onerror: Optional[_OnError] = ..., *, follow_symlinks: bool = ..., dir_fd: Optional[int] = ...) -> Iterator[Tuple[bytes, List[bytes], List[bytes], int]]: ... elif sys.version_info >= (3, 6): def fwalk(top: Union[str, PathLike[str]] = ..., topdown: bool = ..., - onerror: Optional[Callable] = ..., *, follow_symlinks: bool = ..., + onerror: Optional[_OnError] = ..., *, follow_symlinks: bool = ..., dir_fd: Optional[int] = ...) -> Iterator[Tuple[str, List[str], List[str], int]]: ... else: def fwalk(top: str = ..., topdown: bool = ..., - onerror: Optional[Callable] = ..., *, follow_symlinks: bool = ..., + onerror: Optional[_OnError] = ..., *, follow_symlinks: bool = ..., dir_fd: Optional[int] = ...) -> Iterator[Tuple[str, List[str], List[str], int]]: ... def getxattr(path: _FdOrPathType, attribute: _PathType, *, follow_symlinks: bool = ...) -> bytes: ... # Linux only def listxattr(path: _FdOrPathType, *, follow_symlinks: bool = ...) -> List[str]: ... # Linux only @@ -643,17 +568,9 @@ if sys.platform != 'win32': def nice(increment: int) -> int: ... def plock(op: int) -> None: ... # ???op is int? -if sys.version_info >= (3, 0): - class _wrap_close(_TextIOWrapper): - def close(self) -> Optional[int]: ... # type: ignore - def popen(command: str, mode: str = ..., buffering: int = ...) -> _wrap_close: ... -else: - class _wrap_close(IO[Text]): - def close(self) -> Optional[int]: ... - def popen(__cmd: Text, __mode: Text = ..., __bufsize: int = ...) -> _wrap_close: ... - def popen2(__cmd: Text, __mode: Text = ..., __bufsize: int = ...) -> Tuple[IO[Text], IO[Text]]: ... - def popen3(__cmd: Text, __mode: Text = ..., __bufsize: int = ...) -> Tuple[IO[Text], IO[Text], IO[Text]]: ... - def popen4(__cmd: Text, __mode: Text = ..., __bufsize: int = ...) -> Tuple[IO[Text], IO[Text]]: ... +class _wrap_close(_TextIOWrapper): + def close(self) -> Optional[int]: ... # type: ignore +def popen(command: str, mode: str = ..., buffering: int = ...) -> _wrap_close: ... def spawnl(mode: int, path: _PathType, arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> int: ... def spawnle(mode: int, path: _PathType, arg0: Union[bytes, Text], @@ -662,11 +579,7 @@ def spawnv(mode: int, path: _PathType, args: List[Union[bytes, Text]]) -> int: . def spawnve(mode: int, path: _PathType, args: List[Union[bytes, Text]], env: Mapping[str, str]) -> int: ... def system(command: _PathType) -> int: ... -if sys.version_info >= (3, 3): - from posix import times_result - def times() -> times_result: ... -else: - def times() -> Tuple[float, float, float, float, float]: ... +def times() -> times_result: ... def waitpid(pid: int, options: int) -> Tuple[int, int]: ... if sys.platform == 'win32': @@ -678,9 +591,8 @@ else: def spawnvp(mode: int, file: _PathType, args: List[Union[bytes, Text]]) -> int: ... def spawnvpe(mode: int, file: _PathType, args: List[Union[bytes, Text]], env: Mapping[str, str]) -> int: ... def wait() -> Tuple[int, int]: ... # Unix only - if sys.version_info >= (3, 3): - from posix import waitid_result - def waitid(idtype: int, ident: int, options: int) -> waitid_result: ... + from posix import waitid_result + def waitid(idtype: int, ident: int, options: int) -> waitid_result: ... def wait3(options: int) -> Tuple[int, int, Any]: ... def wait4(pid: int, options: int) -> Tuple[int, int, Any]: ... def WCOREDUMP(status: int) -> bool: ... @@ -692,7 +604,7 @@ else: def WSTOPSIG(status: int) -> int: ... def WTERMSIG(status: int) -> int: ... -if sys.platform != 'win32' and sys.version_info >= (3, 3): +if sys.platform != 'win32': from posix import sched_param def sched_get_priority_min(policy: int) -> int: ... # some flavors of Unix def sched_get_priority_max(policy: int) -> int: ... # some flavors of Unix @@ -705,8 +617,7 @@ if sys.platform != 'win32' and sys.version_info >= (3, 3): def sched_setaffinity(pid: int, mask: Iterable[int]) -> None: ... # some flavors of Unix def sched_getaffinity(pid: int) -> Set[int]: ... # some flavors of Unix -if sys.version_info >= (3, 4): - def cpu_count() -> Optional[int]: ... +def cpu_count() -> Optional[int]: ... if sys.platform != 'win32': # Unix only def confstr(name: Union[str, int]) -> Optional[str]: ... diff --git a/stdlib/3/pathlib.pyi b/stdlib/3/pathlib.pyi index 42968fa98ec7..ff6bedd1c043 100644 --- a/stdlib/3/pathlib.pyi +++ b/stdlib/3/pathlib.pyi @@ -3,7 +3,7 @@ from types import TracebackType import os import sys -_P = TypeVar('_P', bound='PurePath') +_P = TypeVar('_P', bound=PurePath) if sys.version_info >= (3, 6): _PurePathBase = os.PathLike[str] @@ -30,7 +30,12 @@ class PurePath(_PurePathBase): def __le__(self, other: PurePath) -> bool: ... def __gt__(self, other: PurePath) -> bool: ... def __ge__(self, other: PurePath) -> bool: ... - def __truediv__(self: _P, key: Union[str, PurePath]) -> _P: ... + if sys.version_info < (3, 6): + def __truediv__(self: _P, key: Union[str, PurePath]) -> _P: ... + def __rtruediv__(self: _P, key: Union[str, PurePath]) -> _P: ... + else: + def __truediv__(self: _P, key: Union[str, os.PathLike[str]]) -> _P: ... + def __rtruediv__(self: _P, key: Union[str, os.PathLike[str]]) -> _P: ... if sys.version_info < (3,): def __div__(self: _P, key: Union[str, PurePath]) -> _P: ... def __bytes__(self) -> bytes: ... @@ -39,10 +44,16 @@ class PurePath(_PurePathBase): def is_absolute(self) -> bool: ... def is_reserved(self) -> bool: ... def match(self, path_pattern: str) -> bool: ... - def relative_to(self: _P, *other: Union[str, PurePath]) -> _P: ... + if sys.version_info < (3, 6): + def relative_to(self: _P, *other: Union[str, PurePath]) -> _P: ... + else: + def relative_to(self: _P, *other: Union[str, os.PathLike[str]]) -> _P: ... def with_name(self: _P, name: str) -> _P: ... def with_suffix(self: _P, suffix: str) -> _P: ... - def joinpath(self: _P, *other: Union[str, PurePath]) -> _P: ... + if sys.version_info < (3, 6): + def joinpath(self: _P, *other: Union[str, PurePath]) -> _P: ... + else: + def joinpath(self: _P, *other: Union[str, os.PathLike[str]]) -> _P: ... @property def parents(self: _P) -> Sequence[_P]: ... diff --git a/stdlib/3/posix.pyi b/stdlib/3/posix.pyi index 6902e5f23240..83537cfbc650 100644 --- a/stdlib/3/posix.pyi +++ b/stdlib/3/posix.pyi @@ -3,10 +3,13 @@ # NOTE: These are incomplete! import sys -from typing import NamedTuple, Tuple +from typing import List, NamedTuple, Optional, overload, Tuple from os import stat_result as stat_result +if sys.version_info >= (3, 6): + from builtins import _PathLike # See comment in builtins + uname_result = NamedTuple('uname_result', [ ('sysname', str), ('nodename', str), @@ -65,8 +68,7 @@ if sys.version_info >= (3, 6): NGROUPS_MAX: int O_APPEND: int -if sys.version_info >= (3, 4): - O_ACCMODE: int +O_ACCMODE: int O_ASYNC: int O_CREAT: int O_DIRECT: int @@ -110,3 +112,20 @@ WNOHANG: int WSTOPSIG: int WTERMSIG: int WUNTRACED: int + +if sys.version_info >= (3, 6): + @overload + def listdir(path: Optional[str] = ...) -> List[str]: ... + @overload + def listdir(path: bytes) -> List[bytes]: ... + @overload + def listdir(path: int) -> List[str]: ... + @overload + def listdir(path: _PathLike[str]) -> List[str]: ... +else: + @overload + def listdir(path: Optional[str] = ...) -> List[str]: ... + @overload + def listdir(path: bytes) -> List[bytes]: ... + @overload + def listdir(path: int) -> List[str]: ... diff --git a/stdlib/3/queue.pyi b/stdlib/3/queue.pyi index 88605a358325..9647faf4c0d3 100644 --- a/stdlib/3/queue.pyi +++ b/stdlib/3/queue.pyi @@ -2,8 +2,8 @@ # NOTE: These are incomplete! -from collections import deque -from typing import Any, TypeVar, Generic, Optional +from threading import Condition, Lock +from typing import Any, Deque, TypeVar, Generic, Optional import sys _T = TypeVar('_T') @@ -13,7 +13,14 @@ class Full(Exception): ... class Queue(Generic[_T]): maxsize: int - queue: deque # undocumented + + mutex: Lock # undocumented + not_empty: Condition # undocumented + not_full: Condition # undocumented + all_tasks_done: Condition # undocumented + unfinished_tasks: int # undocumented + + queue: Deque[Any] # undocumented def __init__(self, maxsize: int = ...) -> None: ... def _init(self, maxsize: int) -> None: ... def empty(self) -> bool: ... diff --git a/stdlib/3/random.pyi b/stdlib/3/random.pyi index 35ee63488bf7..7fa0698a0a0e 100644 --- a/stdlib/3/random.pyi +++ b/stdlib/3/random.pyi @@ -8,17 +8,15 @@ import _random import sys -from typing import ( - Any, TypeVar, Sequence, List, Callable, AbstractSet, Union, Optional -) +from typing import Any, TypeVar, Sequence, List, Callable, AbstractSet, Union, Optional, Tuple _T = TypeVar('_T') class Random(_random.Random): def __init__(self, x: Any = ...) -> None: ... def seed(self, a: Any = ..., version: int = ...) -> None: ... - def getstate(self) -> tuple: ... - def setstate(self, state: tuple) -> None: ... + def getstate(self) -> Tuple[Any, ...]: ... + def setstate(self, state: Tuple[Any, ...]) -> None: ... def getrandbits(self, k: int) -> int: ... def randrange(self, start: int, stop: Union[int, None] = ..., step: int = ...) -> int: ... def randint(self, a: int, b: int) -> int: ... diff --git a/stdlib/3/re.pyi b/stdlib/3/re.pyi index a75bfe67e619..9fb77420d299 100644 --- a/stdlib/3/re.pyi +++ b/stdlib/3/re.pyi @@ -7,31 +7,31 @@ import sys from typing import ( - List, Iterator, overload, Callable, Tuple, Sequence, Dict, - Generic, AnyStr, Match, Pattern, Any, Optional, Union + List, Iterator, overload, Callable, Tuple, + AnyStr, Match, Pattern, Any, Optional, Union ) # ----- re variables and constants ----- if sys.version_info >= (3, 6): import enum class RegexFlag(enum.IntFlag): - A = 0 - ASCII = 0 - DEBUG = 0 - I = 0 - IGNORECASE = 0 - L = 0 - LOCALE = 0 - M = 0 - MULTILINE = 0 - S = 0 - DOTALL = 0 - X = 0 - VERBOSE = 0 - U = 0 - UNICODE = 0 - T = 0 - TEMPLATE = 0 + A: int + ASCII: int + DEBUG: int + I: int + IGNORECASE: int + L: int + LOCALE: int + M: int + MULTILINE: int + S: int + DOTALL: int + X: int + VERBOSE: int + U: int + UNICODE: int + T: int + TEMPLATE: int A = RegexFlag.A ASCII = RegexFlag.ASCII @@ -52,23 +52,23 @@ if sys.version_info >= (3, 6): TEMPLATE = RegexFlag.TEMPLATE _FlagsType = Union[int, RegexFlag] else: - A = 0 - ASCII = 0 - DEBUG = 0 - I = 0 - IGNORECASE = 0 - L = 0 - LOCALE = 0 - M = 0 - MULTILINE = 0 - S = 0 - DOTALL = 0 - X = 0 - VERBOSE = 0 - U = 0 - UNICODE = 0 - T = 0 - TEMPLATE = 0 + A: int + ASCII: int + DEBUG: int + I: int + IGNORECASE: int + L: int + LOCALE: int + M: int + MULTILINE: int + S: int + DOTALL: int + X: int + VERBOSE: int + U: int + UNICODE: int + T: int + TEMPLATE: int _FlagsType = int if sys.version_info < (3, 7): diff --git a/stdlib/3/reprlib.pyi b/stdlib/3/reprlib.pyi index 462251875f39..7ff879bc7704 100644 --- a/stdlib/3/reprlib.pyi +++ b/stdlib/3/reprlib.pyi @@ -24,7 +24,7 @@ class Repr: def repr1(self, x: Any, level: int) -> str: ... def repr_tuple(self, x: Tuple[Any, ...], level: int) -> str: ... def repr_list(self, x: List[Any], level: int) -> str: ... - def repr_array(self, x: array, level: int) -> str: ... + def repr_array(self, x: array[Any], level: int) -> str: ... def repr_set(self, x: Set[Any], level: int) -> str: ... def repr_frozenset(self, x: FrozenSet[Any], level: int) -> str: ... def repr_deque(self, x: Deque[Any], level: int) -> str: ... diff --git a/stdlib/3/selectors.pyi b/stdlib/3/selectors.pyi index 39e68ce7950a..6dd864795fc7 100644 --- a/stdlib/3/selectors.pyi +++ b/stdlib/3/selectors.pyi @@ -1,16 +1,14 @@ # Stubs for selector # See https://docs.python.org/3/library/selectors.html -from typing import Any, List, NamedTuple, Mapping, Tuple, Optional, Union from abc import ABCMeta, abstractmethod -import socket +from typing import Any, List, Mapping, NamedTuple, Optional, Protocol, Tuple, Union +class _HasFileno(Protocol): + def fileno(self) -> int: ... # Type aliases added mainly to preserve some context -# -# See https://github.com/python/typeshed/issues/482 -# for details regarding how _FileObject is typed. -_FileObject = Union[int, socket.socket] +_FileObject = Union[int, _HasFileno] _FileDescriptor = int _EventMask = int diff --git a/stdlib/3/shelve.pyi b/stdlib/3/shelve.pyi index 4a339692ce00..97a045e0e849 100644 --- a/stdlib/3/shelve.pyi +++ b/stdlib/3/shelve.pyi @@ -2,7 +2,7 @@ from typing import Any, Dict, Iterator, Optional, Tuple import collections -class Shelf(collections.MutableMapping): +class Shelf(collections.MutableMapping[Any, Any]): def __init__(self, dict: Dict[bytes, Any], protocol: Optional[int] = ..., writeback: bool = ..., keyencoding: str = ...) -> None: ... def __iter__(self) -> Iterator[str]: ... def __len__(self) -> int: ... diff --git a/stdlib/3/signal.pyi b/stdlib/3/signal.pyi index 34a8cdd07f29..670567b83650 100644 --- a/stdlib/3/signal.pyi +++ b/stdlib/3/signal.pyi @@ -1,132 +1,118 @@ """Stub file for the 'signal' module.""" -import sys from enum import IntEnum -from typing import Any, Callable, List, Tuple, Dict, Generic, Union, Optional, Iterable, Set +from typing import Any, Callable, Tuple, Union, Optional, Iterable, Set from types import FrameType class ItimerError(IOError): ... -ITIMER_PROF: int = ... -ITIMER_REAL: int = ... -ITIMER_VIRTUAL: int = ... - -NSIG: int = ... - -if sys.version_info >= (3, 5): - class Signals(IntEnum): - SIGABRT = ... - SIGALRM = ... - SIGBREAK = ... # Windows - SIGBUS = ... - SIGCHLD = ... - SIGCLD = ... - SIGCONT = ... - SIGEMT = ... - SIGFPE = ... - SIGHUP = ... - SIGILL = ... - SIGINFO = ... - SIGINT = ... - SIGIO = ... - SIGIOT = ... - SIGKILL = ... - SIGPIPE = ... - SIGPOLL = ... - SIGPROF = ... - SIGPWR = ... - SIGQUIT = ... - SIGRTMAX = ... - SIGRTMIN = ... - SIGSEGV = ... - SIGSTOP = ... - SIGSYS = ... - SIGTERM = ... - SIGTRAP = ... - SIGTSTP = ... - SIGTTIN = ... - SIGTTOU = ... - SIGURG = ... - SIGUSR1 = ... - SIGUSR2 = ... - SIGVTALRM = ... - SIGWINCH = ... - SIGXCPU = ... - SIGXFSZ = ... - - class Handlers(IntEnum): - SIG_DFL = ... - SIG_IGN = ... - - SIG_DFL = Handlers.SIG_DFL - SIG_IGN = Handlers.SIG_IGN - - class Sigmasks(IntEnum): - SIG_BLOCK = ... - SIG_UNBLOCK = ... - SIG_SETMASK = ... - - SIG_BLOCK = Sigmasks.SIG_BLOCK - SIG_UNBLOCK = Sigmasks.SIG_UNBLOCK - SIG_SETMASK = Sigmasks.SIG_SETMASK - - _SIG = Signals - _SIGNUM = Union[int, Signals] - _HANDLER = Union[Callable[[Signals, FrameType], None], int, Handlers, None] -else: - SIG_DFL: int = ... - SIG_IGN: int = ... - - SIG_BLOCK: int = ... - SIG_UNBLOCK: int = ... - SIG_SETMASK: int = ... - - _SIG = int - _SIGNUM = int - _HANDLER = Union[Callable[[int, FrameType], None], int, None] - -SIGABRT: _SIG = ... -SIGALRM: _SIG = ... -SIGBREAK: _SIG = ... # Windows -SIGBUS: _SIG = ... -SIGCHLD: _SIG = ... -SIGCLD: _SIG = ... -SIGCONT: _SIG = ... -SIGEMT: _SIG = ... -SIGFPE: _SIG = ... -SIGHUP: _SIG = ... -SIGILL: _SIG = ... -SIGINFO: _SIG = ... -SIGINT: _SIG = ... -SIGIO: _SIG = ... -SIGIOT: _SIG = ... -SIGKILL: _SIG = ... -SIGPIPE: _SIG = ... -SIGPOLL: _SIG = ... -SIGPROF: _SIG = ... -SIGPWR: _SIG = ... -SIGQUIT: _SIG = ... -SIGRTMAX: _SIG = ... -SIGRTMIN: _SIG = ... -SIGSEGV: _SIG = ... -SIGSTOP: _SIG = ... -SIGSYS: _SIG = ... -SIGTERM: _SIG = ... -SIGTRAP: _SIG = ... -SIGTSTP: _SIG = ... -SIGTTIN: _SIG = ... -SIGTTOU: _SIG = ... -SIGURG: _SIG = ... -SIGUSR1: _SIG = ... -SIGUSR2: _SIG = ... -SIGVTALRM: _SIG = ... -SIGWINCH: _SIG = ... -SIGXCPU: _SIG = ... -SIGXFSZ: _SIG = ... +ITIMER_PROF: int +ITIMER_REAL: int +ITIMER_VIRTUAL: int + +NSIG: int + +class Signals(IntEnum): + SIGABRT: int + SIGALRM: int + SIGBREAK: int # Windows + SIGBUS: int + SIGCHLD: int + SIGCLD: int + SIGCONT: int + SIGEMT: int + SIGFPE: int + SIGHUP: int + SIGILL: int + SIGINFO: int + SIGINT: int + SIGIO: int + SIGIOT: int + SIGKILL: int + SIGPIPE: int + SIGPOLL: int + SIGPROF: int + SIGPWR: int + SIGQUIT: int + SIGRTMAX: int + SIGRTMIN: int + SIGSEGV: int + SIGSTOP: int + SIGSYS: int + SIGTERM: int + SIGTRAP: int + SIGTSTP: int + SIGTTIN: int + SIGTTOU: int + SIGURG: int + SIGUSR1: int + SIGUSR2: int + SIGVTALRM: int + SIGWINCH: int + SIGXCPU: int + SIGXFSZ: int + +class Handlers(IntEnum): + SIG_DFL: int + SIG_IGN: int + +SIG_DFL = Handlers.SIG_DFL +SIG_IGN = Handlers.SIG_IGN + +class Sigmasks(IntEnum): + SIG_BLOCK: int + SIG_UNBLOCK: int + SIG_SETMASK: int + +SIG_BLOCK = Sigmasks.SIG_BLOCK +SIG_UNBLOCK = Sigmasks.SIG_UNBLOCK +SIG_SETMASK = Sigmasks.SIG_SETMASK + +_SIGNUM = Union[int, Signals] +_HANDLER = Union[Callable[[Signals, FrameType], None], int, Handlers, None] + +SIGABRT: Signals +SIGALRM: Signals +SIGBREAK: Signals # Windows +SIGBUS: Signals +SIGCHLD: Signals +SIGCLD: Signals +SIGCONT: Signals +SIGEMT: Signals +SIGFPE: Signals +SIGHUP: Signals +SIGILL: Signals +SIGINFO: Signals +SIGINT: Signals +SIGIO: Signals +SIGIOT: Signals +SIGKILL: Signals +SIGPIPE: Signals +SIGPOLL: Signals +SIGPROF: Signals +SIGPWR: Signals +SIGQUIT: Signals +SIGRTMAX: Signals +SIGRTMIN: Signals +SIGSEGV: Signals +SIGSTOP: Signals +SIGSYS: Signals +SIGTERM: Signals +SIGTRAP: Signals +SIGTSTP: Signals +SIGTTIN: Signals +SIGTTOU: Signals +SIGURG: Signals +SIGUSR1: Signals +SIGUSR2: Signals +SIGVTALRM: Signals +SIGWINCH: Signals +SIGXCPU: Signals +SIGXFSZ: Signals # Windows -CTRL_C_EVENT: _SIG = ... -CTRL_BREAK_EVENT: _SIG = ... +CTRL_C_EVENT: int +CTRL_BREAK_EVENT: int class struct_siginfo(Tuple[int, int, int, int, int, int, int]): def __init__(self, sequence: Iterable[int]) -> None: ... diff --git a/stdlib/3/smtplib.pyi b/stdlib/3/smtplib.pyi index ec8e27f09dfb..d13439b385d5 100644 --- a/stdlib/3/smtplib.pyi +++ b/stdlib/3/smtplib.pyi @@ -96,20 +96,16 @@ class SMTP: vrfy = verify def expn(self, address: str) -> _Reply: ... def ehlo_or_helo_if_needed(self) -> None: ... - if sys.version_info >= (3, 5): - user: str - password: str - def auth(self, mechanism: str, authobject: _AuthObject, *, initial_response_ok: bool = ...) -> _Reply: ... - @overload - def auth_cram_md5(self, challenge: None = ...) -> None: ... - @overload - def auth_cram_md5(self, challenge: bytes) -> str: ... - def auth_plain(self, challenge: Optional[bytes] = ...) -> str: ... - def auth_login(self, challenge: Optional[bytes] = ...) -> str: ... - def login(self, user: str, password: str, *, - initial_response_ok: bool = ...) -> _Reply: ... - else: - def login(self, user: str, password: str) -> _Reply: ... + user: str + password: str + def auth(self, mechanism: str, authobject: _AuthObject, *, initial_response_ok: bool = ...) -> _Reply: ... + @overload + def auth_cram_md5(self, challenge: None = ...) -> None: ... + @overload + def auth_cram_md5(self, challenge: bytes) -> str: ... + def auth_plain(self, challenge: Optional[bytes] = ...) -> str: ... + def auth_login(self, challenge: Optional[bytes] = ...) -> str: ... + def login(self, user: str, password: str, *, initial_response_ok: bool = ...) -> _Reply: ... def starttls(self, keyfile: Optional[str] = ..., certfile: Optional[str] = ..., context: Optional[SSLContext] = ...) -> _Reply: ... def sendmail(self, from_addr: str, to_addrs: Union[str, Sequence[str]], diff --git a/stdlib/3/socketserver.pyi b/stdlib/3/socketserver.pyi index d485b8bf1034..2403614b4709 100644 --- a/stdlib/3/socketserver.pyi +++ b/stdlib/3/socketserver.pyi @@ -1,7 +1,7 @@ # NB: SocketServer.pyi and socketserver.pyi must remain consistent! # Stubs for socketserver -from typing import Any, BinaryIO, Optional, Tuple, Type +from typing import Any, BinaryIO, Optional, Tuple, Type, Text, Union from socket import SocketType import sys import types @@ -15,7 +15,7 @@ class BaseServer: request_queue_size: int socket_type: int timeout: Optional[float] - def __init__(self, server_address: Tuple[str, int], + def __init__(self, server_address: Any, RequestHandlerClass: type) -> None: ... def fileno(self) -> int: ... def handle_request(self) -> None: ... @@ -38,7 +38,7 @@ class BaseServer: def __enter__(self) -> BaseServer: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[types.TracebackType]) -> bool: ... + exc_tb: Optional[types.TracebackType]) -> None: ... if sys.version_info >= (3, 3): def service_actions(self) -> None: ... @@ -54,12 +54,12 @@ class UDPServer(BaseServer): if sys.platform != 'win32': class UnixStreamServer(BaseServer): - def __init__(self, server_address: Tuple[str, int], + def __init__(self, server_address: Union[Text, bytes], RequestHandlerClass: type, bind_and_activate: bool = ...) -> None: ... class UnixDatagramServer(BaseServer): - def __init__(self, server_address: Tuple[str, int], + def __init__(self, server_address: Union[Text, bytes], RequestHandlerClass: type, bind_and_activate: bool = ...) -> None: ... diff --git a/stdlib/3/sre_parse.pyi b/stdlib/3/sre_parse.pyi index 93b3c1dd7dab..8757af795665 100644 --- a/stdlib/3/sre_parse.pyi +++ b/stdlib/3/sre_parse.pyi @@ -77,5 +77,5 @@ class Tokenizer: def fix_flags(src: Union[str, bytes], flag: int) -> int: ... def parse(str: str, flags: int = ..., pattern: Pattern = ...) -> SubPattern: ... _TemplateType = Tuple[List[Tuple[int, int]], List[str]] -def parse_template(source: str, pattern: _Pattern) -> _TemplateType: ... -def expand_template(template: _TemplateType, match: Match) -> str: ... +def parse_template(source: str, pattern: _Pattern[Any]) -> _TemplateType: ... +def expand_template(template: _TemplateType, match: Match[Any]) -> str: ... diff --git a/stdlib/3/subprocess.pyi b/stdlib/3/subprocess.pyi index b2424494d25e..8bc2e807e571 100644 --- a/stdlib/3/subprocess.pyi +++ b/stdlib/3/subprocess.pyi @@ -2,19 +2,30 @@ # Based on http://docs.python.org/3.6/library/subprocess.html import sys -from typing import Sequence, Any, Mapping, Callable, Tuple, IO, Optional, Union, List, Type, Text +from typing import ( + Sequence, Any, Mapping, Callable, Tuple, IO, Optional, Union, List, Type, Text, + Generic, TypeVar, AnyStr, + overload, +) from types import TracebackType +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + # We prefer to annotate inputs to methods (eg subprocess.check_call) with these -# union types. However, outputs (eg check_call return) and class attributes -# (eg TimeoutError.cmd) we prefer to annotate with Any, so the caller does not -# have to use an assertion to confirm which type. +# union types. +# For outputs we use laborious literal based overloads to try to determine +# which specific return types to use, and prefer to fall back to Any when +# this does not work, so the caller does not have to use an assertion to confirm +# which type. # # For example: # # try: # x = subprocess.check_output(["ls", "-l"]) -# reveal_type(x) # Any, but morally is _TXT +# reveal_type(x) # bytes, based on the overloads # except TimeoutError as e: # reveal_type(e.cmd) # Any, but morally is _CMD _FILE = Union[None, int, IO[Any]] @@ -29,94 +40,399 @@ else: _CMD = Union[_TXT, Sequence[_PATH]] _ENV = Union[Mapping[bytes, _TXT], Mapping[Text, _TXT]] -if sys.version_info >= (3, 5): - class CompletedProcess: - # morally: _CMD - args: Any - returncode: int - # morally: Optional[_TXT] - stdout: Any - stderr: Any - def __init__(self, args: _CMD, - returncode: int, - stdout: Optional[_TXT] = ..., - stderr: Optional[_TXT] = ...) -> None: ... - def check_returncode(self) -> None: ... +_S = TypeVar('_S') +_T = TypeVar('_T') - if sys.version_info >= (3, 7): - # Nearly the same args as for 3.6, except for capture_output and text - def run(args: _CMD, - bufsize: int = ..., - executable: _PATH = ..., - stdin: _FILE = ..., - stdout: _FILE = ..., - stderr: _FILE = ..., - preexec_fn: Callable[[], Any] = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: Optional[_PATH] = ..., - env: Optional[_ENV] = ..., - universal_newlines: bool = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - capture_output: bool = ..., - check: bool = ..., - encoding: Optional[str] = ..., - errors: Optional[str] = ..., - input: Optional[_TXT] = ..., - text: Optional[bool] = ..., - timeout: Optional[float] = ...) -> CompletedProcess: ... - elif sys.version_info >= (3, 6): - # Nearly same args as Popen.__init__ except for timeout, input, and check - def run(args: _CMD, - bufsize: int = ..., - executable: _PATH = ..., - stdin: _FILE = ..., - stdout: _FILE = ..., - stderr: _FILE = ..., - preexec_fn: Callable[[], Any] = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: Optional[_PATH] = ..., - env: Optional[_ENV] = ..., - universal_newlines: bool = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - check: bool = ..., - encoding: Optional[str] = ..., - errors: Optional[str] = ..., - input: Optional[_TXT] = ..., - timeout: Optional[float] = ...) -> CompletedProcess: ... - else: - # Nearly same args as Popen.__init__ except for timeout, input, and check - def run(args: _CMD, - timeout: Optional[float] = ..., - input: Optional[_TXT] = ..., - check: bool = ..., - bufsize: int = ..., - executable: _PATH = ..., - stdin: _FILE = ..., - stdout: _FILE = ..., - stderr: _FILE = ..., - preexec_fn: Callable[[], Any] = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: Optional[_PATH] = ..., - env: Optional[_ENV] = ..., - universal_newlines: bool = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ...) -> CompletedProcess: ... +class CompletedProcess(Generic[_T]): + # morally: _CMD + args: Any + returncode: int + # These are really both Optional, but requiring checks would be tedious + # and writing all the overloads would be horrific. + stdout: _T + stderr: _T + def __init__(self, args: _CMD, returncode: int, stdout: Optional[_T] = ..., stderr: Optional[_T] = ...) -> None: ... + def check_returncode(self) -> None: ... + +if sys.version_info >= (3, 7): + # Nearly the same args as for 3.6, except for capture_output and text + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ..., + input: Optional[str] = ..., + text: Literal[True], + timeout: Optional[float] = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str, + errors: Optional[str] = ..., + input: Optional[str] = ..., + text: Optional[bool] = ..., + timeout: Optional[float] = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: Optional[str] = ..., + errors: str, + input: Optional[str] = ..., + text: Optional[bool] = ..., + timeout: Optional[float] = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + *, + universal_newlines: Literal[True], + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + # where the *real* keyword only args start + capture_output: bool = ..., + check: bool = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ..., + input: Optional[str] = ..., + text: Optional[bool] = ..., + timeout: Optional[float] = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: Literal[False] = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: None = ..., + errors: None = ..., + input: Optional[bytes] = ..., + text: Literal[None, False] = ..., + timeout: Optional[float] = ..., + ) -> CompletedProcess[bytes]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ..., + input: Optional[_TXT] = ..., + text: Optional[bool] = ..., + timeout: Optional[float] = ..., + ) -> CompletedProcess[Any]: ... +elif sys.version_info >= (3, 6): + # Nearly same args as Popen.__init__ except for timeout, input, and check + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + check: bool = ..., + encoding: str, + errors: Optional[str] = ..., + input: Optional[str] = ..., + timeout: Optional[float] = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + check: bool = ..., + encoding: Optional[str] = ..., + errors: str, + input: Optional[str] = ..., + timeout: Optional[float] = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + *, + universal_newlines: Literal[True], + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + # where the *real* keyword only args start + check: bool = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ..., + input: Optional[str] = ..., + timeout: Optional[float] = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: Literal[False] = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + check: bool = ..., + encoding: None = ..., + errors: None = ..., + input: Optional[bytes] = ..., + timeout: Optional[float] = ..., + ) -> CompletedProcess[bytes]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + check: bool = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ..., + input: Optional[_TXT] = ..., + timeout: Optional[float] = ..., + ) -> CompletedProcess[Any]: ... +else: + # Nearly same args as Popen.__init__ except for timeout, input, and check + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + *, + universal_newlines: Literal[True], + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + # where the *real* keyword only args start + check: bool = ..., + input: Optional[str] = ..., + timeout: Optional[float] = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: Literal[False] = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + check: bool = ..., + input: Optional[bytes] = ..., + timeout: Optional[float] = ..., + ) -> CompletedProcess[bytes]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + check: bool = ..., + input: Optional[_TXT] = ..., + timeout: Optional[float] = ..., + ) -> CompletedProcess[Any]: ... # Same args as Popen.__init__ def call(args: _CMD, @@ -136,7 +452,7 @@ def call(args: _CMD, restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., - timeout: float = ...) -> int: ... + timeout: Optional[float] = ...) -> int: ... # Same args as Popen.__init__ def check_call(args: _CMD, @@ -156,10 +472,11 @@ def check_call(args: _CMD, restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., - timeout: float = ...) -> int: ... + timeout: Optional[float] = ...) -> int: ... if sys.version_info >= (3, 7): # 3.7 added text + @overload def check_output(args: _CMD, bufsize: int = ..., executable: _PATH = ..., @@ -177,7 +494,128 @@ if sys.version_info >= (3, 7): start_new_session: bool = ..., pass_fds: Any = ..., *, - timeout: float = ..., + timeout: Optional[float] = ..., + input: _TXT = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ..., + text: Literal[True], + ) -> str: ... + @overload + def check_output(args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + timeout: Optional[float] = ..., + input: _TXT = ..., + encoding: str, + errors: Optional[str] = ..., + text: Optional[bool] = ..., + ) -> str: ... + @overload + def check_output(args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + timeout: Optional[float] = ..., + input: _TXT = ..., + encoding: Optional[str] = ..., + errors: str, + text: Optional[bool] = ..., + ) -> str: ... + @overload + def check_output(args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + *, + universal_newlines: Literal[True], + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + # where the real keyword only ones start + timeout: Optional[float] = ..., + input: _TXT = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ..., + text: Optional[bool] = ..., + ) -> str: ... + @overload + def check_output(args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: Literal[False] = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + timeout: Optional[float] = ..., + input: _TXT = ..., + encoding: None = ..., + errors: None = ..., + text: Literal[None, False] = ..., + ) -> bytes: ... + @overload + def check_output(args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + timeout: Optional[float] = ..., input: _TXT = ..., encoding: Optional[str] = ..., errors: Optional[str] = ..., @@ -185,6 +623,7 @@ if sys.version_info >= (3, 7): ) -> Any: ... # morally: -> _TXT elif sys.version_info >= (3, 6): # 3.6 added encoding and errors + @overload def check_output(args: _CMD, bufsize: int = ..., executable: _PATH = ..., @@ -202,12 +641,146 @@ elif sys.version_info >= (3, 6): start_new_session: bool = ..., pass_fds: Any = ..., *, - timeout: float = ..., + timeout: Optional[float] = ..., + input: _TXT = ..., + encoding: str, + errors: Optional[str] = ..., + ) -> str: ... + @overload + def check_output(args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + timeout: Optional[float] = ..., + input: _TXT = ..., + encoding: Optional[str] = ..., + errors: str, + ) -> str: ... + @overload + def check_output(args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + universal_newlines: Literal[True], + timeout: Optional[float] = ..., + input: _TXT = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ..., + ) -> str: ... + @overload + def check_output(args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: Literal[False] = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + timeout: Optional[float] = ..., + input: _TXT = ..., + encoding: None = ..., + errors: None = ..., + ) -> bytes: ... + @overload + def check_output(args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + timeout: Optional[float] = ..., input: _TXT = ..., encoding: Optional[str] = ..., errors: Optional[str] = ..., ) -> Any: ... # morally: -> _TXT else: + @overload + def check_output(args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + timeout: Optional[float] = ..., + input: _TXT = ..., + *, + universal_newlines: Literal[True], + ) -> str: ... + @overload + def check_output(args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: Literal[False] = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + timeout: Optional[float] = ..., + input: _TXT = ..., + ) -> bytes: ... + @overload def check_output(args: _CMD, bufsize: int = ..., executable: _PATH = ..., @@ -224,7 +797,7 @@ else: restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., - timeout: float = ..., + timeout: Optional[float] = ..., input: _TXT = ..., ) -> Any: ... # morally: -> _TXT @@ -251,10 +824,9 @@ class CalledProcessError(Exception): # morally: Optional[_TXT] output: Any - if sys.version_info >= (3, 5): - # morally: Optional[_TXT] - stdout: Any - stderr: Any + # morally: Optional[_TXT] + stdout: Any + stderr: Any def __init__(self, returncode: int, @@ -262,69 +834,344 @@ class CalledProcessError(Exception): output: Optional[_TXT] = ..., stderr: Optional[_TXT] = ...) -> None: ... -class Popen: +class Popen(Generic[AnyStr]): args: _CMD - stdin: IO[Any] - stdout: IO[Any] - stderr: IO[Any] + stdin: IO[AnyStr] + stdout: IO[AnyStr] + stderr: IO[AnyStr] pid = 0 returncode = 0 - if sys.version_info >= (3, 6): - def __init__(self, - args: _CMD, - bufsize: int = ..., - executable: Optional[_PATH] = ..., - stdin: Optional[_FILE] = ..., - stdout: Optional[_FILE] = ..., - stderr: Optional[_FILE] = ..., - preexec_fn: Optional[Callable[[], Any]] = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: Optional[_PATH] = ..., - env: Optional[_ENV] = ..., - universal_newlines: bool = ..., - startupinfo: Optional[Any] = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - encoding: Optional[str] = ..., - errors: Optional[str] = ...) -> None: ... + # Technically it is wrong that Popen provides __new__ instead of __init__ + # but this shouldn't come up hopefully? + + if sys.version_info >= (3, 7): + # text is added in 3.7 + @overload + def __new__(cls, + args: _CMD, + bufsize: int = ..., + executable: Optional[_PATH] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Optional[Any] = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + text: Optional[bool] = ..., + encoding: str, + errors: Optional[str] = ...) -> Popen[str]: ... + @overload + def __new__(cls, + args: _CMD, + bufsize: int = ..., + executable: Optional[_PATH] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Optional[Any] = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + text: Optional[bool] = ..., + encoding: Optional[str] = ..., + errors: str) -> Popen[str]: ... + @overload + def __new__(cls, + args: _CMD, + bufsize: int = ..., + executable: Optional[_PATH] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + *, + universal_newlines: Literal[True], + startupinfo: Optional[Any] = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + # where the *real* keyword only args start + text: Optional[bool] = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ...) -> Popen[str]: ... + @overload + def __new__(cls, + args: _CMD, + bufsize: int = ..., + executable: Optional[_PATH] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Optional[Any] = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + text: Literal[True], + encoding: Optional[str] = ..., + errors: Optional[str] = ...) -> Popen[str]: ... + @overload + def __new__(cls, + args: _CMD, + bufsize: int = ..., + executable: Optional[_PATH] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: Literal[False] = ..., + startupinfo: Optional[Any] = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + text: Literal[None, False] = ..., + encoding: None = ..., + errors: None = ...) -> Popen[bytes]: ... + @overload + def __new__(cls, + args: _CMD, + bufsize: int = ..., + executable: Optional[_PATH] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Optional[Any] = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + text: Optional[bool] = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ...) -> Popen[Any]: ... + elif sys.version_info >= (3, 6): + @overload + def __new__(cls, + args: _CMD, + bufsize: int = ..., + executable: Optional[_PATH] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Optional[Any] = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + encoding: str, + errors: Optional[str] = ...) -> Popen[str]: ... + @overload + def __new__(cls, + args: _CMD, + bufsize: int = ..., + executable: Optional[_PATH] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Optional[Any] = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + encoding: Optional[str] = ..., + errors: str) -> Popen[str]: ... + @overload + def __new__(cls, + args: _CMD, + bufsize: int = ..., + executable: Optional[_PATH] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + *, + universal_newlines: Literal[True], + startupinfo: Optional[Any] = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + # where the *real* keyword only args start + encoding: Optional[str] = ..., + errors: Optional[str] = ...) -> Popen[str]: ... + @overload + def __new__(cls, + args: _CMD, + bufsize: int = ..., + executable: Optional[_PATH] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: Literal[False] = ..., + startupinfo: Optional[Any] = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + encoding: None = ..., + errors: None = ...) -> Popen[bytes]: ... + @overload + def __new__(cls, + args: _CMD, + bufsize: int = ..., + executable: Optional[_PATH] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Optional[Any] = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + encoding: Optional[str] = ..., + errors: Optional[str] = ...) -> Popen[Any]: ... else: - def __init__(self, - args: _CMD, - bufsize: int = ..., - executable: Optional[_PATH] = ..., - stdin: Optional[_FILE] = ..., - stdout: Optional[_FILE] = ..., - stderr: Optional[_FILE] = ..., - preexec_fn: Optional[Callable[[], Any]] = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: Optional[_PATH] = ..., - env: Optional[_ENV] = ..., - universal_newlines: bool = ..., - startupinfo: Optional[Any] = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ...) -> None: ... + @overload + def __new__(cls, + args: _CMD, + bufsize: int = ..., + executable: Optional[_PATH] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + *, + universal_newlines: Literal[True], + startupinfo: Optional[Any] = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ...) -> Popen[str]: ... + @overload + def __new__(cls, + args: _CMD, + bufsize: int = ..., + executable: Optional[_PATH] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + *, + universal_newlines: Literal[False] = ..., + startupinfo: Optional[Any] = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ...) -> Popen[bytes]: ... + @overload + def __new__(cls, + args: _CMD, + bufsize: int = ..., + executable: Optional[_PATH] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Optional[Any] = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ...) -> Popen[Any]: ... def poll(self) -> int: ... def wait(self, timeout: Optional[float] = ...) -> int: ... # Return str/bytes def communicate(self, - input: Optional[_TXT] = ..., + input: Optional[AnyStr] = ..., timeout: Optional[float] = ..., - # morally: -> Tuple[Optional[_TXT], Optional[_TXT]] - ) -> Tuple[Any, Any]: ... + # morally this should be optional + ) -> Tuple[AnyStr, AnyStr]: ... def send_signal(self, signal: int) -> None: ... def terminate(self) -> None: ... def kill(self) -> None: ... - def __enter__(self) -> Popen: ... - def __exit__(self, type: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> bool: ... + def __enter__(self: _S) -> _S: ... + def __exit__(self, type: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> None: ... # The result really is always a str. def getstatusoutput(cmd: _TXT) -> Tuple[int, str]: ... diff --git a/stdlib/3/symbol.pyi b/stdlib/3/symbol.pyi index 0cf5f1cdff28..59be5776560b 100644 --- a/stdlib/3/symbol.pyi +++ b/stdlib/3/symbol.pyi @@ -9,8 +9,7 @@ eval_input: int decorator: int decorators: int decorated: int -if sys.version_info >= (3, 5): - async_funcdef: int +async_funcdef: int funcdef: int parameters: int typedargslist: int @@ -45,8 +44,7 @@ global_stmt: int nonlocal_stmt: int assert_stmt: int compound_stmt: int -if sys.version_info >= (3, 5): - async_stmt: int +async_stmt: int if_stmt: int while_stmt: int for_stmt: int @@ -73,8 +71,7 @@ arith_expr: int term: int factor: int power: int -if sys.version_info >= (3, 5): - atom_expr: int +atom_expr: int atom: int testlist_comp: int trailer: int diff --git a/stdlib/3/sys.pyi b/stdlib/3/sys.pyi index 3f856bbc9c76..48644328d056 100644 --- a/stdlib/3/sys.pyi +++ b/stdlib/3/sys.pyi @@ -16,7 +16,7 @@ _T = TypeVar('_T') # The following type alias are stub-only and do not exist during runtime _ExcInfo = Tuple[Type[BaseException], BaseException, TracebackType] -_OptExcInfo = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]] +_OptExcInfo = Union[_ExcInfo, Tuple[None, None, None]] # ----- sys variables ----- abiflags: str @@ -83,6 +83,7 @@ class _flags: hash_randomization: int if sys.version_info >= (3, 7): dev_mode: int + utf8_mode: int float_info: _float_info class _float_info: @@ -185,8 +186,7 @@ def getwindowsversion() -> _WinVersion: ... # Windows only def intern(string: str) -> str: ... -if sys.version_info >= (3, 5): - def is_finalizing() -> bool: ... +def is_finalizing() -> bool: ... if sys.version_info >= (3, 7): __breakpointhook__: Any # contains the original value of breakpointhook diff --git a/stdlib/3/tempfile.pyi b/stdlib/3/tempfile.pyi index e041b44e7bc7..5d66a47a1b43 100644 --- a/stdlib/3/tempfile.pyi +++ b/stdlib/3/tempfile.pyi @@ -3,121 +3,149 @@ # based on http://docs.python.org/3.3/library/tempfile.html +import os import sys from types import TracebackType -from typing import Any, AnyStr, Generic, IO, Iterable, Iterator, List, Optional, overload, Tuple, Type +from typing import Any, AnyStr, Generic, IO, Iterable, Iterator, List, Optional, overload, Tuple, Type, TypeVar, Union + +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal # global variables TMP_MAX: int tempdir: Optional[str] template: str +_S = TypeVar("_S") +_T = TypeVar("_T") # for pytype, define typevar in same file as alias +if sys.version_info >= (3, 6): + _DirT = Union[_T, os.PathLike[_T]] +else: + _DirT = Union[_T] -if sys.version_info >= (3, 5): - def TemporaryFile( - mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., - newline: Optional[str] = ..., suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., - dir: Optional[AnyStr] = ... - ) -> IO[Any]: - ... - def NamedTemporaryFile( - mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., - newline: Optional[str] = ..., suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., - dir: Optional[AnyStr] = ..., delete: bool = ... - ) -> IO[Any]: - ... - - # It does not actually derive from IO[AnyStr], but it does implement the - # protocol. - class SpooledTemporaryFile(IO[AnyStr]): - def __init__(self, max_size: int = ..., mode: str = ..., - buffering: int = ..., encoding: Optional[str] = ..., - newline: Optional[str] = ..., suffix: Optional[str] = ..., - prefix: Optional[str] = ..., dir: Optional[str] = ... - ) -> None: ... - def rollover(self) -> None: ... - def __enter__(self) -> SpooledTemporaryFile: ... - def __exit__(self, exc_type: Optional[Type[BaseException]], - exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... +@overload +def TemporaryFile( + mode: Literal["r", "w", "a", "x", "r+", "w+", "a+", "x+", "rt", "wt", "at", "xt", "r+t", "w+t", "a+t", "x+t"], + buffering: int = ..., + encoding: Optional[str] = ..., + newline: Optional[str] = ..., + suffix: Optional[AnyStr] = ..., + prefix: Optional[AnyStr] = ..., + dir: Optional[_DirT[AnyStr]] = ..., +) -> IO[str]: ... +@overload +def TemporaryFile( + mode: Literal["rb", "wb", "ab", "xb", "r+b", "w+b", "a+b", "x+b"] = ..., + buffering: int = ..., + encoding: Optional[str] = ..., + newline: Optional[str] = ..., + suffix: Optional[AnyStr] = ..., + prefix: Optional[AnyStr] = ..., + dir: Optional[_DirT[AnyStr]] = ..., +) -> IO[bytes]: ... +@overload +def TemporaryFile( + mode: str = ..., + buffering: int = ..., + encoding: Optional[str] = ..., + newline: Optional[str] = ..., + suffix: Optional[AnyStr] = ..., + prefix: Optional[AnyStr] = ..., + dir: Optional[_DirT[AnyStr]] = ..., +) -> IO[Any]: ... - # These methods are copied from the abstract methods of IO, because - # SpooledTemporaryFile implements IO. - # See also https://github.com/python/typeshed/pull/2452#issuecomment-420657918. - def close(self) -> None: ... - def fileno(self) -> int: ... - def flush(self) -> None: ... - def isatty(self) -> bool: ... - def read(self, n: int = ...) -> AnyStr: ... - def readable(self) -> bool: ... - def readline(self, limit: int = ...) -> AnyStr: ... - def readlines(self, hint: int = ...) -> List[AnyStr]: ... - def seek(self, offset: int, whence: int = ...) -> int: ... - def seekable(self) -> bool: ... - def tell(self) -> int: ... - def truncate(self, size: Optional[int] = ...) -> int: ... - def writable(self) -> bool: ... - def write(self, s: AnyStr) -> int: ... - def writelines(self, lines: Iterable[AnyStr]) -> None: ... - def __next__(self) -> AnyStr: ... - def __iter__(self) -> Iterator[AnyStr]: ... +@overload +def NamedTemporaryFile( + mode: Literal["r", "w", "a", "x", "r+", "w+", "a+", "x+", "rt", "wt", "at", "xt", "r+t", "w+t", "a+t", "x+t"], + buffering: int = ..., + encoding: Optional[str] = ..., + newline: Optional[str] = ..., + suffix: Optional[AnyStr] = ..., + prefix: Optional[AnyStr] = ..., + dir: Optional[_DirT[AnyStr]] = ..., + delete: bool = ..., +) -> IO[str]: ... +@overload +def NamedTemporaryFile( + mode: Literal["rb", "wb", "ab", "xb", "r+b", "w+b", "a+b", "x+b"] = ..., + buffering: int = ..., + encoding: Optional[str] = ..., + newline: Optional[str] = ..., + suffix: Optional[AnyStr] = ..., + prefix: Optional[AnyStr] = ..., + dir: Optional[_DirT[AnyStr]] = ..., + delete: bool = ..., +) -> IO[bytes]: ... +@overload +def NamedTemporaryFile( + mode: str = ..., + buffering: int = ..., + encoding: Optional[str] = ..., + newline: Optional[str] = ..., + suffix: Optional[AnyStr] = ..., + prefix: Optional[AnyStr] = ..., + dir: Optional[_DirT[AnyStr]] = ..., + delete: bool = ..., +) -> IO[Any]: ... - class TemporaryDirectory(Generic[AnyStr]): - name: str - def __init__(self, suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., - dir: Optional[AnyStr] = ...) -> None: ... - def cleanup(self) -> None: ... - def __enter__(self) -> AnyStr: ... - def __exit__(self, exc_type: Optional[Type[BaseException]], - exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... +# It does not actually derive from IO[AnyStr], but it does implement the +# protocol. +class SpooledTemporaryFile(IO[AnyStr]): + def __init__(self, max_size: int = ..., mode: str = ..., + buffering: int = ..., encoding: Optional[str] = ..., + newline: Optional[str] = ..., suffix: Optional[str] = ..., + prefix: Optional[str] = ..., dir: Optional[str] = ... + ) -> None: ... + def rollover(self) -> None: ... + def __enter__(self: _S) -> _S: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> Optional[bool]: ... - def mkstemp(suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., dir: Optional[AnyStr] = ..., - text: bool = ...) -> Tuple[int, AnyStr]: ... - @overload - def mkdtemp() -> str: ... - @overload - def mkdtemp(suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., - dir: Optional[AnyStr] = ...) -> AnyStr: ... - def mktemp(suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., dir: Optional[AnyStr] = ...) -> AnyStr: ... + # These methods are copied from the abstract methods of IO, because + # SpooledTemporaryFile implements IO. + # See also https://github.com/python/typeshed/pull/2452#issuecomment-420657918. + def close(self) -> None: ... + def fileno(self) -> int: ... + def flush(self) -> None: ... + def isatty(self) -> bool: ... + def read(self, n: int = ...) -> AnyStr: ... + def readable(self) -> bool: ... + def readline(self, limit: int = ...) -> AnyStr: ... + def readlines(self, hint: int = ...) -> List[AnyStr]: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def seekable(self) -> bool: ... + def tell(self) -> int: ... + def truncate(self, size: Optional[int] = ...) -> int: ... + def writable(self) -> bool: ... + def write(self, s: AnyStr) -> int: ... + def writelines(self, lines: Iterable[AnyStr]) -> None: ... + def __next__(self) -> AnyStr: ... + def __iter__(self) -> Iterator[AnyStr]: ... - def gettempdirb() -> bytes: ... - def gettempprefixb() -> bytes: ... -else: - def TemporaryFile( - mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., - newline: Optional[str] = ..., suffix: str = ..., prefix: str = ..., - dir: Optional[str] = ... - ) -> IO[Any]: - ... - def NamedTemporaryFile( - mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., - newline: Optional[str] = ..., suffix: str = ..., prefix: str = ..., - dir: Optional[str] = ..., delete: bool = ... - ) -> IO[Any]: - ... - def SpooledTemporaryFile( - max_size: int = ..., mode: str = ..., buffering: int = ..., - encoding: str = ..., newline: str = ..., suffix: str = ..., - prefix: str = ..., dir: Optional[str] = ... - ) -> IO[Any]: - ... +class TemporaryDirectory(Generic[AnyStr]): + name: str + def __init__(self, suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., + dir: Optional[_DirT[AnyStr]] = ...) -> None: ... + def cleanup(self) -> None: ... + def __enter__(self) -> AnyStr: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> None: ... - class TemporaryDirectory: - name: str - def __init__(self, suffix: str = ..., prefix: str = ..., - dir: Optional[str] = ...) -> None: ... - def cleanup(self) -> None: ... - def __enter__(self) -> str: ... - def __exit__(self, exc_type: Optional[Type[BaseException]], - exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... +def mkstemp(suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., dir: Optional[_DirT[AnyStr]] = ..., + text: bool = ...) -> Tuple[int, AnyStr]: ... +@overload +def mkdtemp() -> str: ... +@overload +def mkdtemp(suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., + dir: Optional[_DirT[AnyStr]] = ...) -> AnyStr: ... +def mktemp(suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., dir: Optional[_DirT[AnyStr]] = ...) -> AnyStr: ... - def mkstemp(suffix: str = ..., prefix: str = ..., dir: Optional[str] = ..., - text: bool = ...) -> Tuple[int, str]: ... - def mkdtemp(suffix: str = ..., prefix: str = ..., - dir: Optional[str] = ...) -> str: ... - def mktemp(suffix: str = ..., prefix: str = ..., dir: Optional[str] = ...) -> str: ... +def gettempdirb() -> bytes: ... +def gettempprefixb() -> bytes: ... def gettempdir() -> str: ... def gettempprefix() -> str: ... diff --git a/stdlib/3/tokenize.pyi b/stdlib/3/tokenize.pyi index 33c8a2d5d258..b3c5fd9641b6 100644 --- a/stdlib/3/tokenize.pyi +++ b/stdlib/3/tokenize.pyi @@ -3,9 +3,10 @@ from builtins import open as _builtin_open import sys from token import * # noqa: F403 -COMMENT: int -NL: int -ENCODING: int +if sys.version_info < (3, 7): + COMMENT: int + NL: int + ENCODING: int _Position = Tuple[int, int] @@ -44,7 +45,7 @@ def generate_tokens(readline: Callable[[], str]) -> Generator[TokenInfo, None, N if sys.version_info >= (3, 6): from os import PathLike - def open(filename: Union[str, bytes, int, PathLike]) -> TextIO: ... + def open(filename: Union[str, bytes, int, PathLike[Any]]) -> TextIO: ... else: def open(filename: Union[str, bytes, int]) -> TextIO: ... diff --git a/stdlib/3/types.pyi b/stdlib/3/types.pyi index 73b88899c53f..61f87832ad9e 100644 --- a/stdlib/3/types.pyi +++ b/stdlib/3/types.pyi @@ -6,7 +6,7 @@ import sys from typing import ( Any, Awaitable, Callable, Dict, Generic, Iterator, Mapping, Optional, Tuple, TypeVar, - Union, overload, Type + Union, overload, Type, Iterable ) # ModuleType is exported from this module, but for circular import @@ -147,7 +147,7 @@ class MethodType: __self__: object __name__: str __qualname__: str - def __init__(self, func: Callable, obj: object) -> None: ... + def __init__(self, func: Callable[..., Any], obj: object) -> None: ... def __call__(self, *args: Any, **kwargs: Any) -> Any: ... class BuiltinFunctionType: __self__: Union[object, ModuleType] @@ -156,6 +156,38 @@ class BuiltinFunctionType: def __call__(self, *args: Any, **kwargs: Any) -> Any: ... BuiltinMethodType = BuiltinFunctionType +if sys.version_info >= (3, 7): + class WrapperDescriptorType: + __name__: str + __qualname__: str + __objclass__: type + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __get__(self, obj: Any, type: type = ...) -> Any: ... + + class MethodWrapperType: + __self__: object + __name__: str + __qualname__: str + __objclass__: type + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + + class MethodDescriptorType: + __name__: str + __qualname__: str + __objclass__: type + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __get__(self, obj: Any, type: type = ...) -> Any: ... + + class ClassMethodDescriptorType: + __name__: str + __qualname__: str + __objclass__: type + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __get__(self, obj: Any, type: type = ...) -> Any: ... + + class TracebackType: if sys.version_info >= (3, 7): def __init__(self, tb_next: Optional[TracebackType], tb_frame: FrameType, tb_lasti: int, tb_lineno: int) -> None: ... @@ -199,7 +231,11 @@ class MemberDescriptorType: def __set__(self, obj: Any) -> None: ... def __delete__(self, obj: Any) -> None: ... -def new_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ..., exec_body: Callable[[Dict[str, Any]], None] = ...) -> type: ... +if sys.version_info >= (3, 7): + def new_class(name: str, bases: Iterable[object] = ..., kwds: Dict[str, Any] = ..., exec_body: Callable[[Dict[str, Any]], None] = ...) -> type: ... + def resolve_bases(bases: Iterable[object]) -> Tuple[Any, ...]: ... +else: + def new_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ..., exec_body: Callable[[Dict[str, Any]], None] = ...) -> type: ... def prepare_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ...) -> Tuple[type, Dict[str, Any], Dict[str, Any]]: ... # Actually a different type, but `property` is special and we want that too. diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index e83640a73d1e..fb279c01f46b 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -23,6 +23,13 @@ Protocol: _SpecialForm = ... Callable: _SpecialForm = ... Type: _SpecialForm = ... ClassVar: _SpecialForm = ... +if sys.version_info >= (3, 8): + Final: _SpecialForm = ... + _F = TypeVar('_F', bound=Callable[..., Any]) + def final(f: _F) -> _F: ... + Literal: _SpecialForm = ... + # TypedDict is a (non-subscriptable) special form. + TypedDict: object = ... class GenericMeta(type): ... @@ -49,6 +56,9 @@ Counter = TypeAlias(object) Deque = TypeAlias(object) ChainMap = TypeAlias(object) +if sys.version_info >= (3, 7): + OrderedDict = TypeAlias(object) + # Predefined type variables. AnyStr = TypeVar('AnyStr', str, bytes) @@ -65,36 +75,36 @@ _KT_co = TypeVar('_KT_co', covariant=True) # Key type covariant containers. _VT_co = TypeVar('_VT_co', covariant=True) # Value type covariant containers. _T_contra = TypeVar('_T_contra', contravariant=True) # Ditto contravariant. _TC = TypeVar('_TC', bound=Type[object]) -_C = TypeVar("_C", bound=Callable) +_C = TypeVar("_C", bound=Callable[..., Any]) -def runtime(cls: _TC) -> _TC: ... +def runtime_checkable(cls: _TC) -> _TC: ... -@runtime +@runtime_checkable class SupportsInt(Protocol, metaclass=ABCMeta): @abstractmethod def __int__(self) -> int: ... -@runtime +@runtime_checkable class SupportsFloat(Protocol, metaclass=ABCMeta): @abstractmethod def __float__(self) -> float: ... -@runtime +@runtime_checkable class SupportsComplex(Protocol, metaclass=ABCMeta): @abstractmethod def __complex__(self) -> complex: ... -@runtime +@runtime_checkable class SupportsBytes(Protocol, metaclass=ABCMeta): @abstractmethod def __bytes__(self) -> bytes: ... -@runtime +@runtime_checkable class SupportsAbs(Protocol[_T_co]): @abstractmethod def __abs__(self) -> _T_co: ... -@runtime +@runtime_checkable class SupportsRound(Protocol[_T_co]): @overload @abstractmethod @@ -103,17 +113,17 @@ class SupportsRound(Protocol[_T_co]): @abstractmethod def __round__(self, ndigits: int) -> _T_co: ... -@runtime +@runtime_checkable class Reversible(Protocol[_T_co]): @abstractmethod def __reversed__(self) -> Iterator[_T_co]: ... -@runtime +@runtime_checkable class Sized(Protocol, metaclass=ABCMeta): @abstractmethod def __len__(self) -> int: ... -@runtime +@runtime_checkable class Hashable(Protocol, metaclass=ABCMeta): # TODO: This is special, in that a subclass of a hashable class may not be hashable # (for example, list vs. object). It's not obvious how to represent this. This class @@ -121,12 +131,12 @@ class Hashable(Protocol, metaclass=ABCMeta): @abstractmethod def __hash__(self) -> int: ... -@runtime +@runtime_checkable class Iterable(Protocol[_T_co]): @abstractmethod def __iter__(self) -> Iterator[_T_co]: ... -@runtime +@runtime_checkable class Iterator(Iterable[_T_co], Protocol[_T_co]): @abstractmethod def __next__(self) -> _T_co: ... @@ -156,13 +166,9 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]): @property def gi_running(self) -> bool: ... @property - def gi_yieldfrom(self) -> Optional[Generator]: ... - -# TODO: Several types should only be defined if sys.python_version >= (3, 5): -# Awaitable, AsyncIterator, AsyncIterable, Coroutine, Collection. -# See https: //github.com/python/typeshed/issues/655 for why this is not easy. + def gi_yieldfrom(self) -> Optional[Generator[Any, Any, Any]]: ... -@runtime +@runtime_checkable class Awaitable(Protocol[_T_co]): @abstractmethod def __await__(self) -> Generator[Any, None, _T_co]: ... @@ -193,12 +199,12 @@ class Coroutine(Awaitable[_V_co], Generic[_T_co, _T_contra, _V_co]): class AwaitableGenerator(Awaitable[_V_co], Generator[_T_co, _T_contra, _V_co], Generic[_T_co, _T_contra, _V_co, _S], metaclass=ABCMeta): ... -@runtime +@runtime_checkable class AsyncIterable(Protocol[_T_co]): @abstractmethod def __aiter__(self) -> AsyncIterator[_T_co]: ... -@runtime +@runtime_checkable class AsyncIterator(AsyncIterable[_T_co], Protocol[_T_co]): @abstractmethod @@ -232,14 +238,14 @@ if sys.version_info >= (3, 6): @property def ag_running(self) -> bool: ... -@runtime +@runtime_checkable class Container(Protocol[_T_co]): @abstractmethod def __contains__(self, __x: object) -> bool: ... if sys.version_info >= (3, 6): - @runtime + @runtime_checkable class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]): # Implement Sized (but don't have it as a base class). @abstractmethod @@ -247,7 +253,7 @@ if sys.version_info >= (3, 6): _Collection = Collection else: - @runtime + @runtime_checkable class _Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]): # Implement Sized (but don't have it as a base class). @abstractmethod @@ -261,10 +267,7 @@ class Sequence(_Collection[_T_co], Reversible[_T_co], Generic[_T_co]): @abstractmethod def __getitem__(self, s: slice) -> Sequence[_T_co]: ... # Mixin methods - if sys.version_info >= (3, 5): - def index(self, x: Any, start: int = ..., end: int = ...) -> int: ... - else: - def index(self, x: Any) -> int: ... + def index(self, x: Any, start: int = ..., end: int = ...) -> int: ... def count(self, x: Any) -> int: ... def __contains__(self, x: object) -> bool: ... def __iter__(self) -> Iterator[_T_co]: ... @@ -332,47 +335,49 @@ class MappingView: def __len__(self) -> int: ... class ItemsView(MappingView, AbstractSet[Tuple[_KT_co, _VT_co]], Generic[_KT_co, _VT_co]): - def __and__(self, o: Iterable[_T]) -> AbstractSet[Union[Tuple[_KT_co, _VT_co], _T]]: ... - def __rand__(self, o: Iterable[_T]) -> AbstractSet[Union[Tuple[_KT_co, _VT_co], _T]]: ... + def __and__(self, o: Iterable[Any]) -> Set[Tuple[_KT_co, _VT_co]]: ... + def __rand__(self, o: Iterable[_T]) -> Set[_T]: ... def __contains__(self, o: object) -> bool: ... def __iter__(self) -> Iterator[Tuple[_KT_co, _VT_co]]: ... - def __or__(self, o: Iterable[_T]) -> AbstractSet[Union[Tuple[_KT_co, _VT_co], _T]]: ... - def __ror__(self, o: Iterable[_T]) -> AbstractSet[Union[Tuple[_KT_co, _VT_co], _T]]: ... - def __sub__(self, o: Iterable[_T]) -> AbstractSet[Union[Tuple[_KT_co, _VT_co], _T]]: ... - def __rsub__(self, o: Iterable[_T]) -> AbstractSet[Union[Tuple[_KT_co, _VT_co], _T]]: ... - def __xor__(self, o: Iterable[_T]) -> AbstractSet[Union[Tuple[_KT_co, _VT_co], _T]]: ... - def __rxor__(self, o: Iterable[_T]) -> AbstractSet[Union[Tuple[_KT_co, _VT_co], _T]]: ... + def __or__(self, o: Iterable[_T]) -> Set[Union[Tuple[_KT_co, _VT_co], _T]]: ... + def __ror__(self, o: Iterable[_T]) -> Set[Union[Tuple[_KT_co, _VT_co], _T]]: ... + def __sub__(self, o: Iterable[Any]) -> Set[Tuple[_KT_co, _VT_co]]: ... + def __rsub__(self, o: Iterable[_T]) -> Set[_T]: ... + def __xor__(self, o: Iterable[_T]) -> Set[Union[Tuple[_KT_co, _VT_co], _T]]: ... + def __rxor__(self, o: Iterable[_T]) -> Set[Union[Tuple[_KT_co, _VT_co], _T]]: ... class KeysView(MappingView, AbstractSet[_KT_co], Generic[_KT_co]): - def __and__(self, o: Iterable[_T]) -> AbstractSet[Union[_KT_co, _T]]: ... - def __rand__(self, o: Iterable[_T]) -> AbstractSet[Union[_KT_co, _T]]: ... + def __and__(self, o: Iterable[Any]) -> Set[_KT_co]: ... + def __rand__(self, o: Iterable[_T]) -> Set[_T]: ... def __contains__(self, o: object) -> bool: ... def __iter__(self) -> Iterator[_KT_co]: ... - def __or__(self, o: Iterable[_T]) -> AbstractSet[Union[_KT_co, _T]]: ... - def __ror__(self, o: Iterable[_T]) -> AbstractSet[Union[_KT_co, _T]]: ... - def __sub__(self, o: Iterable[_T]) -> AbstractSet[Union[_KT_co, _T]]: ... - def __rsub__(self, o: Iterable[_T]) -> AbstractSet[Union[_KT_co, _T]]: ... - def __xor__(self, o: Iterable[_T]) -> AbstractSet[Union[_KT_co, _T]]: ... - def __rxor__(self, o: Iterable[_T]) -> AbstractSet[Union[_KT_co, _T]]: ... + def __or__(self, o: Iterable[_T]) -> Set[Union[_KT_co, _T]]: ... + def __ror__(self, o: Iterable[_T]) -> Set[Union[_KT_co, _T]]: ... + def __sub__(self, o: Iterable[Any]) -> Set[_KT_co]: ... + def __rsub__(self, o: Iterable[_T]) -> Set[_T]: ... + def __xor__(self, o: Iterable[_T]) -> Set[Union[_KT_co, _T]]: ... + def __rxor__(self, o: Iterable[_T]) -> Set[Union[_KT_co, _T]]: ... class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]): def __contains__(self, o: object) -> bool: ... def __iter__(self) -> Iterator[_VT_co]: ... -@runtime +@runtime_checkable class ContextManager(Protocol[_T_co]): def __enter__(self) -> _T_co: ... def __exit__(self, __exc_type: Optional[Type[BaseException]], __exc_value: Optional[BaseException], __traceback: Optional[TracebackType]) -> Optional[bool]: ... -if sys.version_info >= (3, 5): - @runtime - class AsyncContextManager(Protocol[_T_co]): - def __aenter__(self) -> Awaitable[_T_co]: ... - def __aexit__(self, exc_type: Optional[Type[BaseException]], - exc_value: Optional[BaseException], - traceback: Optional[TracebackType]) -> Awaitable[Optional[bool]]: ... +@runtime_checkable +class AsyncContextManager(Protocol[_T_co]): + def __aenter__(self) -> Awaitable[_T_co]: ... + def __aexit__( + self, + exc_type: Optional[Type[BaseException]], + exc_value: Optional[BaseException], + traceback: Optional[TracebackType], + ) -> Awaitable[Optional[bool]]: ... class Mapping(_Collection[_KT], Generic[_KT, _VT_co]): # TODO: We wish the key type could also be covariant, but that doesn't work, @@ -474,7 +479,7 @@ class IO(Iterator[AnyStr], Generic[AnyStr]): def __enter__(self) -> IO[AnyStr]: ... @abstractmethod def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException], - traceback: Optional[TracebackType]) -> bool: ... + traceback: Optional[TracebackType]) -> Optional[bool]: ... class BinaryIO(IO[bytes]): # TODO readinto @@ -510,8 +515,8 @@ class ByteString(Sequence[int], metaclass=ABCMeta): ... class Match(Generic[AnyStr]): pos = 0 endpos = 0 - lastindex = 0 - lastgroup: AnyStr + lastindex: Optional[int] + lastgroup: Optional[AnyStr] string: AnyStr # The regular expression object whose match() or search() method produced @@ -520,22 +525,24 @@ class Match(Generic[AnyStr]): def expand(self, template: AnyStr) -> AnyStr: ... + # TODO: The return for a group may be None, except if __group is 0 or not given. @overload - def group(self, group1: int = ...) -> AnyStr: ... - @overload - def group(self, group1: str) -> AnyStr: ... + def group(self, __group: Union[str, int] = ...) -> AnyStr: ... @overload - def group(self, group1: int, group2: int, - *groups: int) -> Sequence[AnyStr]: ... - @overload - def group(self, group1: str, group2: str, - *groups: str) -> Sequence[AnyStr]: ... + def group( + self, + __group1: Union[str, int], + __group2: Union[str, int], + *groups: Union[str, int], + ) -> Tuple[AnyStr, ...]: ... def groups(self, default: AnyStr = ...) -> Sequence[AnyStr]: ... def groupdict(self, default: AnyStr = ...) -> dict[str, AnyStr]: ... def start(self, group: Union[int, str] = ...) -> int: ... def end(self, group: Union[int, str] = ...) -> int: ... def span(self, group: Union[int, str] = ...) -> Tuple[int, int]: ... + @property + def regs(self) -> Tuple[Tuple[int, int], ...]: ... # undocumented if sys.version_info >= (3, 6): def __getitem__(self, g: Union[int, str]) -> AnyStr: ... @@ -574,8 +581,9 @@ class Pattern(Generic[AnyStr]): # Functions -def get_type_hints(obj: Callable, globalns: Optional[dict[str, Any]] = ..., - localns: Optional[dict[str, Any]] = ...) -> dict[str, Any]: ... +def get_type_hints( + obj: Callable[..., Any], globalns: Optional[Dict[str, Any]] = ..., localns: Optional[Dict[str, Any]] = ..., +) -> Dict[str, Any]: ... @overload def cast(tp: Type[_T], obj: Any) -> _T: ... @@ -585,7 +593,7 @@ def cast(tp: str, obj: Any) -> Any: ... # Type constructors # NamedTuple is special-cased in the type checker -class NamedTuple(tuple): +class NamedTuple(Tuple[Any, ...]): _field_types: collections.OrderedDict[str, Type[Any]] _field_defaults: Dict[str, Any] = ... _fields: Tuple[str, ...] @@ -600,6 +608,17 @@ class NamedTuple(tuple): def _asdict(self) -> collections.OrderedDict[str, Any]: ... def _replace(self: _T, **kwargs: Any) -> _T: ... +# Internal mypy fallback type for all typed dicts (does not exist at runtime) +class _TypedDict(Mapping[str, object], metaclass=ABCMeta): + def copy(self: _T) -> _T: ... + # Using NoReturn so that only calls using mypy plugin hook that specialize the signature + # can go through. + def setdefault(self, k: NoReturn, default: object) -> object: ... + # Mypy plugin hook for 'pop' expects that 'default' has a type variable type. + def pop(self, k: NoReturn, default: _T = ...) -> object: ... + def update(self: _T, __m: _T) -> None: ... + def __delitem__(self, k: NoReturn) -> None: ... + def NewType(name: str, tp: Type[_T]) -> Type[_T]: ... # This itself is only available during type checking diff --git a/stdlib/3/unittest/case.pyi b/stdlib/3/unittest/case.pyi index f71e5e4e8b7f..2e9e523c3ae1 100644 --- a/stdlib/3/unittest/case.pyi +++ b/stdlib/3/unittest/case.pyi @@ -214,11 +214,11 @@ class _AssertWarnsContext: lineno: int def __enter__(self) -> _AssertWarnsContext: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... + exc_tb: Optional[TracebackType]) -> None: ... class _AssertLogsContext: records: List[logging.LogRecord] output: List[str] def __enter__(self) -> _AssertLogsContext: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... + exc_tb: Optional[TracebackType]) -> Optional[bool]: ... diff --git a/stdlib/3/unittest/loader.pyi b/stdlib/3/unittest/loader.pyi index 53b81ad72db2..d32c7132bdb1 100644 --- a/stdlib/3/unittest/loader.pyi +++ b/stdlib/3/unittest/loader.pyi @@ -7,19 +7,13 @@ from typing import Any, Callable, List, Optional, Sequence, Type class TestLoader: - if sys.version_info >= (3, 5): - errors: List[Type[BaseException]] + errors: List[Type[BaseException]] testMethodPrefix: str sortTestMethodsUsing: Callable[[str, str], bool] suiteClass: Callable[[List[unittest.case.TestCase]], unittest.suite.TestSuite] def loadTestsFromTestCase(self, testCaseClass: Type[unittest.case.TestCase]) -> unittest.suite.TestSuite: ... - if sys.version_info >= (3, 5): - def loadTestsFromModule(self, module: ModuleType, - *, pattern: Any = ...) -> unittest.suite.TestSuite: ... - else: - def loadTestsFromModule(self, - module: ModuleType) -> unittest.suite.TestSuite: ... + def loadTestsFromModule(self, module: ModuleType, *, pattern: Any = ...) -> unittest.suite.TestSuite: ... def loadTestsFromName(self, name: str, module: Optional[ModuleType] = ...) -> unittest.suite.TestSuite: ... def loadTestsFromNames(self, names: Sequence[str], diff --git a/stdlib/3/unittest/mock.pyi b/stdlib/3/unittest/mock.pyi index cb3db6198b41..b4c4ce38aab9 100644 --- a/stdlib/3/unittest/mock.pyi +++ b/stdlib/3/unittest/mock.pyi @@ -1,7 +1,9 @@ # Stubs for mock import sys -from typing import Any, Optional, Text, Type +from typing import Any, List, Optional, Text, Tuple, Type, TypeVar + +_T = TypeVar("_T") FILTER_DIR: Any @@ -18,7 +20,7 @@ class _Sentinel: sentinel: Any DEFAULT: Any -class _CallList(list): +class _CallList(List[_T]): def __contains__(self, value: Any) -> bool: ... class _MockIter: @@ -33,14 +35,14 @@ class Base: # TODO: Defining this and other mock classes as classes in this stub causes # many false positives with mypy and production code. See if we can # improve mypy somehow and use a class with an "Any" base class. -NonCallableMock: Any +NonCallableMock = Any class CallableMixin(Base): side_effect: Any def __init__(self, spec: Optional[Any] = ..., side_effect: Optional[Any] = ..., return_value: Any = ..., wraps: Optional[Any] = ..., name: Optional[Any] = ..., spec_set: Optional[Any] = ..., parent: Optional[Any] = ..., _spec_state: Optional[Any] = ..., _new_name: Any = ..., _new_parent: Optional[Any] = ..., **kwargs: Any) -> None: ... def __call__(_mock_self, *args: Any, **kwargs: Any) -> Any: ... -Mock: Any +Mock = Any class _patch: attribute_name: Any @@ -94,8 +96,8 @@ patch: _patcher class MagicMixin: def __init__(self, *args: Any, **kw: Any) -> None: ... -NonCallableMagicMock: Any -MagicMock: Any +NonCallableMagicMock = Any +MagicMock = Any class MagicProxy: name: Any @@ -111,7 +113,7 @@ class _ANY: ANY: Any -class _Call(tuple): +class _Call(Tuple[Any, ...]): def __new__(cls, value: Any = ..., name: Optional[Any] = ..., parent: Optional[Any] = ..., two: bool = ..., from_kall: bool = ...) -> Any: ... name: Any parent: Any @@ -140,7 +142,7 @@ class _SpecState: def mock_open(mock: Optional[Any] = ..., read_data: Any = ...) -> Any: ... -PropertyMock: Any +PropertyMock = Any if sys.version_info >= (3, 7): def seal(mock: Any) -> None: ... diff --git a/stdlib/3/unittest/runner.pyi b/stdlib/3/unittest/runner.pyi index 786bc191e0cf..4c84d8b06fff 100644 --- a/stdlib/3/unittest/runner.pyi +++ b/stdlib/3/unittest/runner.pyi @@ -23,18 +23,16 @@ class TestRunner: class TextTestRunner(TestRunner): - if sys.version_info >= (3, 5): - def __init__(self, stream: Optional[TextIO] = ..., - descriptions: bool = ..., verbosity: int = ..., - failfast: bool = ..., buffer: bool = ..., - resultclass: Optional[_ResultClassType] = ..., - warnings: Optional[Type[Warning]] = ..., - *, tb_locals: bool = ...) -> None: ... - else: - def __init__(self, - stream: Optional[TextIO] = ..., - descriptions: bool = ..., verbosity: int = ..., - failfast: bool = ..., buffer: bool = ..., - resultclass: Optional[_ResultClassType] = ..., - warnings: Optional[Type[Warning]] = ...) -> None: ... + def __init__( + self, + stream: Optional[TextIO] = ..., + descriptions: bool = ..., + verbosity: int = ..., + failfast: bool = ..., + buffer: bool = ..., + resultclass: Optional[_ResultClassType] = ..., + warnings: Optional[Type[Warning]] = ..., + *, + tb_locals: bool = ..., + ) -> None: ... def _makeResult(self) -> unittest.result.TestResult: ... diff --git a/stdlib/3/unittest/util.pyi b/stdlib/3/unittest/util.pyi new file mode 100644 index 000000000000..9b56f8bbfa7d --- /dev/null +++ b/stdlib/3/unittest/util.pyi @@ -0,0 +1,22 @@ +# undocumented +from typing import Any, List, Sequence, Tuple, TypeVar + +_T = TypeVar('_T') +_Mismatch = Tuple[_T, _T, int] + +_MAX_LENGTH: int +_PLACEHOLDER_LEN: int +_MIN_BEGIN_LEN: int +_MIN_END_LEN: int +_MIN_COMMON_LEN: int +_MIN_DIFF_LEN: int + +def _shorten(s: str, prefixlen: int, suffixlen: int) -> str: ... +def _common_shorten_repr(*args: str) -> Tuple[str]: ... +def safe_repr(obj: object, short: bool = ...) -> str: ... +def strclass(cls: type) -> str: ... +def sorted_list_difference(expected: Sequence[_T], actual: Sequence[_T]) -> Tuple[List[_T], List[_T]]: ... +def unorderable_list_difference(expected: Sequence[_T], actual: Sequence[_T]) -> Tuple[List[_T], List[_T]]: ... +def three_way_cmp(x: Any, y: Any) -> int: ... +def _count_diff_all_purpose(actual: Sequence[_T], expected: Sequence[_T]) -> List[_Mismatch[_T]]: ... +def _count_diff_hashable(actual: Sequence[_T], expected: Sequence[_T]) -> List[_Mismatch[_T]]: ... diff --git a/stdlib/3/urllib/parse.pyi b/stdlib/3/urllib/parse.pyi index 8d7cc4a0db5c..952d3cf9e346 100644 --- a/stdlib/3/urllib/parse.pyi +++ b/stdlib/3/urllib/parse.pyi @@ -35,7 +35,7 @@ class _NetlocResultMixinStr(_NetlocResultMixinBase[str], _ResultMixinStr): ... class _NetlocResultMixinBytes(_NetlocResultMixinBase[bytes], _ResultMixinBytes): ... -class _DefragResultBase(tuple, Generic[AnyStr]): +class _DefragResultBase(Tuple[Any, ...], Generic[AnyStr]): url: AnyStr fragment: AnyStr @@ -109,19 +109,14 @@ def urldefrag(url: str) -> DefragResult: ... @overload def urldefrag(url: bytes) -> DefragResultBytes: ... -if sys.version_info >= (3, 5): - def urlencode(query: Union[Mapping[Any, Any], - Mapping[Any, Sequence[Any]], - Sequence[Tuple[Any, Any]], - Sequence[Tuple[Any, Sequence[Any]]]], - doseq: bool = ..., safe: AnyStr = ..., encoding: str = ..., errors: str = ..., - quote_via: Callable[[str, AnyStr, str, str], str] = ...) -> str: ... -else: - def urlencode(query: Union[Mapping[Any, Any], - Mapping[Any, Sequence[Any]], - Sequence[Tuple[Any, Any]], - Sequence[Tuple[Any, Sequence[Any]]]], - doseq: bool = ..., safe: AnyStr = ..., encoding: str = ..., errors: str = ...) -> str: ... +def urlencode( + query: Union[Mapping[Any, Any], Mapping[Any, Sequence[Any]], Sequence[Tuple[Any, Any]], Sequence[Tuple[Any, Sequence[Any]]]], + doseq: bool = ..., + safe: AnyStr = ..., + encoding: str = ..., + errors: str = ..., + quote_via: Callable[[str, AnyStr, str, str], str] = ..., +) -> str: ... def urljoin(base: AnyStr, url: Optional[AnyStr], allow_fragments: bool = ...) -> AnyStr: ... diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index a1a556813fef..a18210a5971d 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -4,7 +4,7 @@ from typing import ( Any, Callable, ClassVar, Dict, List, IO, Mapping, Optional, Sequence, Tuple, TypeVar, Union, overload, NoReturn, ) -from http.client import HTTPResponse, HTTPMessage, HTTPConnectionProtocol +from http.client import HTTPResponse, HTTPMessage, _HTTPConnectionProtocol from http.cookiejar import CookieJar from email.message import Message from urllib.response import addinfourl @@ -13,7 +13,7 @@ import sys import os _T = TypeVar('_T') -_UrlopenRet = Union[_HTTPResponse, addinfourl] +_UrlopenRet = Any class _HTTPResponse(HTTPResponse): url: str @@ -34,6 +34,7 @@ def pathname2url(path: str) -> str: ... def getproxies() -> Dict[str, str]: ... def parse_http_list(s: str) -> List[str]: ... def parse_keqv_list(l: List[str]) -> Dict[str, str]: ... +def proxy_bypass(host: str) -> Any: ... # Undocumented class Request: @property @@ -115,14 +116,17 @@ class HTTPPasswordMgrWithDefaultRealm(HTTPPasswordMgr): user: str, passwd: str) -> None: ... def find_user_password(self, realm: str, authuri: str) -> Tuple[Optional[str], Optional[str]]: ... -if sys.version_info >= (3, 5): - class HTTPPasswordMgrWithPriorAuth(HTTPPasswordMgrWithDefaultRealm): - def add_password(self, realm: str, uri: Union[str, Sequence[str]], - user: str, passwd: str, - is_authenticated: bool = ...) -> None: ... - def update_authenticated(self, uri: Union[str, Sequence[str]], - is_authenticated: bool = ...) -> None: ... - def is_authenticated(self, authuri: str) -> bool: ... +class HTTPPasswordMgrWithPriorAuth(HTTPPasswordMgrWithDefaultRealm): + def add_password( + self, + realm: str, + uri: Union[str, Sequence[str]], + user: str, + passwd: str, + is_authenticated: bool = ..., + ) -> None: ... + def update_authenticated(self, uri: Union[str, Sequence[str]], is_authenticated: bool = ...) -> None: ... + def is_authenticated(self, authuri: str) -> bool: ... class AbstractBasicAuthHandler: def __init__(self, @@ -162,7 +166,7 @@ class AbstractHTTPHandler(BaseHandler): # undocumented def set_http_debuglevel(self, level: int) -> None: ... def do_request_(self, request: Request) -> Request: ... def do_open(self, - http_class: HTTPConnectionProtocol, + http_class: _HTTPConnectionProtocol, req: Request, **http_conn_args: Any) -> HTTPResponse: ... @@ -198,7 +202,7 @@ class HTTPErrorProcessor(BaseHandler): def https_response(self, request, response) -> _UrlopenRet: ... if sys.version_info >= (3, 6): - def urlretrieve(url: str, filename: Optional[Union[str, os.PathLike]] = ..., + def urlretrieve(url: str, filename: Optional[Union[str, os.PathLike[Any]]] = ..., reporthook: Optional[Callable[[int, int, int], None]] = ..., data: Optional[bytes] = ...) -> Tuple[str, HTTPMessage]: ... else: diff --git a/stdlib/3/urllib/response.pyi b/stdlib/3/urllib/response.pyi index ef3507d7ddc7..7cbc045a3f76 100644 --- a/stdlib/3/urllib/response.pyi +++ b/stdlib/3/urllib/response.pyi @@ -7,7 +7,7 @@ _AIUT = TypeVar("_AIUT", bound=addbase) class addbase(BinaryIO): def __enter__(self: _AIUT) -> _AIUT: ... - def __exit__(self, type: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> bool: ... + def __exit__(self, type: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> None: ... def __iter__(self: _AIUT) -> _AIUT: ... def __next__(self) -> bytes: ... def close(self) -> None: ... diff --git a/stdlib/3.5/zipapp.pyi b/stdlib/3/zipapp.pyi similarity index 100% rename from stdlib/3.5/zipapp.pyi rename to stdlib/3/zipapp.pyi diff --git a/tests/check_consistent.py b/tests/check_consistent.py index 0566b4967b93..161cea2d84b7 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -1,7 +1,11 @@ #!/usr/bin/env python3 -# Symlinks are bad on Windows, so we cannot use them in typeshed. -# This checks that certain files are duplicated exactly. +# For various reasons we need the contents of certain files to be +# duplicated in two places, for example stdlib/2and3/builtins.pyi and +# stdlib/2/__builtin__.pyi must be identical. In the past we used +# symlinks but that doesn't always work on Windows, so now you must +# manually update both files, and this test verifies that they are +# identical. The list below indicates which sets of files must match. import os import filecmp @@ -13,7 +17,6 @@ 'stdlib/2and3/ntpath.pyi', 'stdlib/2and3/macpath.pyi', 'stdlib/2/os/path.pyi', 'stdlib/3/os/path.pyi'}, {'stdlib/3/enum.pyi', 'third_party/2/enum.pyi'}, - {'stdlib/2/os/path.pyi', 'stdlib/3/os/path.pyi'}, {'stdlib/3/unittest/mock.pyi', 'third_party/2and3/mock.pyi'}, {'stdlib/3/concurrent/__init__.pyi', 'third_party/2/concurrent/__init__.pyi'}, {'stdlib/3/concurrent/futures/__init__.pyi', 'third_party/2/concurrent/futures/__init__.pyi'}, @@ -22,7 +25,7 @@ {'stdlib/3/concurrent/futures/process.pyi', 'third_party/2/concurrent/futures/process.pyi'}, {'stdlib/3.7/dataclasses.pyi', 'third_party/3/dataclasses.pyi'}, {'stdlib/3/pathlib.pyi', 'third_party/2/pathlib2.pyi'}, - {'stdlib/3.7/contextvars.pyi', 'third_party/3.5/contextvars.pyi'}, + {'stdlib/3.7/contextvars.pyi', 'third_party/3/contextvars.pyi'}, ] def main(): diff --git a/tests/mypy_test.py b/tests/mypy_test.py index 7ac6f077b08f..cba411abb8ce 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -21,7 +21,6 @@ "Patterns are unanchored regexps on the full path.") parser.add_argument('-v', '--verbose', action='count', default=0, help="More output") parser.add_argument('-n', '--dry-run', action='store_true', help="Don't actually run mypy") -parser.add_argument('-a', '--new-analyzer', action='store_true', help="Use new mypy semantic analyzer") parser.add_argument('-x', '--exclude', type=str, nargs='*', help="Exclude pattern") parser.add_argument('-p', '--python-version', type=str, nargs='*', help="These versions only (major[.minor])") @@ -89,7 +88,7 @@ def main(): print("Cannot import mypy. Did you install it?") sys.exit(1) - versions = [(3, 7), (3, 6), (3, 5), (3, 4), (2, 7)] + versions = [(3, 8), (3, 7), (3, 6), (3, 5), (2, 7)] if args.python_version: versions = [v for v in versions if any(('%d.%d' % v).startswith(av) for av in args.python_version)] @@ -133,8 +132,7 @@ def main(): flags.append('--no-site-packages') flags.append('--show-traceback') flags.append('--no-implicit-optional') - if args.new_analyzer: - flags.append('--new-semantic-analyzer') + flags.append('--disallow-any-generics') if args.warn_unused_ignores: flags.append('--warn-unused-ignores') sys.argv = ['mypy'] + flags + files diff --git a/tests/pytype_test.py b/tests/pytype_test.py index bb4793a20078..d4f422827e2d 100755 --- a/tests/pytype_test.py +++ b/tests/pytype_test.py @@ -1,5 +1,5 @@ -#!/usr/bin/env python -r"""Test runner for typeshed. +#!/usr/bin/env python3 +"""Test runner for typeshed. Depends on pytype being installed. @@ -11,61 +11,67 @@ """ import argparse -import collections import itertools import os -from pytype import config -from pytype import io import re import subprocess -import sys import traceback +from typing import List, Match, Optional, Sequence, Tuple -parser = argparse.ArgumentParser(description='Pytype/typeshed tests.') -parser.add_argument('-n', '--dry-run', action='store_true', default=False, - help='Don\'t actually run tests') -# Default to '' so that symlinking typeshed subdirs in cwd will work. -parser.add_argument('--typeshed-location', type=str, default='', - help='Path to typeshed installation.') -# Set to true to print a stack trace every time an exception is thrown. -parser.add_argument('--print-stderr', action='store_true', default=False, - help='Print stderr every time an error is encountered.') -# We need to invoke python2.7 and 3.6. -parser.add_argument('--python27-exe', type=str, default='python2.7', - help='Path to a python 2.7 interpreter.') -parser.add_argument('--python36-exe', type=str, default='python3.6', - help='Path to a python 3.6 interpreter.') +from pytype import config as pytype_config, io as pytype_io +TYPESHED_SUBDIRS = ["stdlib", "third_party"] -TYPESHED_SUBDIRS = ['stdlib', 'third_party'] - -TYPESHED_HOME = 'TYPESHED_HOME' +TYPESHED_HOME = "TYPESHED_HOME" UNSET = object() # marker for tracking the TYPESHED_HOME environment variable -def main(): - args = parser.parse_args() - code = pytype_test(args) - sys.exit(code) - - -class PathMatcher(object): - def __init__(self, patterns): - if patterns: - self.matcher = re.compile('(%s)$' % '|'.join(patterns)) - else: - self.matcher = None - - def search(self, path): +def main() -> None: + args = create_parser().parse_args() + typeshed_location = args.typeshed_location or os.getcwd() + subdir_paths = [os.path.join(typeshed_location, d) for d in TYPESHED_SUBDIRS] + check_subdirs_discoverable(subdir_paths) + check_python_exes_runnable(python27_exe_arg=args.python27_exe, python36_exe_arg=args.python36_exe) + files_to_test = determine_files_to_test(typeshed_location=typeshed_location, subdir_paths=subdir_paths) + run_all_tests( + files_to_test=files_to_test, + typeshed_location=typeshed_location, + python27_exe=args.python27_exe, + python36_exe=args.python36_exe, + print_stderr=args.print_stderr, + dry_run=args.dry_run, + ) + + +def create_parser() -> argparse.ArgumentParser: + parser = argparse.ArgumentParser(description="Pytype/typeshed tests.") + parser.add_argument("-n", "--dry-run", action="store_true", default=False, help="Don't actually run tests") + # Default to '' so that symlinking typeshed subdirs in cwd will work. + parser.add_argument("--typeshed-location", type=str, default="", help="Path to typeshed installation.") + # Set to true to print a stack trace every time an exception is thrown. + parser.add_argument( + "--print-stderr", action="store_true", default=False, help="Print stderr every time an error is encountered." + ) + # We need to invoke python2.7 and 3.6. + parser.add_argument("--python27-exe", type=str, default="python2.7", help="Path to a python 2.7 interpreter.") + parser.add_argument("--python36-exe", type=str, default="python3.6", help="Path to a python 3.6 interpreter.") + return parser + + +class PathMatcher: + def __init__(self, patterns: Sequence[str]) -> None: + self.matcher = re.compile(r"({})$".format("|".join(patterns))) if patterns else None + + def search(self, path: str) -> Optional[Match[str]]: if not self.matcher: - return False + return None return self.matcher.search(path) -def load_blacklist(typeshed_location): - filename = os.path.join(typeshed_location, 'tests', 'pytype_blacklist.txt') - skip_re = re.compile(r'^\s*([^\s#]+)\s*(?:#.*)?$') +def load_blacklist(typeshed_location: str) -> List[str]: + filename = os.path.join(typeshed_location, "tests", "pytype_blacklist.txt") + skip_re = re.compile(r"^\s*([^\s#]+)\s*(?:#.*)?$") skip = [] with open(filename) as f: @@ -77,14 +83,18 @@ def load_blacklist(typeshed_location): return skip -def run_pytype(args, dry_run, typeshed_location): +def run_pytype(*, filename: str, python_version: str, python_exe: str, typeshed_location: str) -> Optional[str]: """Runs pytype, returning the stderr if any.""" - if dry_run: - return None + options = pytype_config.Options.create( + filename, + module_name=_get_module_name(filename), + parse_pyi=True, + python_version=python_version, + python_exe=python_exe) old_typeshed_home = os.environ.get(TYPESHED_HOME, UNSET) os.environ[TYPESHED_HOME] = typeshed_location try: - io.parse_pyi(config.Options(args)) + pytype_io.parse_pyi(options) except Exception: stderr = traceback.format_exc() else: @@ -96,7 +106,7 @@ def run_pytype(args, dry_run, typeshed_location): return stderr -def _get_relative(filename): +def _get_relative(filename: str) -> str: top = 0 for d in TYPESHED_SUBDIRS: try: @@ -108,106 +118,108 @@ def _get_relative(filename): return filename[top:] -def _get_module_name(filename): +def _get_module_name(filename: str) -> str: """Converts a filename {subdir}/m.n/module/foo to module.foo.""" - return '.'.join(_get_relative(filename).split(os.path.sep)[2:]).replace( - '.pyi', '').replace('.__init__', '') + return ".".join(_get_relative(filename).split(os.path.sep)[2:]).replace(".pyi", "").replace(".__init__", "") -def can_run(path, exe, *args): - exe = os.path.join(path, exe) +def can_run(exe: str, *, args: List[str]) -> bool: try: - subprocess.Popen( - [exe] + list(args), stdout=subprocess.PIPE, stderr=subprocess.PIPE - ).communicate() - return True + subprocess.run([exe] + args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) except OSError: return False + else: + return True -def _is_version(path, version): - return any('%s/%s' % (d, version) in path for d in TYPESHED_SUBDIRS) - +def _is_version(path: str, version: str) -> bool: + return any("{}/{}".format(d, version) in path for d in TYPESHED_SUBDIRS) -def pytype_test(args): - """Test with pytype, returning 0 for success and 1 for failure.""" - typeshed_location = args.typeshed_location or os.getcwd() - paths = [os.path.join(typeshed_location, d) for d in TYPESHED_SUBDIRS] - for p in paths: +def check_subdirs_discoverable(subdir_paths: List[str]) -> None: + for p in subdir_paths: if not os.path.isdir(p): - print('Cannot find typeshed subdir at %s ' - '(specify parent dir via --typeshed-location)' % p) - return 1 - - for python_version_str in ('27', '36'): - dest = 'python%s_exe' % python_version_str - version = '.'.join(list(python_version_str)) - arg = '--python%s-exe' % python_version_str - if not can_run('', getattr(args, dest), '--version'): - print('Cannot run Python {version}. (point to a valid executable ' - 'via {arg})'.format(version=version, arg=arg)) - return 1 + raise SystemExit("Cannot find typeshed subdir at {} (specify parent dir via --typeshed-location)".format(p)) + +def check_python_exes_runnable(*, python27_exe_arg: str, python36_exe_arg: str) -> None: + for exe, version_str in zip([python27_exe_arg, python36_exe_arg], ["27", "36"]): + if can_run(exe, args=["--version"]): + continue + formatted_version = ".".join(list(version_str)) + script_arg = "--python{}-exe".format(version_str) + raise SystemExit( + "Cannot run Python {version}. (point to a valid executable via {arg})".format( + version=formatted_version, arg=script_arg + ) + ) + + +def determine_files_to_test(*, typeshed_location: str, subdir_paths: Sequence[str]) -> List[Tuple[str, int]]: + """Determine all files to test, checking if it's in the blacklist and which Python versions to use. + + Returns a list of pairs of the file path and Python version as an int.""" skipped = PathMatcher(load_blacklist(typeshed_location)) files = [] - bad = [] - - def _parse(filename, major_version): - if major_version == 3: - version = '3.6' - exe = args.python36_exe - else: - version = '2.7' - exe = args.python27_exe - options = [ - '--module-name=%s' % _get_module_name(filename), - '--parse-pyi', - '-V %s' % version, - '--python_exe=%s' % exe, - ] - return run_pytype(options + [filename], - dry_run=args.dry_run, - typeshed_location=typeshed_location) - - for root, _, filenames in itertools.chain.from_iterable( - os.walk(p) for p in paths): - for f in sorted(f for f in filenames if f.endswith('.pyi')): + for root, _, filenames in itertools.chain.from_iterable(os.walk(p) for p in subdir_paths): + for f in sorted(f for f in filenames if f.endswith(".pyi")): f = os.path.join(root, f) rel = _get_relative(f) - if not skipped.search(rel): - if _is_version(f, '2and3'): - files.append((f, 2)) - files.append((f, 3)) - elif _is_version(f, '2'): - files.append((f, 2)) - elif _is_version(f, '3'): - files.append((f, 3)) - else: - print('Unrecognized path: %s' % f) - + if skipped.search(rel): + continue + if _is_version(f, "2and3"): + files.append((f, 2)) + files.append((f, 3)) + elif _is_version(f, "2"): + files.append((f, 2)) + elif _is_version(f, "3"): + files.append((f, 3)) + else: + print("Unrecognized path: {}".format(f)) + return files + + +def run_all_tests( + *, + files_to_test: Sequence[Tuple[str, int]], + typeshed_location: str, + python27_exe: str, + python36_exe: str, + print_stderr: bool, + dry_run: bool +) -> None: + bad = [] errors = 0 - total_tests = len(files) - print('Testing files with pytype...') - for i, (f, version) in enumerate(files): - stderr = _parse(f, version) + total_tests = len(files_to_test) + print("Testing files with pytype...") + for i, (f, version) in enumerate(files_to_test): + stderr = ( + run_pytype( + filename=f, + python_version="2.7" if version == 2 else "3.6", + python_exe=python27_exe if version == 2 else python36_exe, + typeshed_location=typeshed_location, + ) + if not dry_run + else None + ) if stderr: - if args.print_stderr: + if print_stderr: print(stderr) errors += 1 - # We strip off the stack trace and just leave the last line with the - # actual error; to see the stack traces use --print_stderr. - bad.append((_get_relative(f), stderr.rstrip().rsplit('\n', 1)[-1])) + stacktrace_final_line = stderr.rstrip().rsplit("\n", 1)[-1] + bad.append((_get_relative(f), stacktrace_final_line)) runs = i + 1 if runs % 25 == 0: - print(' %3d/%d with %3d errors' % (runs, total_tests, errors)) + print(" {:3d}/{:d} with {:3d} errors".format(runs, total_tests, errors)) - print('Ran pytype with %d pyis, got %d errors.' % (total_tests, errors)) + print("Ran pytype with {:d} pyis, got {:d} errors.".format(total_tests, errors)) for f, err in bad: - print('%s: %s' % (f, err)) - return int(bool(errors)) + print("{}: {}".format(f, err)) + if errors: + raise SystemExit("\nRun again with --print-stderr to get the full stacktrace.") -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/third_party/2/concurrent/futures/_base.pyi b/third_party/2/concurrent/futures/_base.pyi index 95189a741199..00ff41d76959 100644 --- a/third_party/2/concurrent/futures/_base.pyi +++ b/third_party/2/concurrent/futures/_base.pyi @@ -1,21 +1,26 @@ -from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set, NamedTuple +import threading +from logging import Logger +from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set, List from types import TracebackType import sys FIRST_COMPLETED: str FIRST_EXCEPTION: str ALL_COMPLETED: str -PENDING: Any -RUNNING: Any -CANCELLED: Any -CANCELLED_AND_NOTIFIED: Any -FINISHED: Any -LOGGER: Any +PENDING: str +RUNNING: str +CANCELLED: str +CANCELLED_AND_NOTIFIED: str +FINISHED: str +LOGGER: Logger class Error(Exception): ... class CancelledError(Error): ... class TimeoutError(Error): ... +if sys.version_info >= (3, 7): + class BrokenExecutor(RuntimeError): ... + _T = TypeVar('_T') class Future(Generic[_T]): @@ -48,9 +53,48 @@ class Executor: def map(self, func: Callable[..., _T], *iterables: Iterable[Any], timeout: Optional[float] = ...,) -> Iterator[_T]: ... def shutdown(self, wait: bool = ...) -> None: ... def __enter__(self: _T) -> _T: ... - def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: ... + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> Optional[bool]: ... def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> Iterator[Future[_T]]: ... def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Set[Future[_T]], Set[Future[_T]]]: ... + +class _Waiter: + event: threading.Event + finished_futures: List[Future[Any]] + def __init__(self) -> None: ... + def add_result(self, future: Future[Any]) -> None: ... + def add_exception(self, future: Future[Any]) -> None: ... + def add_cancelled(self, future: Future[Any]) -> None: ... + + +class _AsCompletedWaiter(_Waiter): + lock: threading.Lock + def __init__(self) -> None: ... + def add_result(self, future: Future[Any]) -> None: ... + def add_exception(self, future: Future[Any]) -> None: ... + def add_cancelled(self, future: Future[Any]) -> None: ... + + +class _FirstCompletedWaiter(_Waiter): + def add_result(self, future: Future[Any]) -> None: ... + def add_exception(self, future: Future[Any]) -> None: ... + def add_cancelled(self, future: Future[Any]) -> None: ... + + +class _AllCompletedWaiter(_Waiter): + num_pending_calls: int + stop_on_exception: bool + lock: threading.Lock + def __init__(self, num_pending_calls: int, stop_on_exception: bool) -> None: ... + def add_result(self, future: Future[Any]) -> None: ... + def add_exception(self, future: Future[Any]) -> None: ... + def add_cancelled(self, future: Future[Any]) -> None: ... + + +class _AcquireFutures: + futures: Iterable[Future[Any]] + def __init__(self, futures: Iterable[Future[Any]]) -> None: ... + def __enter__(self) -> None: ... + def __exit__(self, *args: Any) -> None: ... diff --git a/third_party/2/concurrent/futures/process.pyi b/third_party/2/concurrent/futures/process.pyi index ba0cd61a6170..ca22879c02fe 100644 --- a/third_party/2/concurrent/futures/process.pyi +++ b/third_party/2/concurrent/futures/process.pyi @@ -1,5 +1,5 @@ from typing import Any, Callable, Optional, Tuple -from ._base import Future, Executor +from ._base import Executor import sys EXTRA_QUEUED_CALLS: Any @@ -8,8 +8,11 @@ if sys.version_info >= (3,): class BrokenProcessPool(RuntimeError): ... if sys.version_info >= (3, 7): + from multiprocessing.context import BaseContext + class ProcessPoolExecutor(Executor): def __init__(self, max_workers: Optional[int] = ..., + mp_context: Optional[BaseContext] = ..., initializer: Optional[Callable[..., None]] = ..., initargs: Tuple[Any, ...] = ...) -> None: ... else: diff --git a/third_party/2/concurrent/futures/thread.pyi b/third_party/2/concurrent/futures/thread.pyi index 983594dc728f..82c8ddd03d94 100644 --- a/third_party/2/concurrent/futures/thread.pyi +++ b/third_party/2/concurrent/futures/thread.pyi @@ -1,7 +1,13 @@ -from typing import Any, Callable, Optional, Tuple +from typing import Any, Callable, Iterable, Mapping, Optional, Tuple, TypeVar, Generic from ._base import Executor, Future import sys +if sys.version_info >= (3, 7): + from ._base import BrokenExecutor + class BrokenThreadPool(BrokenExecutor): ... + +_S = TypeVar('_S') + class ThreadPoolExecutor(Executor): if sys.version_info >= (3, 7): def __init__(self, max_workers: Optional[int] = ..., @@ -13,3 +19,12 @@ class ThreadPoolExecutor(Executor): thread_name_prefix: str = ...) -> None: ... else: def __init__(self, max_workers: Optional[int] = ...) -> None: ... + + +class _WorkItem(Generic[_S]): + future: Future[_S] + fn: Callable[..., _S] + args: Iterable[Any] + kwargs: Mapping[str, Any] + def __init__(self, future: Future[_S], fn: Callable[..., _S], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ... + def run(self) -> None: ... diff --git a/third_party/2/gflags.pyi b/third_party/2/gflags.pyi index 87edd4e4a0bb..88eb2578fb64 100644 --- a/third_party/2/gflags.pyi +++ b/third_party/2/gflags.pyi @@ -35,7 +35,7 @@ class FlagValues: def is_gnu_getopt(self) -> bool: ... IsGnuGetOpt = is_gnu_getopt # TODO dict type - def FlagDict(self) -> dict: ... + def FlagDict(self) -> Dict[Any, Any]: ... def flags_by_module_dict(self) -> Dict[str, List[Flag]]: ... FlagsByModuleDict = flags_by_module_dict def flags_by_module_id_dict(self) -> Dict[int, List[Flag]]: ... @@ -206,7 +206,7 @@ def DEFINE_enum(name: str, default: Optional[str], enum_values: List[str], help: class BaseListParser(ArgumentParser): def __init__(self, token: str = ..., name: str = ...) -> None: ... - def Parse(self, argument: Any) -> list: ... + def Parse(self, argument: Any) -> List[Any]: ... class ListParser(BaseListParser): def __init__(self) -> None: ... diff --git a/third_party/2/pathlib2.pyi b/third_party/2/pathlib2.pyi index 42968fa98ec7..ff6bedd1c043 100644 --- a/third_party/2/pathlib2.pyi +++ b/third_party/2/pathlib2.pyi @@ -3,7 +3,7 @@ from types import TracebackType import os import sys -_P = TypeVar('_P', bound='PurePath') +_P = TypeVar('_P', bound=PurePath) if sys.version_info >= (3, 6): _PurePathBase = os.PathLike[str] @@ -30,7 +30,12 @@ class PurePath(_PurePathBase): def __le__(self, other: PurePath) -> bool: ... def __gt__(self, other: PurePath) -> bool: ... def __ge__(self, other: PurePath) -> bool: ... - def __truediv__(self: _P, key: Union[str, PurePath]) -> _P: ... + if sys.version_info < (3, 6): + def __truediv__(self: _P, key: Union[str, PurePath]) -> _P: ... + def __rtruediv__(self: _P, key: Union[str, PurePath]) -> _P: ... + else: + def __truediv__(self: _P, key: Union[str, os.PathLike[str]]) -> _P: ... + def __rtruediv__(self: _P, key: Union[str, os.PathLike[str]]) -> _P: ... if sys.version_info < (3,): def __div__(self: _P, key: Union[str, PurePath]) -> _P: ... def __bytes__(self) -> bytes: ... @@ -39,10 +44,16 @@ class PurePath(_PurePathBase): def is_absolute(self) -> bool: ... def is_reserved(self) -> bool: ... def match(self, path_pattern: str) -> bool: ... - def relative_to(self: _P, *other: Union[str, PurePath]) -> _P: ... + if sys.version_info < (3, 6): + def relative_to(self: _P, *other: Union[str, PurePath]) -> _P: ... + else: + def relative_to(self: _P, *other: Union[str, os.PathLike[str]]) -> _P: ... def with_name(self: _P, name: str) -> _P: ... def with_suffix(self: _P, suffix: str) -> _P: ... - def joinpath(self: _P, *other: Union[str, PurePath]) -> _P: ... + if sys.version_info < (3, 6): + def joinpath(self: _P, *other: Union[str, PurePath]) -> _P: ... + else: + def joinpath(self: _P, *other: Union[str, os.PathLike[str]]) -> _P: ... @property def parents(self: _P) -> Sequence[_P]: ... diff --git a/third_party/2/six/moves/CGIHTTPServer.pyi b/third_party/2/six/moves/CGIHTTPServer.pyi new file mode 100644 index 000000000000..b39390c67abf --- /dev/null +++ b/third_party/2/six/moves/CGIHTTPServer.pyi @@ -0,0 +1 @@ +from CGIHTTPServer import * diff --git a/third_party/2/six/moves/__init__.pyi b/third_party/2/six/moves/__init__.pyi index ade03042ca7c..2bc82cbc675b 100644 --- a/third_party/2/six/moves/__init__.pyi +++ b/third_party/2/six/moves/__init__.pyi @@ -36,7 +36,7 @@ from . import http_client from . import email_mime_text # import email.MIMEBase as email_mime_base from . import BaseHTTPServer -# import CGIHTTPServer as CGIHTTPServer +from . import CGIHTTPServer from . import SimpleHTTPServer from . import cPickle from . import queue diff --git a/third_party/2/tornado/httputil.pyi b/third_party/2/tornado/httputil.pyi index bfc81fa786a7..5f74cb57c31e 100644 --- a/third_party/2/tornado/httputil.pyi +++ b/third_party/2/tornado/httputil.pyi @@ -1,16 +1,16 @@ -from typing import Any +from typing import Any, Dict from tornado.util import ObjectDict from collections import namedtuple class SSLError(Exception): ... -class _NormalizedHeaderCache(dict): +class _NormalizedHeaderCache(Dict[Any, Any]): size: Any queue: Any def __init__(self, size) -> None: ... def __missing__(self, key): ... -class HTTPHeaders(dict): +class HTTPHeaders(Dict[Any, Any]): def __init__(self, *args, **kwargs) -> None: ... def add(self, name, value): ... def get_list(self, name): ... diff --git a/third_party/2/tornado/testing.pyi b/third_party/2/tornado/testing.pyi index 25fd0e59e583..c10025810c1c 100644 --- a/third_party/2/tornado/testing.pyi +++ b/third_party/2/tornado/testing.pyi @@ -1,4 +1,4 @@ -from typing import Any, Optional +from typing import Any, Callable, Generator, Optional, overload import unittest import logging @@ -42,7 +42,10 @@ class AsyncHTTPSTestCase(AsyncHTTPTestCase): def get_ssl_options(self): ... def get_protocol(self): ... -def gen_test(f): ... +@overload +def gen_test(*, timeout: Optional[float] = ...) -> Callable[[Callable[..., Generator[Any, Any, Any]]], Callable[..., None]]: ... +@overload +def gen_test(func: Callable[..., Generator[Any, Any, Any]]) -> Callable[..., None]: ... class LogTrapTestCase(unittest.TestCase): def run(self, result: Optional[Any] = ...): ... diff --git a/third_party/2/tornado/util.pyi b/third_party/2/tornado/util.pyi index 1f6e0d2dd113..8ebb0a1b8f62 100644 --- a/third_party/2/tornado/util.pyi +++ b/third_party/2/tornado/util.pyi @@ -1,8 +1,8 @@ -from typing import Any +from typing import Any, Dict xrange: Any -class ObjectDict(dict): +class ObjectDict(Dict[Any, Any]): def __getattr__(self, name): ... def __setattr__(self, name, value): ... diff --git a/third_party/2and3/atomicwrites/__init__.pyi b/third_party/2and3/atomicwrites/__init__.pyi index 07edff6979d8..cecbd10bcf29 100644 --- a/third_party/2and3/atomicwrites/__init__.pyi +++ b/third_party/2and3/atomicwrites/__init__.pyi @@ -1,13 +1,15 @@ -from typing import AnyStr, Callable, ContextManager, IO, Optional, Text, Type +from typing import Any, AnyStr, Callable, ContextManager, Generic, IO, Optional, Text, Type, Union def replace_atomic(src: AnyStr, dst: AnyStr) -> None: ... def move_atomic(src: AnyStr, dst: AnyStr) -> None: ... class AtomicWriter(object): - def __init__(self, path: AnyStr, mode: Text = ..., overwrite: bool = ...) -> None: ... - def open(self) -> ContextManager[IO]: ... - def _open(self, get_fileobject: Callable) -> ContextManager[IO]: ... - def get_fileobject(self, dir: Optional[AnyStr] = ..., **kwargs) -> IO: ... - def sync(self, f: IO) -> None: ... - def commit(self, f: IO) -> None: ... - def rollback(self, f: IO) -> None: ... -def atomic_write(path: AnyStr, writer_cls: Type[AtomicWriter] = ..., **cls_kwargs: object) -> ContextManager[IO]: ... + def __init__(self, path: Union[Text, bytes], mode: Text = ..., overwrite: bool = ...) -> None: ... + def open(self) -> ContextManager[IO[Any]]: ... + def _open(self, get_fileobject: Callable[..., IO[AnyStr]]) -> ContextManager[IO[AnyStr]]: ... + def get_fileobject(self, dir: Union[None, Text, bytes] = ..., **kwargs: Any) -> IO[Any]: ... + def sync(self, f: IO[Any]) -> None: ... + def commit(self, f: IO[Any]) -> None: ... + def rollback(self, f: IO[Any]) -> None: ... +def atomic_write( + path: Union[Text, bytes], writer_cls: Type[AtomicWriter] = ..., **cls_kwargs: object, +) -> ContextManager[IO[Any]]: ... diff --git a/third_party/2and3/boto/s3/cors.pyi b/third_party/2and3/boto/s3/cors.pyi index 6ffe8ee6d9d7..af34ab815001 100644 --- a/third_party/2and3/boto/s3/cors.pyi +++ b/third_party/2and3/boto/s3/cors.pyi @@ -1,4 +1,4 @@ -from typing import Any, Optional +from typing import Any, List, Optional class CORSRule: allowed_method: Any @@ -12,7 +12,7 @@ class CORSRule: def endElement(self, name, value, connection): ... def to_xml(self) -> str: ... -class CORSConfiguration(list): +class CORSConfiguration(List[CORSRule]): def startElement(self, name, attrs, connection): ... def endElement(self, name, value, connection): ... def to_xml(self) -> str: ... diff --git a/third_party/2and3/boto/s3/lifecycle.pyi b/third_party/2and3/boto/s3/lifecycle.pyi index 0b775efc03f6..fb42bb20494d 100644 --- a/third_party/2and3/boto/s3/lifecycle.pyi +++ b/third_party/2and3/boto/s3/lifecycle.pyi @@ -1,4 +1,4 @@ -from typing import Any, Optional +from typing import Any, List, Optional class Rule: id: Any @@ -26,7 +26,7 @@ class Transition: def __init__(self, days: Optional[Any] = ..., date: Optional[Any] = ..., storage_class: Optional[Any] = ...) -> None: ... def to_xml(self): ... -class Transitions(list): +class Transitions(List[Transition]): transition_properties: int current_transition_property: int temp_days: Any @@ -44,7 +44,7 @@ class Transitions(list): @property def storage_class(self): ... -class Lifecycle(list): +class Lifecycle(List[Rule]): def startElement(self, name, attrs, connection): ... def endElement(self, name, value, connection): ... def to_xml(self): ... diff --git a/third_party/2and3/boto/s3/tagging.pyi b/third_party/2and3/boto/s3/tagging.pyi index 9dec4e3f89e9..15553e7c7853 100644 --- a/third_party/2and3/boto/s3/tagging.pyi +++ b/third_party/2and3/boto/s3/tagging.pyi @@ -1,4 +1,4 @@ -from typing import Any, Optional +from typing import Any, List, Optional class Tag: key: Any @@ -9,13 +9,13 @@ class Tag: def to_xml(self): ... def __eq__(self, other): ... -class TagSet(list): +class TagSet(List[Tag]): def startElement(self, name, attrs, connection): ... def endElement(self, name, value, connection): ... def add_tag(self, key, value): ... def to_xml(self): ... -class Tags(list): +class Tags(List[TagSet]): def startElement(self, name, attrs, connection): ... def endElement(self, name, value, connection): ... def to_xml(self): ... diff --git a/third_party/2and3/boto/s3/website.pyi b/third_party/2and3/boto/s3/website.pyi index 2a92866307ea..6bc9047171f2 100644 --- a/third_party/2and3/boto/s3/website.pyi +++ b/third_party/2and3/boto/s3/website.pyi @@ -1,4 +1,4 @@ -from typing import Any, Optional +from typing import Any, List, Optional def tag(key, value): ... @@ -27,8 +27,8 @@ class RedirectLocation(_XMLKeyValue): def __init__(self, hostname: Optional[Any] = ..., protocol: Optional[Any] = ...) -> None: ... def to_xml(self): ... -class RoutingRules(list): - def add_rule(self, rule): ... +class RoutingRules(List[RoutingRule]): + def add_rule(self, rule: RoutingRule) -> RoutingRules: ... def startElement(self, name, attrs, connection): ... def endElement(self, name, value, connection): ... def to_xml(self): ... diff --git a/third_party/2and3/boto/utils.pyi b/third_party/2and3/boto/utils.pyi index 6552b0af1610..7c927d8356ce 100644 --- a/third_party/2and3/boto/utils.pyi +++ b/third_party/2and3/boto/utils.pyi @@ -25,7 +25,7 @@ from typing import ( _KT = TypeVar('_KT') _VT = TypeVar('_VT') -if sys.version_info[0] >= 3: +if sys.version_info >= (3,): # TODO move _StringIO definition into boto.compat once stubs exist and rename to StringIO import io _StringIO = io.StringIO @@ -37,7 +37,7 @@ if sys.version_info[0] >= 3: else: # TODO move _StringIO definition into boto.compat once stubs exist and rename to StringIO import StringIO - _StringIO = StringIO.StringIO + _StringIO = StringIO.StringIO[Any] from hashlib import _hash _HashType = _hash @@ -91,7 +91,7 @@ def get_instance_metadata( data: str = ..., timeout: Optional[int] = ..., num_retries: int = ..., -) -> Optional[LazyLoadMetadata]: ... +) -> Optional[LazyLoadMetadata[Any, Any]]: ... def get_instance_identity( version: str = ..., url: str = ..., @@ -138,7 +138,7 @@ class ShellCommand: cwd: Optional[subprocess._TXT] = ..., ) -> None: ... - process: subprocess.Popen + process: subprocess.Popen[Any] def run(self, cwd: Optional[subprocess._CMD] = ...) -> Optional[int]: ... def setReadOnly(self, value) -> None: ... @@ -204,7 +204,7 @@ def notify( append_instance_id: bool = ..., ) -> None: ... def get_utf8_value(value: str) -> bytes: ... -def mklist(value: Any) -> List: ... +def mklist(value: Any) -> List[Any]: ... def pythonize_name(name: str) -> str: ... def write_mime_multipart( content: List[Tuple[str, str]], diff --git a/third_party/2and3/characteristic/__init__.pyi b/third_party/2and3/characteristic/__init__.pyi index 20bd6e58a94e..61c8c8a14137 100644 --- a/third_party/2and3/characteristic/__init__.pyi +++ b/third_party/2and3/characteristic/__init__.pyi @@ -1,4 +1,4 @@ -from typing import Sequence, Callable, Union, Any, Optional, AnyStr, TypeVar, Type +from typing import Sequence, Callable, Union, Any, Optional, AnyStr, TypeVar, Type, Dict def with_repr(attrs: Sequence[Union[AnyStr, Attribute]]) -> Callable[..., Any]: ... def with_cmp(attrs: Sequence[Union[AnyStr, Attribute]]) -> Callable[..., Any]: ... @@ -18,7 +18,7 @@ def attributes( apply_with_repr: bool = ..., apply_immutable: bool = ..., store_attributes: Optional[Callable[[type, Attribute], Any]] = ..., - **kw: Optional[dict]) -> Callable[[Type[_T]], Type[_T]]: ... + **kw: Optional[Dict[Any, Any]]) -> Callable[[Type[_T]], Type[_T]]: ... class Attribute: def __init__( diff --git a/third_party/2and3/click/__init__.pyi b/third_party/2and3/click/__init__.pyi index 4733c6d0c006..11eaa8707a06 100644 --- a/third_party/2and3/click/__init__.pyi +++ b/third_party/2and3/click/__init__.pyi @@ -49,6 +49,8 @@ from .decorators import ( from .types import ( ParamType as ParamType, File as File, + FloatRange as FloatRange, + DateTime as DateTime, Path as Path, Choice as Choice, IntRange as IntRange, diff --git a/third_party/2and3/click/core.pyi b/third_party/2and3/click/core.pyi index fa2413d69e3e..aab8ef84c836 100644 --- a/third_party/2and3/click/core.pyi +++ b/third_party/2and3/click/core.pyi @@ -19,6 +19,8 @@ from typing import ( from click.formatting import HelpFormatter from click.parser import OptionParser +_CC = TypeVar("_CC", bound=Callable[[], Any]) + def invoke_param_callback( callback: Callable[[Context, Parameter, Optional[str]], Any], ctx: Context, @@ -45,7 +47,7 @@ class Context: parent: Optional[Context] command: Command info_name: Optional[str] - params: Dict + params: Dict[Any, Any] args: List[str] protected_args: List[str] obj: Any @@ -62,7 +64,7 @@ class Context: auto_envvar_prefix: Optional[str] color: Optional[bool] _meta: Dict[str, Any] - _close_callbacks: List + _close_callbacks: List[Any] _depth: int def __init__( @@ -99,8 +101,7 @@ class Context: def make_formatter(self) -> HelpFormatter: ... - def call_on_close(self, f: Callable) -> Callable: - ... + def call_on_close(self, f: _CC) -> _CC: ... def close(self) -> None: ... @@ -132,25 +133,16 @@ class Context: def get_help(self) -> str: ... - def invoke( - self, callback: Union[Command, Callable], *args, **kwargs - ) -> Any: - ... - - def forward( - self, callback: Union[Command, Callable], *args, **kwargs - ) -> Any: - ... + def invoke(self, callback: Union[Command, Callable[..., Any]], *args, **kwargs) -> Any: ... + def forward(self, callback: Union[Command, Callable[..., Any]], *args, **kwargs) -> Any: ... class BaseCommand: allow_extra_args: bool allow_interspersed_args: bool ignore_unknown_options: bool name: str - context_settings: Dict - - def __init__(self, name: str, context_settings: Optional[Dict] = ...) -> None: - ... + context_settings: Dict[Any, Any] + def __init__(self, name: str, context_settings: Optional[Dict[Any, Any]] = ...) -> None: ... def get_usage(self, ctx: Context) -> str: ... @@ -184,7 +176,7 @@ class BaseCommand: class Command(BaseCommand): - callback: Optional[Callable] + callback: Optional[Callable[..., Any]] params: List[Parameter] help: Optional[str] epilog: Optional[str] @@ -197,8 +189,8 @@ class Command(BaseCommand): def __init__( self, name: str, - context_settings: Optional[Dict] = ..., - callback: Optional[Callable] = ..., + context_settings: Optional[Dict[Any, Any]] = ..., + callback: Optional[Callable[..., Any]] = ..., params: Optional[List[Parameter]] = ..., help: Optional[str] = ..., epilog: Optional[str] = ..., @@ -257,7 +249,7 @@ class MultiCommand(Command): invoke_without_command: bool subcommand_metavar: str chain: bool - result_callback: Callable + result_callback: Callable[..., Any] def __init__( self, @@ -266,7 +258,7 @@ class MultiCommand(Command): no_args_is_help: Optional[bool] = ..., subcommand_metavar: Optional[str] = ..., chain: bool = ..., - result_callback: Optional[Callable] = ..., + result_callback: Optional[Callable[..., Any]] = ..., **attrs ) -> None: ... @@ -302,11 +294,8 @@ class Group(MultiCommand): def add_command(self, cmd: Command, name: Optional[str] = ...): ... - def command(self, *args, **kwargs) -> Callable[[Callable], Command]: - ... - - def group(self, *args, **kwargs) -> Callable[[Callable], Group]: - ... + def command(self, *args, **kwargs) -> Callable[[Callable[..., Any]], Command]: ... + def group(self, *args, **kwargs) -> Callable[[Callable[..., Any]], Group]: ... class CommandCollection(MultiCommand): @@ -351,12 +340,13 @@ class _ParamType: def split_envvar_value(self, rv: str) -> List[str]: ... - def fail(self, message: str, param: Optional[Parameter] = ..., ctx: Optional[Context] = ...) -> None: + def fail(self, message: str, param: Optional[Parameter] = ..., ctx: Optional[Context] = ...) -> NoReturn: ... # This type is here to resolve https://github.com/python/mypy/issues/5275 -_ConvertibleType = Union[type, _ParamType, Tuple[type, ...], Callable[[str], Any], Callable[[Optional[str]], Any]] +_ConvertibleType = Union[type, _ParamType, Tuple[Union[type, _ParamType], ...], + Callable[[str], Any], Callable[[Optional[str]], Any]] class Parameter: diff --git a/third_party/2and3/click/decorators.pyi b/third_party/2and3/click/decorators.pyi index 44f4ad7883b0..04787749f253 100644 --- a/third_party/2and3/click/decorators.pyi +++ b/third_party/2and3/click/decorators.pyi @@ -35,7 +35,7 @@ def command( name: Optional[str] = ..., cls: Optional[Type[Command]] = ..., # Command - context_settings: Optional[Dict] = ..., + context_settings: Optional[Dict[Any, Any]] = ..., help: Optional[str] = ..., epilog: Optional[str] = ..., short_help: Optional[str] = ..., @@ -43,9 +43,7 @@ def command( add_help_option: bool = ..., hidden: bool = ..., deprecated: bool = ..., -) -> Callable[[Callable], Command]: - ... - +) -> Callable[[Callable[..., Any]], Command]: ... # This inherits attrs from Group, MultiCommand and Command. @@ -59,7 +57,7 @@ def group( no_args_is_help: Optional[bool] = ..., subcommand_metavar: Optional[str] = ..., chain: bool = ..., - result_callback: Optional[Callable] = ..., + result_callback: Optional[Callable[..., Any]] = ..., # Command help: Optional[str] = ..., epilog: Optional[str] = ..., @@ -70,9 +68,7 @@ def group( deprecated: bool = ..., # User-defined **kwargs: Any, -) -> Callable[[Callable], Group]: - ... - +) -> Callable[[Callable[..., Any]], Group]: ... def argument( *param_decls: str, diff --git a/third_party/2and3/click/exceptions.pyi b/third_party/2and3/click/exceptions.pyi index ab2932eb4a5e..3f0dda36248c 100644 --- a/third_party/2and3/click/exceptions.pyi +++ b/third_party/2and3/click/exceptions.pyi @@ -20,11 +20,8 @@ class ClickException(Exception): class UsageError(ClickException): ctx: Optional[Context] - def __init__(self, message: str, ctx: Optional[Context] = ...) -> None: - ... - - def show(self, file: Optional[IO] = ...) -> None: - ... + def __init__(self, message: str, ctx: Optional[Context] = ...) -> None: ... + def show(self, file: Optional[IO[Any]] = ...) -> None: ... class BadParameter(UsageError): diff --git a/third_party/2and3/click/termui.pyi b/third_party/2and3/click/termui.pyi index 4262e32306bb..87e9bdcc9cfc 100644 --- a/third_party/2and3/click/termui.pyi +++ b/third_party/2and3/click/termui.pyi @@ -8,6 +8,7 @@ from typing import ( Optional, Text, overload, + Text, Tuple, TypeVar, Union, @@ -62,7 +63,7 @@ def get_terminal_size() -> Tuple[int, int]: def echo_via_pager( text_or_generator: Union[str, Iterable[str], Callable[[], Generator[str, None, None]]], - color: Optional[bool] + color: Optional[bool] = ..., ) -> None: ... @@ -83,7 +84,7 @@ def progressbar( bar_template: str = ..., info_sep: str = ..., width: int = ..., - file: Optional[IO] = ..., + file: Optional[IO[Any]] = ..., color: Optional[bool] = ..., ) -> _ProgressBar[_T]: ... @@ -102,7 +103,7 @@ def progressbar( bar_template: str = ..., info_sep: str = ..., width: int = ..., - file: Optional[IO] = ..., + file: Optional[IO[Any]] = ..., color: Optional[bool] = ..., ) -> _ProgressBar[int]: ... @@ -112,7 +113,7 @@ def clear() -> None: def style( - text: str, + text: Text, fg: Optional[str] = ..., bg: Optional[str] = ..., bold: Optional[bool] = ..., @@ -125,14 +126,14 @@ def style( ... -def unstyle(text: str) -> str: +def unstyle(text: Text) -> str: ... # Styling options copied from style() for nicer type checking. def secho( message: Optional[str] = ..., - file: Optional[IO] = ..., + file: Optional[IO[Any]] = ..., nl: bool = ..., err: bool = ..., color: Optional[bool] = ..., diff --git a/third_party/2and3/click/testing.pyi b/third_party/2and3/click/testing.pyi index 6b16df9b2d39..bd24c9be7159 100644 --- a/third_party/2and3/click/testing.pyi +++ b/third_party/2and3/click/testing.pyi @@ -13,7 +13,7 @@ class EchoingStdin: def readlines(self) -> List[bytes]: ... def __iter__(self) -> Iterable[bytes]: ... -def make_input_stream(input: Optional[Union[bytes, Text, IO]], charset: Text) -> BinaryIO: ... +def make_input_stream(input: Optional[Union[bytes, Text, IO[Any]]], charset: Text) -> BinaryIO: ... class Result: runner: CliRunner @@ -56,7 +56,7 @@ class CliRunner: def make_env(self, overrides: Optional[Mapping[str, str]] = ...) -> Dict[str, str]: ... def isolation( self, - input: Optional[IO] = ..., + input: Optional[Union[bytes, Text, IO[Any]]] = ..., env: Optional[Mapping[str, str]] = ..., color: bool = ..., ) -> ContextManager[BinaryIO]: ... @@ -64,7 +64,7 @@ class CliRunner: self, cli: BaseCommand, args: Optional[Union[str, Iterable[str]]] = ..., - input: Optional[IO] = ..., + input: Optional[Union[bytes, Text, IO[Any]]] = ..., env: Optional[Mapping[str, str]] = ..., catch_exceptions: bool = ..., color: bool = ..., diff --git a/third_party/2and3/click/types.pyi b/third_party/2and3/click/types.pyi index 7f1e0ba8f324..cf37a7385a80 100644 --- a/third_party/2and3/click/types.pyi +++ b/third_party/2and3/click/types.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, IO, Iterable, List, Optional, TypeVar, Union, Tuple as _PyTuple, Type +from typing import Any, Callable, Generic, IO, Iterable, List, Optional, TypeVar, Union, Tuple as _PyTuple, Type import datetime import uuid @@ -71,8 +71,13 @@ class FloatParamType(ParamType): class FloatRange(FloatParamType): - ... - + def __init__( + self, + min: Optional[float] = ..., + max: Optional[float] = ..., + clamp: bool = ..., + ) -> None: + ... class File(ParamType): def __init__( @@ -82,38 +87,19 @@ class File(ParamType): errors: Optional[str] = ..., lazy: Optional[bool] = ..., atomic: Optional[bool] = ..., - ) -> None: - ... - - def __call__( - self, - value: Optional[str], - param: Optional[Parameter] = ..., - ctx: Optional[Context] = ..., - ) -> IO: - ... - - def convert( - self, - value: str, - param: Optional[Parameter], - ctx: Optional[Context], - ) -> IO: - ... - - def resolve_lazy_flag(self, value: str) -> bool: - ... - + ) -> None: ... + def __call__(self, value: Optional[str], param: Optional[Parameter] = ..., ctx: Optional[Context] = ...) -> IO[Any]: ... + def convert(self, value: str, param: Optional[Parameter], ctx: Optional[Context]) -> IO[Any]: ... + def resolve_lazy_flag(self, value: str) -> bool: ... _F = TypeVar('_F') # result of the function _Func = Callable[[Optional[str]], _F] -class FuncParamType(ParamType): - func: _Func +class FuncParamType(ParamType, Generic[_F]): + func: _Func[_F] - def __init__(self, func: _Func) -> None: - ... + def __init__(self, func: _Func[_F]) -> None: ... def __call__( self, diff --git a/third_party/2and3/click/utils.pyi b/third_party/2and3/click/utils.pyi index 547c5e80d85c..d4fc17e9b965 100644 --- a/third_party/2and3/click/utils.pyi +++ b/third_party/2and3/click/utils.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Iterator, IO, List, Optional, TypeVar, Union, Text +from typing import Any, AnyStr, Callable, Generic, Iterator, IO, List, Optional, TypeVar, Union, Text _T = TypeVar('_T') @@ -19,7 +19,7 @@ def make_default_short_help(help: str, max_length: int = ...): ... -class LazyFile: +class LazyFile(object): name: str mode: str encoding: Optional[str] @@ -33,47 +33,24 @@ class LazyFile: encoding: Optional[str] = ..., errors: str = ..., atomic: bool = ... - ) -> None: - ... - - def open(self) -> IO: - ... - - def close(self) -> None: - ... - - def close_intelligently(self) -> None: - ... - - def __enter__(self) -> LazyFile: - ... - - def __exit__(self, exc_type, exc_value, tb): - ... - - def __iter__(self) -> Iterator: - ... - - -class KeepOpenFile: - _file: IO - - def __init__(self, file: IO) -> None: - ... - - def __enter__(self) -> KeepOpenFile: - ... - - def __exit__(self, exc_type, exc_value, tb): - ... - - def __iter__(self) -> Iterator: - ... - + ) -> None: ... + def open(self) -> IO[Any]: ... + def close(self) -> None: ... + def close_intelligently(self) -> None: ... + def __enter__(self) -> LazyFile: ... + def __exit__(self, exc_type, exc_value, tb): ... + def __iter__(self) -> Iterator[Any]: ... + +class KeepOpenFile(Generic[AnyStr]): + _file: IO[AnyStr] + def __init__(self, file: IO[AnyStr]) -> None: ... + def __enter__(self) -> KeepOpenFile[AnyStr]: ... + def __exit__(self, exc_type, exc_value, tb): ... + def __iter__(self) -> Iterator[AnyStr]: ... def echo( message: object = ..., - file: Optional[IO] = ..., + file: Optional[IO[Text]] = ..., nl: bool = ..., err: bool = ..., color: Optional[bool] = ..., @@ -90,7 +67,6 @@ def get_text_stream( ) -> IO[str]: ... - def open_file( filename: str, mode: str = ..., @@ -98,14 +74,10 @@ def open_file( errors: str = ..., lazy: bool = ..., atomic: bool = ... -) -> Union[IO, LazyFile, KeepOpenFile]: - ... - - +) -> Any: ... # really Union[IO, LazyFile, KeepOpenFile] def get_os_args() -> List[str]: ... - def format_filename(filename: str, shorten: bool = ...) -> str: ... diff --git a/third_party/2/cryptography/__init__.pyi b/third_party/2and3/cryptography/__init__.pyi similarity index 100% rename from third_party/2/cryptography/__init__.pyi rename to third_party/2and3/cryptography/__init__.pyi diff --git a/third_party/2/cryptography/hazmat/__init__.pyi b/third_party/2and3/cryptography/hazmat/__init__.pyi similarity index 100% rename from third_party/2/cryptography/hazmat/__init__.pyi rename to third_party/2and3/cryptography/hazmat/__init__.pyi diff --git a/third_party/2/cryptography/hazmat/primitives/__init__.pyi b/third_party/2and3/cryptography/hazmat/primitives/__init__.pyi similarity index 100% rename from third_party/2/cryptography/hazmat/primitives/__init__.pyi rename to third_party/2and3/cryptography/hazmat/primitives/__init__.pyi diff --git a/third_party/2/cryptography/hazmat/primitives/asymmetric/__init__.pyi b/third_party/2and3/cryptography/hazmat/primitives/asymmetric/__init__.pyi similarity index 100% rename from third_party/2/cryptography/hazmat/primitives/asymmetric/__init__.pyi rename to third_party/2and3/cryptography/hazmat/primitives/asymmetric/__init__.pyi diff --git a/third_party/2/cryptography/hazmat/primitives/asymmetric/dsa.pyi b/third_party/2and3/cryptography/hazmat/primitives/asymmetric/dsa.pyi similarity index 100% rename from third_party/2/cryptography/hazmat/primitives/asymmetric/dsa.pyi rename to third_party/2and3/cryptography/hazmat/primitives/asymmetric/dsa.pyi diff --git a/third_party/2/cryptography/hazmat/primitives/asymmetric/rsa.pyi b/third_party/2and3/cryptography/hazmat/primitives/asymmetric/rsa.pyi similarity index 97% rename from third_party/2/cryptography/hazmat/primitives/asymmetric/rsa.pyi rename to third_party/2and3/cryptography/hazmat/primitives/asymmetric/rsa.pyi index 006e8221e6c5..310ced7ca0c8 100644 --- a/third_party/2/cryptography/hazmat/primitives/asymmetric/rsa.pyi +++ b/third_party/2and3/cryptography/hazmat/primitives/asymmetric/rsa.pyi @@ -25,7 +25,7 @@ class RSAPublicKey: RSAPublicKeyWithSerialization = RSAPublicKey -def generate_private_key(public_exponent: int, key_size: int, backend) -> RSAPrivateKey: ... +def generate_private_key(public_exponent: int, key_size: int, backend) -> RSAPrivateKeyWithSerialization: ... def rsa_crt_iqmp(p: int, q: int) -> int: ... def rsa_crt_dmp1(private_exponent: int, p: int) -> int: ... def rsa_crt_dmq1(private_exponent: int, q: int) -> int: ... diff --git a/third_party/2/cryptography/hazmat/primitives/serialization.pyi b/third_party/2and3/cryptography/hazmat/primitives/serialization.pyi similarity index 100% rename from third_party/2/cryptography/hazmat/primitives/serialization.pyi rename to third_party/2and3/cryptography/hazmat/primitives/serialization.pyi diff --git a/third_party/2and3/dateutil/_common.pyi b/third_party/2and3/dateutil/_common.pyi index 1311a175e1ba..7f1b23957bab 100644 --- a/third_party/2and3/dateutil/_common.pyi +++ b/third_party/2and3/dateutil/_common.pyi @@ -1,9 +1,11 @@ -from typing import Optional +from typing import Optional, TypeVar + +_T = TypeVar("_T") class weekday(object): def __init__(self, weekday: int, n: Optional[int] = ...) -> None: ... - def __call__(self, n: int) -> weekday: ... + def __call__(self: _T, n: int) -> _T: ... def __eq__(self, other) -> bool: ... diff --git a/third_party/2and3/dateutil/rrule.pyi b/third_party/2and3/dateutil/rrule.pyi index f8ab9d29ad36..a459abe3efde 100644 --- a/third_party/2and3/dateutil/rrule.pyi +++ b/third_party/2and3/dateutil/rrule.pyi @@ -35,18 +35,18 @@ class rrulebase: class rrule(rrulebase): def __init__(self, freq, - dtstart: Optional[datetime.datetime] = ..., + dtstart: Optional[datetime.date] = ..., interval: int = ..., wkst: Optional[Union[weekday, int]] = ..., count: Optional[int] = ..., - until: Optional[Union[datetime.datetime, int]] = ..., + until: Optional[Union[datetime.date, int]] = ..., bysetpos: Optional[Union[int, Iterable[int]]] = ..., bymonth: Optional[Union[int, Iterable[int]]] = ..., bymonthday: Optional[Union[int, Iterable[int]]] = ..., byyearday: Optional[Union[int, Iterable[int]]] = ..., byeaster: Optional[Union[int, Iterable[int]]] = ..., byweekno: Optional[Union[int, Iterable[int]]] = ..., - byweekday: Optional[Union[int, Iterable[int]]] = ..., + byweekday: Optional[Union[int, weekday, Iterable[int], Iterable[weekday]]] = ..., byhour: Optional[Union[int, Iterable[int]]] = ..., byminute: Optional[Union[int, Iterable[int]]] = ..., bysecond: Optional[Union[int, Iterable[int]]] = ..., diff --git a/third_party/2and3/emoji.pyi b/third_party/2and3/emoji.pyi index fe193b124574..695018e5e9b6 100644 --- a/third_party/2and3/emoji.pyi +++ b/third_party/2and3/emoji.pyi @@ -1,4 +1,4 @@ -from typing import Tuple, Pattern, List, Dict, Union +from typing import Tuple, Pattern, List, Dict, Union, Text _DEFAULT_DELIMITER: str @@ -13,6 +13,6 @@ def demojize( delimiters: Tuple[str, str] = ... ) -> str: ... -def get_emoji_regexp() -> Pattern: ... +def get_emoji_regexp() -> Pattern[Text]: ... def emoji_lis(string: str) -> List[Dict[str, Union[int, str]]]: ... diff --git a/third_party/2and3/flask/app.pyi b/third_party/2and3/flask/app.pyi index 5be3d6d5931b..654d41c1f07f 100644 --- a/third_party/2and3/flask/app.pyi +++ b/third_party/2and3/flask/app.pyi @@ -13,13 +13,51 @@ from .signals import appcontext_tearing_down, got_request_exception, request_fin from .templating import DispatchingJinjaLoader, Environment from .wrappers import Request, Response from .testing import FlaskClient -from typing import Any, Callable, ContextManager, Dict, List, Optional, Type, TypeVar, Union, Text +from types import TracebackType +from typing import ( + Any, + Callable, + ContextManager, + Dict, + List, + Optional, + Type, + TypeVar, + Union, + Text, + Tuple, + NoReturn, + Iterable, + ByteString +) from datetime import timedelta def setupmethod(f: Any): ... _T = TypeVar('_T') + +_ExcInfo = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]] +_StartResponse = Callable[[str, List[Tuple[str, str]], Optional[_ExcInfo]], Callable[[bytes], Any]] +_WSGICallable = Callable[[Dict[Text, Any], _StartResponse], Iterable[bytes]] + +_Status = Union[str, int] +_Headers = Union[Dict[Any, Any], List[Tuple[Any, Any]]] +_Body = Union[Text, ByteString, Dict[Text, Any], Response, _WSGICallable] +_ViewFuncReturnType = Union[ + _Body, + Tuple[_Body, _Status, _Headers], + Tuple[_Body, _Status], + Tuple[_Body, _Headers], +] + +_ViewFunc = Union[ + Callable[..., NoReturn], + Callable[..., _ViewFuncReturnType], +] +_VT = TypeVar('_VT', bound=_ViewFunc) + + class Flask(_PackageBoundObject): request_class: type = ... response_class: type = ... @@ -89,15 +127,15 @@ class Flask(_PackageBoundObject): env: Optional[str] = ... debug: bool = ... def run(self, host: Optional[str] = ..., port: Optional[Union[int, str]] = ..., debug: Optional[bool] = ..., load_dotenv: bool = ..., **options: Any) -> None: ... - def test_client(self, use_cookies: bool = ..., **kwargs: Any) -> FlaskClient: ... + def test_client(self, use_cookies: bool = ..., **kwargs: Any) -> FlaskClient[Response]: ... def test_cli_runner(self, **kwargs: Any): ... def open_session(self, request: Any): ... def save_session(self, session: Any, response: Any): ... def make_null_session(self): ... def register_blueprint(self, blueprint: Blueprint, **options: Any) -> None: ... def iter_blueprints(self): ... - def add_url_rule(self, rule: str, endpoint: Optional[str] = ..., view_func: Callable[..., Any] = ..., provide_automatic_options: Optional[bool] = ..., **options: Any) -> None: ... - def route(self, rule: str, **options: Any) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... + def add_url_rule(self, rule: str, endpoint: Optional[str] = ..., view_func: _ViewFunc = ..., provide_automatic_options: Optional[bool] = ..., **options: Any) -> None: ... + def route(self, rule: str, **options: Any) -> Callable[[_VT], _VT]: ... def endpoint(self, endpoint: str) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... def errorhandler(self, code_or_exception: Union[int, Type[Exception]]) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... def register_error_handler(self, code_or_exception: Union[int, Type[Exception]], f: Callable[..., Any]) -> None: ... diff --git a/third_party/2and3/flask/blueprints.pyi b/third_party/2and3/flask/blueprints.pyi index d43f8e4ff612..d534ac8a14b3 100644 --- a/third_party/2and3/flask/blueprints.pyi +++ b/third_party/2and3/flask/blueprints.pyi @@ -3,9 +3,11 @@ # NOTE: This dynamically typed stub was automatically generated by stubgen. from .helpers import _PackageBoundObject +from .app import _ViewFunc from typing import Any, Callable, Optional, Type, TypeVar, Union _T = TypeVar('_T') +_VT = TypeVar('_VT', bound=_ViewFunc) class BlueprintSetupState: app: Any = ... @@ -16,7 +18,7 @@ class BlueprintSetupState: url_prefix: Any = ... url_defaults: Any = ... def __init__(self, blueprint: Any, app: Any, options: Any, first_registration: Any) -> None: ... - def add_url_rule(self, rule: str, endpoint: Optional[str] = ..., view_func: Callable[..., Any] = ..., **options: Any) -> None: ... + def add_url_rule(self, rule: str, endpoint: Optional[str] = ..., view_func: _ViewFunc = ..., **options: Any) -> None: ... class Blueprint(_PackageBoundObject): warn_on_modifications: bool = ... @@ -37,8 +39,8 @@ class Blueprint(_PackageBoundObject): def record_once(self, func: Any): ... def make_setup_state(self, app: Any, options: Any, first_registration: bool = ...): ... def register(self, app: Any, options: Any, first_registration: bool = ...) -> None: ... - def route(self, rule: str, **options: Any) -> Callable[[Callable[..., Any]], Callable[..., Any]]: ... - def add_url_rule(self, rule: str, endpoint: Optional[str] = ..., view_func: Callable[..., Any] = ..., **options: Any) -> None: ... + def route(self, rule: str, **options: Any) -> Callable[[_VT], _VT]: ... + def add_url_rule(self, rule: str, endpoint: Optional[str] = ..., view_func: _ViewFunc = ..., **options: Any) -> None: ... def endpoint(self, endpoint: str) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... def app_template_filter(self, name: Optional[Any] = ...): ... def add_app_template_filter(self, f: Any, name: Optional[Any] = ...) -> None: ... diff --git a/third_party/2and3/flask/sessions.pyi b/third_party/2and3/flask/sessions.pyi index b0d238d90127..aa6cb6ef4a83 100644 --- a/third_party/2and3/flask/sessions.pyi +++ b/third_party/2and3/flask/sessions.pyi @@ -6,7 +6,7 @@ from abc import ABCMeta from typing import Any, MutableMapping, Optional from werkzeug.datastructures import CallbackDict -class SessionMixin(MutableMapping, metaclass=ABCMeta): +class SessionMixin(MutableMapping[str, Any], metaclass=ABCMeta): @property def permanent(self): ... @permanent.setter @@ -15,7 +15,7 @@ class SessionMixin(MutableMapping, metaclass=ABCMeta): modified: bool = ... accessed: bool = ... -class SecureCookieSession(CallbackDict, SessionMixin): +class SecureCookieSession(CallbackDict[str, Any], SessionMixin): modified: bool = ... accessed: bool = ... def __init__(self, initial: Optional[Any] = ...) -> None: ... diff --git a/third_party/2and3/flask/templating.pyi b/third_party/2and3/flask/templating.pyi index 1da102d2bcd4..87d77152740b 100644 --- a/third_party/2and3/flask/templating.pyi +++ b/third_party/2and3/flask/templating.pyi @@ -5,7 +5,7 @@ from .globals import _app_ctx_stack, _request_ctx_stack from .signals import before_render_template, template_rendered from jinja2 import BaseLoader, Environment as BaseEnvironment -from typing import Any +from typing import Any, Text, Iterable, Union class Environment(BaseEnvironment): app: Any = ... @@ -17,5 +17,8 @@ class DispatchingJinjaLoader(BaseLoader): def get_source(self, environment: Any, template: Any): ... def list_templates(self): ... -def render_template(template_name_or_list: Any, **context: Any): ... -def render_template_string(source: Any, **context: Any): ... +def render_template( + template_name_or_list: Union[Text, Iterable[Text]], + **context: Any +) -> Text: ... +def render_template_string(source: Text, **context: Any) -> Text: ... diff --git a/third_party/2and3/flask/testing.pyi b/third_party/2and3/flask/testing.pyi index 813eeca4d27e..45a0065b1977 100644 --- a/third_party/2and3/flask/testing.pyi +++ b/third_party/2and3/flask/testing.pyi @@ -4,17 +4,21 @@ from click import BaseCommand from click.testing import CliRunner, Result -from typing import Any, IO, Iterable, Mapping, Optional, Union +from typing import Any, IO, Iterable, Mapping, Optional, Text, TypeVar, Union from werkzeug.test import Client def make_test_environ_builder(app: Any, path: str = ..., base_url: Optional[Any] = ..., subdomain: Optional[Any] = ..., url_scheme: Optional[Any] = ..., *args: Any, **kwargs: Any): ... -class FlaskClient(Client): +# Response type for the client below. +# By default _R is Tuple[Iterable[Any], Union[Text, int], werkzeug.datastructures.Headers], however +# most commonly it is wrapped in a Reponse object. +_R = TypeVar('_R') + +class FlaskClient(Client[_R]): preserve_context: bool = ... environ_base: Any = ... def __init__(self, *args: Any, **kwargs: Any) -> None: ... def session_transaction(self, *args: Any, **kwargs: Any) -> None: ... - def open(self, *args: Any, **kwargs: Any): ... def __enter__(self): ... def __exit__(self, exc_type: Any, exc_value: Any, tb: Any) -> None: ... @@ -25,7 +29,7 @@ class FlaskCliRunner(CliRunner): self, cli: Optional[BaseCommand] = ..., args: Optional[Union[str, Iterable[str]]] = ..., - input: Optional[IO] = ..., + input: Optional[Union[bytes, IO[Any], Text]] = ..., env: Optional[Mapping[str, str]] = ..., catch_exceptions: bool = ..., color: bool = ..., diff --git a/third_party/2and3/google/protobuf/internal/containers.pyi b/third_party/2and3/google/protobuf/internal/containers.pyi index 33e603c93e58..06efb544d560 100644 --- a/third_party/2and3/google/protobuf/internal/containers.pyi +++ b/third_party/2and3/google/protobuf/internal/containers.pyi @@ -35,10 +35,13 @@ class RepeatedScalarFieldContainer(BaseContainer[_T]): def __setslice__(self, start: int, stop: int, values: Iterable[_T]) -> None: ... def __delitem__(self, key: Union[int, slice]) -> None: ... def __delslice__(self, start: int, stop: int) -> None: ... + def __eq__(self, other: object) -> bool: ... class RepeatedCompositeFieldContainer(BaseContainer[_T]): def __init__(self, message_listener: MessageListener, type_checker: Any) -> None: ... def add(self, **kwargs: Any) -> _T: ... + def append(self, value: _T) -> None: ... + def insert(self, key: int, value: _T) -> None: ... def extend(self, elem_seq: Iterable[_T]) -> None: ... def MergeFrom(self, other: RepeatedCompositeFieldContainer[_T]) -> None: ... def remove(self, elem: _T) -> None: ... @@ -46,6 +49,7 @@ class RepeatedCompositeFieldContainer(BaseContainer[_T]): def __getslice__(self, start: int, stop: int) -> List[_T]: ... def __delitem__(self, key: Union[int, slice]) -> None: ... def __delslice__(self, start: int, stop: int) -> None: ... + def __eq__(self, other: object) -> bool: ... # Classes not yet typed class Mapping(Any): ... diff --git a/third_party/2and3/itsdangerous.pyi b/third_party/2and3/itsdangerous.pyi index 32bbf2bb12be..6e627c771000 100644 --- a/third_party/2and3/itsdangerous.pyi +++ b/third_party/2and3/itsdangerous.pyi @@ -39,20 +39,20 @@ class NoneAlgorithm(SigningAlgorithm): def get_signature(self, key: bytes, value: bytes) -> bytes: ... class HMACAlgorithm(SigningAlgorithm): - default_digest_method: Callable - digest_method: Callable - def __init__(self, digest_method: Optional[Callable] = ...) -> None: ... + default_digest_method: Callable[..., Any] + digest_method: Callable[..., Any] + def __init__(self, digest_method: Optional[Callable[..., Any]] = ...) -> None: ... def get_signature(self, key: bytes, value: bytes) -> bytes: ... class Signer(object): - default_digest_method: Callable = ... + default_digest_method: Callable[..., Any] = ... default_key_derivation: str = ... secret_key: bytes sep: bytes salt: Union[Text, bytes] key_derivation: str - digest_method: Callable + digest_method: Callable[..., Any] algorithm: SigningAlgorithm def __init__(self, @@ -60,7 +60,7 @@ class Signer(object): salt: Optional[Union[Text, bytes]] = ..., sep: Optional[Union[Text, bytes]] = ..., key_derivation: Optional[str] = ..., - digest_method: Optional[Callable] = ..., + digest_method: Optional[Callable[..., Any]] = ..., algorithm: Optional[SigningAlgorithm] = ...) -> None: ... def derive_key(self) -> bytes: ... def get_signature(self, value: Union[Text, bytes]) -> bytes: ... @@ -126,7 +126,7 @@ class JSONWebSignatureSerializer(Serializer): def make_signer(self, salt: Optional[Union[Text, bytes]] = ..., algorithm: SigningAlgorithm = ...) -> Signer: ... def make_header(self, header_fields: Optional[Mapping[str, Any]]) -> MutableMapping[str, Any]: ... def dumps(self, obj: Any, salt: Optional[Union[Text, bytes]] = ..., - header_fields: Optional[Mapping[str, Any]] = ...) -> str: ... + header_fields: Optional[Mapping[str, Any]] = ...) -> bytes: ... def loads(self, s: Union[Text, bytes], salt: Optional[Union[Text, bytes]] = ..., return_header: bool = ...) -> Any: ... # morally -> Union[Any, Tuple[Any, MutableMapping[str, Any]]] def loads_unsafe(self, s: Union[Text, bytes], salt: Optional[Union[Text, bytes]] = ..., diff --git a/third_party/2and3/jinja2/environment.pyi b/third_party/2and3/jinja2/environment.pyi index f5997a3aa63b..29704c606e71 100644 --- a/third_party/2and3/jinja2/environment.pyi +++ b/third_party/2and3/jinja2/environment.pyi @@ -36,7 +36,7 @@ class Environment: keep_trailing_newline: bool undefined: Type[Undefined] optimized: bool - finalize: Callable + finalize: Callable[..., Any] autoescape: Any filters: Any tests: Any @@ -45,11 +45,56 @@ class Environment: cache: Any bytecode_cache: BytecodeCache auto_reload: bool - extensions: List - def __init__(self, block_start_string: Text = ..., block_end_string: Text = ..., variable_start_string: Text = ..., variable_end_string: Text = ..., comment_start_string: Any = ..., comment_end_string: Text = ..., line_statement_prefix: Text = ..., line_comment_prefix: Text = ..., trim_blocks: bool = ..., lstrip_blocks: bool = ..., newline_sequence: Text = ..., keep_trailing_newline: bool = ..., extensions: List = ..., optimized: bool = ..., undefined: Type[Undefined] = ..., finalize: Optional[Callable] = ..., autoescape: Union[bool, Callable[[str], bool]] = ..., loader: Optional[BaseLoader] = ..., cache_size: int = ..., auto_reload: bool = ..., bytecode_cache: Optional[BytecodeCache] = ..., enable_async: bool = ...) -> None: ... + extensions: List[Any] + def __init__( + self, + block_start_string: Text = ..., + block_end_string: Text = ..., + variable_start_string: Text = ..., + variable_end_string: Text = ..., + comment_start_string: Any = ..., + comment_end_string: Text = ..., + line_statement_prefix: Text = ..., + line_comment_prefix: Text = ..., + trim_blocks: bool = ..., + lstrip_blocks: bool = ..., + newline_sequence: Text = ..., + keep_trailing_newline: bool = ..., + extensions: List[Any] = ..., + optimized: bool = ..., + undefined: Type[Undefined] = ..., + finalize: Optional[Callable[..., Any]] = ..., + autoescape: Union[bool, Callable[[str], bool]] = ..., + loader: Optional[BaseLoader] = ..., + cache_size: int = ..., + auto_reload: bool = ..., + bytecode_cache: Optional[BytecodeCache] = ..., + enable_async: bool = ..., + ) -> None: ... def add_extension(self, extension): ... def extend(self, **attributes): ... - def overlay(self, block_start_string: Text = ..., block_end_string: Text = ..., variable_start_string: Text = ..., variable_end_string: Text = ..., comment_start_string: Any = ..., comment_end_string: Text = ..., line_statement_prefix: Text = ..., line_comment_prefix: Text = ..., trim_blocks: bool = ..., lstrip_blocks: bool = ..., extensions: List = ..., optimized: bool = ..., undefined: Type[Undefined] = ..., finalize: Callable = ..., autoescape: bool = ..., loader: Optional[BaseLoader] = ..., cache_size: int = ..., auto_reload: bool = ..., bytecode_cache: Optional[BytecodeCache] = ...): ... + def overlay( + self, + block_start_string: Text = ..., + block_end_string: Text = ..., + variable_start_string: Text = ..., + variable_end_string: Text = ..., + comment_start_string: Any = ..., + comment_end_string: Text = ..., + line_statement_prefix: Text = ..., + line_comment_prefix: Text = ..., + trim_blocks: bool = ..., + lstrip_blocks: bool = ..., + extensions: List[Any] = ..., + optimized: bool = ..., + undefined: Type[Undefined] = ..., + finalize: Callable[..., Any] = ..., + autoescape: bool = ..., + loader: Optional[BaseLoader] = ..., + cache_size: int = ..., + auto_reload: bool = ..., + bytecode_cache: Optional[BytecodeCache] = ..., + ): ... lexer: Any def iter_extensions(self): ... def getitem(self, obj, argument): ... @@ -75,8 +120,7 @@ class Environment: # from InternationalizationExtension: def install_gettext_translations(self, translations: Any, newstyle: Optional[bool]): ... def install_null_translations(self, newstyle: Optional[bool]): ... - def install_gettext_callables(self, gettext: Callable, ngettext: Callable, - newstyle: Optional[bool]): ... + def install_gettext_callables(self, gettext: Callable[..., Any], ngettext: Callable[..., Any], newstyle: Optional[bool]): ... def uninstall_gettext_translations(self, translations: Any): ... def extract_translations(self, source: Any, gettext_functions: Any): ... newstyle_gettext: bool diff --git a/third_party/2and3/jinja2/filters.pyi b/third_party/2and3/jinja2/filters.pyi index e0d9c8e8f26a..44b7bb57e371 100644 --- a/third_party/2and3/jinja2/filters.pyi +++ b/third_party/2and3/jinja2/filters.pyi @@ -1,4 +1,4 @@ -from typing import Any, Optional +from typing import Any, NamedTuple, Optional def contextfilter(f): ... def evalcontextfilter(f): ... @@ -37,10 +37,7 @@ def do_batch(value, linecount, fill_with: Optional[Any] = ...): ... def do_round(value, precision: int = ..., method: str = ...): ... def do_groupby(environment, value, attribute): ... -class _GroupTuple(tuple): - grouper: Any - list: Any - def __new__(cls, xxx_todo_changeme): ... +_GroupTuple = NamedTuple("_GroupTuple", [("grouper", Any), ("list", Any)]) def do_sum(environment, iterable, attribute: Optional[Any] = ..., start: int = ...): ... def do_list(value): ... diff --git a/third_party/2and3/jinja2/lexer.pyi b/third_party/2and3/jinja2/lexer.pyi index 182a2fbc488b..88d80e69c92d 100644 --- a/third_party/2and3/jinja2/lexer.pyi +++ b/third_party/2and3/jinja2/lexer.pyi @@ -1,4 +1,4 @@ -from typing import Any, Optional +from typing import Any, Optional, Tuple whitespace_re: Any string_re: Any @@ -72,7 +72,7 @@ class Failure: def __init__(self, message, cls: Any = ...) -> None: ... def __call__(self, lineno, filename): ... -class Token(tuple): +class Token(Tuple[int, Any, Any]): lineno: Any type: Any value: Any diff --git a/third_party/2and3/jinja2/loaders.pyi b/third_party/2and3/jinja2/loaders.pyi index 330de41c4ce5..95a8e3e9f6d8 100644 --- a/third_party/2and3/jinja2/loaders.pyi +++ b/third_party/2and3/jinja2/loaders.pyi @@ -16,7 +16,7 @@ class FileSystemLoader(BaseLoader): encoding: Any followlinks: Any def __init__(self, searchpath: Union[Text, Iterable[Text]], encoding: Text = ..., followlinks: bool = ...) -> None: ... - def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Text, Callable]: ... + def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Text, Callable[..., Any]]: ... def list_templates(self): ... class PackageLoader(BaseLoader): @@ -26,33 +26,35 @@ class PackageLoader(BaseLoader): provider: Any package_path: Any def __init__(self, package_name: Text, package_path: Text = ..., encoding: Text = ...) -> None: ... - def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Text, Callable]: ... + def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Text, Callable[..., Any]]: ... def list_templates(self): ... class DictLoader(BaseLoader): mapping: Any def __init__(self, mapping) -> None: ... - def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Text, Callable]: ... + def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Text, Callable[..., Any]]: ... def list_templates(self): ... class FunctionLoader(BaseLoader): load_func: Any def __init__(self, load_func) -> None: ... - def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Optional[Text], Optional[Callable]]: ... + def get_source( + self, environment: Environment, template: Text, + ) -> Tuple[Text, Optional[Text], Optional[Callable[..., Any]]]: ... class PrefixLoader(BaseLoader): mapping: Any delimiter: Any def __init__(self, mapping, delimiter: str = ...) -> None: ... def get_loader(self, template): ... - def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Text, Callable]: ... + def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Text, Callable[..., Any]]: ... def load(self, environment, name, globals: Optional[Any] = ...): ... def list_templates(self): ... class ChoiceLoader(BaseLoader): loaders: Any def __init__(self, loaders) -> None: ... - def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Text, Callable]: ... + def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Text, Callable[..., Any]]: ... def load(self, environment, name, globals: Optional[Any] = ...): ... def list_templates(self): ... diff --git a/third_party/2and3/markupsafe/__init__.pyi b/third_party/2and3/markupsafe/__init__.pyi index 44d15da3a54c..6bedd247613b 100644 --- a/third_party/2and3/markupsafe/__init__.pyi +++ b/third_party/2and3/markupsafe/__init__.pyi @@ -49,5 +49,5 @@ class EscapeFormatter(string.Formatter): def __init__(self, escape: Callable[[text_type], Markup]) -> None: ... def format_field(self, value: text_type, format_spec: text_type) -> Markup: ... -if sys.version_info[0] >= 3: +if sys.version_info >= (3,): soft_str = soft_unicode diff --git a/third_party/2and3/markupsafe/_compat.pyi b/third_party/2and3/markupsafe/_compat.pyi index 7257425cf6bc..9ca94010112d 100644 --- a/third_party/2and3/markupsafe/_compat.pyi +++ b/third_party/2and3/markupsafe/_compat.pyi @@ -7,7 +7,7 @@ _V = TypeVar('_V') PY2: bool def iteritems(d: Mapping[_K, _V]) -> Iterator[Tuple[_K, _V]]: ... -if sys.version_info[0] >= 3: +if sys.version_info >= (3,): text_type = str string_types = str, unichr = chr diff --git a/third_party/2and3/mock.pyi b/third_party/2and3/mock.pyi index cb3db6198b41..b4c4ce38aab9 100644 --- a/third_party/2and3/mock.pyi +++ b/third_party/2and3/mock.pyi @@ -1,7 +1,9 @@ # Stubs for mock import sys -from typing import Any, Optional, Text, Type +from typing import Any, List, Optional, Text, Tuple, Type, TypeVar + +_T = TypeVar("_T") FILTER_DIR: Any @@ -18,7 +20,7 @@ class _Sentinel: sentinel: Any DEFAULT: Any -class _CallList(list): +class _CallList(List[_T]): def __contains__(self, value: Any) -> bool: ... class _MockIter: @@ -33,14 +35,14 @@ class Base: # TODO: Defining this and other mock classes as classes in this stub causes # many false positives with mypy and production code. See if we can # improve mypy somehow and use a class with an "Any" base class. -NonCallableMock: Any +NonCallableMock = Any class CallableMixin(Base): side_effect: Any def __init__(self, spec: Optional[Any] = ..., side_effect: Optional[Any] = ..., return_value: Any = ..., wraps: Optional[Any] = ..., name: Optional[Any] = ..., spec_set: Optional[Any] = ..., parent: Optional[Any] = ..., _spec_state: Optional[Any] = ..., _new_name: Any = ..., _new_parent: Optional[Any] = ..., **kwargs: Any) -> None: ... def __call__(_mock_self, *args: Any, **kwargs: Any) -> Any: ... -Mock: Any +Mock = Any class _patch: attribute_name: Any @@ -94,8 +96,8 @@ patch: _patcher class MagicMixin: def __init__(self, *args: Any, **kw: Any) -> None: ... -NonCallableMagicMock: Any -MagicMock: Any +NonCallableMagicMock = Any +MagicMock = Any class MagicProxy: name: Any @@ -111,7 +113,7 @@ class _ANY: ANY: Any -class _Call(tuple): +class _Call(Tuple[Any, ...]): def __new__(cls, value: Any = ..., name: Optional[Any] = ..., parent: Optional[Any] = ..., two: bool = ..., from_kall: bool = ...) -> Any: ... name: Any parent: Any @@ -140,7 +142,7 @@ class _SpecState: def mock_open(mock: Optional[Any] = ..., read_data: Any = ...) -> Any: ... -PropertyMock: Any +PropertyMock = Any if sys.version_info >= (3, 7): def seal(mock: Any) -> None: ... diff --git a/third_party/2and3/mypy_extensions.pyi b/third_party/2and3/mypy_extensions.pyi index f9c9ff6da6c0..19d99cc9d70c 100644 --- a/third_party/2and3/mypy_extensions.pyi +++ b/third_party/2and3/mypy_extensions.pyi @@ -1,7 +1,8 @@ import abc import sys from typing import ( - Dict, Type, TypeVar, Optional, Union, Any, Generic, Mapping, ItemsView, KeysView, ValuesView + Dict, Type, TypeVar, Optional, Union, Any, Generic, Mapping, ItemsView, KeysView, ValuesView, + Callable, ) _T = TypeVar('_T') @@ -23,7 +24,7 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta): def viewvalues(self) -> ValuesView[object]: ... def __delitem__(self, k: NoReturn) -> None: ... -def TypedDict(typename: str, fields: Dict[str, Type[_T]], total: bool = ...) -> Type[dict]: ... +def TypedDict(typename: str, fields: Dict[str, Type[_T]], total: bool = ...) -> Type[Dict[str, Any]]: ... def Arg(type: _T = ..., name: Optional[str] = ...) -> _T: ... def DefaultArg(type: _T = ..., name: Optional[str] = ...) -> _T: ... @@ -41,4 +42,6 @@ NoReturn = Union[None] # Deprecated: Use typing.NoReturn instead. # when a Type[_T] is expected, so we can't give it the type we want def trait(cls: Any) -> Any: ... +def mypyc_attr(*attrs: str, **kwattrs: object) -> Callable[[_T], _T]: ... + class FlexibleAlias(Generic[_T, _U]): ... diff --git a/third_party/2and3/pycurl.pyi b/third_party/2and3/pycurl.pyi index 0d9da02d3706..ec70d764fbf9 100644 --- a/third_party/2and3/pycurl.pyi +++ b/third_party/2and3/pycurl.pyi @@ -1,6 +1,6 @@ # TODO(MichalPokorny): more precise types -from typing import Any, Tuple +from typing import Any, List, Tuple GLOBAL_ACK_EINTR: int GLOBAL_ALL: int @@ -14,8 +14,7 @@ def global_cleanup() -> None: ... version: str -def version_info() -> Tuple[int, str, int, str, int, str, - int, str, tuple, Any, int, Any]: ... +def version_info() -> Tuple[int, str, int, str, int, str, int, str, Tuple[str, ...], Any, int, Any]: ... class error(Exception): ... @@ -37,9 +36,9 @@ class CurlMulti(object): def add_handle(self, obj: Curl) -> None: ... def remove_handle(self, obj: Curl) -> None: ... def perform(self) -> Tuple[Any, int]: ... - def fdset(self) -> tuple: ... + def fdset(self) -> Tuple[List[Any], List[Any], List[Any]]: ... def select(self, timeout: float = ...) -> int: ... - def info_read(self, max_objects: int = ...) -> tuple: ... + def info_read(self, max_objects: int = ...) -> Tuple[int, List[Any], List[Any]]: ... class CurlShare(object): def close(self) -> None: ... diff --git a/third_party/2and3/pymysql/connections.pyi b/third_party/2and3/pymysql/connections.pyi index 4f1cd0486ec2..47e00a47dfaa 100644 --- a/third_party/2and3/pymysql/connections.pyi +++ b/third_party/2and3/pymysql/connections.pyi @@ -94,14 +94,14 @@ class Connection: socket: Any rfile: Any wfile: Any - def close(self): ... + def close(self) -> None: ... def autocommit(self, value): ... def commit(self): ... def begin(self) -> None: ... def rollback(self): ... def escape(self, obj): ... def literal(self, obj): ... - def cursor(self, cursor: Optional[Type[Cursor]] = ...): ... + def cursor(self, cursor: Optional[Type[Cursor]] = ...) -> Cursor: ... def __enter__(self): ... def __exit__(self, exc, value, traceback): ... def query(self, sql): ... diff --git a/third_party/2and3/pymysql/err.pyi b/third_party/2and3/pymysql/err.pyi index 29d4f55cd94b..b237af9a0202 100644 --- a/third_party/2and3/pymysql/err.pyi +++ b/third_party/2and3/pymysql/err.pyi @@ -1,4 +1,4 @@ -from typing import Dict +from typing import Dict, NoReturn, Type from .constants import ER as ER class MySQLError(Exception): ... @@ -13,6 +13,6 @@ class InternalError(DatabaseError): ... class ProgrammingError(DatabaseError): ... class NotSupportedError(DatabaseError): ... -error_map: Dict +error_map: Dict[int, Type[DatabaseError]] -def raise_mysql_exception(data) -> None: ... +def raise_mysql_exception(data) -> NoReturn: ... diff --git a/third_party/2and3/pynamodb/attributes.pyi b/third_party/2and3/pynamodb/attributes.pyi index 3c8247435cd7..a2e5088c4eca 100644 --- a/third_party/2and3/pynamodb/attributes.pyi +++ b/third_party/2and3/pynamodb/attributes.pyi @@ -5,7 +5,7 @@ from datetime import datetime _T = TypeVar('_T') _KT = TypeVar('_KT') _VT = TypeVar('_VT') -_MT = TypeVar('_MT', bound='MapAttribute') +_MT = TypeVar('_MT', bound=MapAttribute[Any, Any]) class Attribute(Generic[_T]): attr_name: Optional[Text] @@ -91,6 +91,6 @@ class ListAttribute(Generic[_T], Attribute[List[_T]]): def __init__(self, hash_key: bool = ..., range_key: bool = ..., null: Optional[bool] = ..., default: Optional[Union[Any, Callable[..., Any]]] = ..., attr_name: Optional[Text] = ..., of: Optional[Type[_T]] = ...) -> None: ... def __get__(self, instance: Any, owner: Any) -> List[_T]: ... -DESERIALIZE_CLASS_MAP: Dict[Text, Attribute] -SERIALIZE_CLASS_MAP: Dict[Type, Attribute] -SERIALIZE_KEY_MAP: Dict[Type, Text] +DESERIALIZE_CLASS_MAP: Dict[Text, Attribute[Any]] +SERIALIZE_CLASS_MAP: Dict[Type[Any], Attribute[Any]] +SERIALIZE_KEY_MAP: Dict[Type[Any], Text] diff --git a/third_party/2and3/pynamodb/connection/base.pyi b/third_party/2and3/pynamodb/connection/base.pyi index 9c751501798e..71c9d74fb2fd 100644 --- a/third_party/2and3/pynamodb/connection/base.pyi +++ b/third_party/2and3/pynamodb/connection/base.pyi @@ -4,8 +4,8 @@ BOTOCORE_EXCEPTIONS: Any log: Any class MetaTable: - data: Dict - def __init__(self, data: Dict) -> None: ... + data: Dict[Any, Any] + def __init__(self, data: Dict[Any, Any]) -> None: ... @property def range_keyname(self) -> Optional[Text]: ... @property diff --git a/third_party/2and3/pynamodb/models.pyi b/third_party/2and3/pynamodb/models.pyi index 5943a58d6f31..cf181395faa3 100644 --- a/third_party/2and3/pynamodb/models.pyi +++ b/third_party/2and3/pynamodb/models.pyi @@ -6,7 +6,7 @@ log: Any class DefaultMeta: ... -class ResultSet(Iterable): +class ResultSet(object): results: Any operation: Any arguments: Any @@ -17,7 +17,7 @@ class MetaModel(type): def __init__(self, name: Text, bases: Tuple[type, ...], attrs: Dict[Any, Any]) -> None: ... _T = TypeVar('_T', bound='Model') -KeyType = Union[Text, bytes, float, int, Tuple] +KeyType = Union[Text, bytes, float, int, Tuple[Any, ...]] class Model(metaclass=MetaModel): DoesNotExist = DoesNotExist @@ -86,9 +86,9 @@ class Model(metaclass=MetaModel): @classmethod def get_throttle(cls): ... @classmethod - def get_attributes(cls) -> Dict[str, Attribute]: ... + def get_attributes(cls) -> Dict[str, Attribute[Any]]: ... @classmethod - def _get_attributes(cls) -> Dict[str, Attribute]: ... + def _get_attributes(cls) -> Dict[str, Attribute[Any]]: ... class ModelContextManager(Generic[_T]): model: Type[_T] diff --git a/third_party/2and3/pyre_extensions.pyi b/third_party/2and3/pyre_extensions.pyi new file mode 100644 index 000000000000..742b88013256 --- /dev/null +++ b/third_party/2and3/pyre_extensions.pyi @@ -0,0 +1,7 @@ +from typing import Any, List, Optional, Type, TypeVar + +_T = TypeVar("_T") + +def none_throws(optional: Optional[_T], message: str = ...) -> _T: ... +def safe_cast(new_type: Type[_T], value: Any) -> _T: ... +def ParameterSpecification(__name: str) -> List[Type[Any]]: ... diff --git a/third_party/2and3/redis/client.pyi b/third_party/2and3/redis/client.pyi index f41676177336..ea692bb1a818 100644 --- a/third_party/2and3/redis/client.pyi +++ b/third_party/2and3/redis/client.pyi @@ -1,4 +1,7 @@ -from typing import Any +from datetime import timedelta +from typing import Any, Iterable, Text, Optional, Mapping, Tuple, Union, Callable, List + +from .connection import ConnectionPool SYM_EMPTY: Any @@ -31,21 +34,44 @@ def parse_hscan(response, **options): ... def parse_zscan(response, **options): ... def parse_slowlog_get(response, **options): ... -class StrictRedis: +_Str = Union[bytes, float, int, Text] + +class Redis(object): RESPONSE_CALLBACKS: Any @classmethod - def from_url(cls, url, db=..., **kwargs): ... + def from_url(cls, url: Text, db: Optional[int] = ..., **kwargs) -> Redis: ... connection_pool: Any response_callbacks: Any - def __init__(self, host=..., port=..., db=..., password=..., socket_timeout=..., socket_connect_timeout=..., - socket_keepalive=..., socket_keepalive_options=..., connection_pool=..., unix_socket_path=..., encoding=..., - encoding_errors=..., charset=..., errors=..., decode_responses=..., retry_on_timeout=..., ssl=..., - ssl_keyfile=..., ssl_certfile=..., ssl_cert_reqs=..., ssl_ca_certs=...) -> None: ... + def __init__( + self, + host: Text = ..., + port: int = ..., + db: int = ..., + password: Optional[Text] = ..., + socket_timeout: Optional[float] = ..., + socket_connect_timeout: Optional[float] = ..., + socket_keepalive: Optional[bool] = ..., + socket_keepalive_options: Optional[Mapping[str, Union[int, str]]] = ..., + connection_pool: Optional[ConnectionPool] = ..., + unix_socket_path: Optional[Text] = ..., + encoding: Text = ..., + encoding_errors: Text = ..., + charset: Optional[Text] = ..., + errors: Optional[Text] = ..., + decode_responses: bool = ..., + retry_on_timeout: bool = ..., + ssl: bool = ..., + ssl_keyfile: Optional[Text] = ..., + ssl_certfile: Optional[Text] = ..., + ssl_cert_reqs: Optional[Union[str, int]] = ..., + ssl_ca_certs: Optional[Text] = ..., + max_connections: Optional[int] = ..., + ) -> None: ... def set_response_callback(self, command, callback): ... def pipeline(self, transaction=..., shard_hint=...): ... def transaction(self, func, *watches, **kwargs): ... def lock(self, name, timeout=..., sleep=..., blocking_timeout=..., lock_class=..., thread_local=...): ... - def pubsub(self, **kwargs): ... + def pubsub(self, shard_hint: Any = ..., ignore_subscribe_messages: bool = ...) -> PubSub: ... def execute_command(self, *args, **options): ... def parse_response(self, connection, command_name, **options): ... def bgrewriteaof(self): ... @@ -58,12 +84,12 @@ class StrictRedis: def config_set(self, name, value): ... def config_resetstat(self): ... def config_rewrite(self): ... - def dbsize(self): ... + def dbsize(self) -> int: ... def debug_object(self, key): ... def echo(self, value): ... def flushall(self): ... def flushdb(self): ... - def info(self, section=...): ... + def info(self, section: Optional[Text] = ...) -> Mapping[str, Any]: ... def lastsave(self): ... def object(self, infotype, key): ... def ping(self): ... @@ -93,9 +119,9 @@ class StrictRedis: def dump(self, name): ... def exists(self, name): ... __contains__: Any - def expire(self, name, time): ... + def expire(self, name: Union[Text, bytes], time: Union[int, timedelta]) -> bool: ... def expireat(self, name, when): ... - def get(self, name): ... + def get(self, name: Union[Text, bytes]) -> Optional[bytes]: ... def __getitem__(self, name): ... def getbit(self, name, offset): ... def getrange(self, key, start, end): ... @@ -117,7 +143,15 @@ class StrictRedis: def rename(self, src, dst): ... def renamenx(self, src, dst): ... def restore(self, name, ttl, value): ... - def set(self, name, value, ex=..., px=..., nx=..., xx=...): ... + def set( + self, + name: Union[Text, bytes], + value: _Str, + ex: Union[None, int, timedelta] = ..., + px: Union[None, int, timedelta] = ..., + nx: bool = ..., + xx: bool = ..., + ) -> Optional[bool]: ... def __setitem__(self, name, value): ... def setbit(self, name, offset, value): ... def setex(self, name, time, value): ... @@ -129,14 +163,14 @@ class StrictRedis: def type(self, name): ... def watch(self, *names): ... def unwatch(self): ... - def blpop(self, keys, timeout=...): ... - def brpop(self, keys, timeout=...): ... + def blpop(self, keys: Union[_Str, Iterable[_Str]], timeout: int = ...) -> Optional[Tuple[bytes, bytes]]: ... + def brpop(self, keys: Union[_Str, Iterable[_Str]], timeout: int = ...) -> Optional[Tuple[bytes, bytes]]: ... def brpoplpush(self, src, dst, timeout=...): ... def lindex(self, name, index): ... def linsert(self, name, where, refvalue, value): ... def llen(self, name): ... def lpop(self, name): ... - def lpush(self, name, *values): ... + def lpush(self, name: _Str, *values: _Str) -> int: ... def lpushx(self, name, value): ... def lrange(self, name, start, end): ... def lrem(self, name, count, value): ... @@ -144,11 +178,11 @@ class StrictRedis: def ltrim(self, name, start, end): ... def rpop(self, name): ... def rpoplpush(self, src, dst): ... - def rpush(self, name, *values): ... + def rpush(self, name: _Str, *values: _Str) -> int: ... def rpushx(self, name, value): ... def sort(self, name, start=..., num=..., by=..., get=..., desc=..., alpha=..., store=..., groups=...): ... - def scan(self, cursor=..., match=..., count=...): ... - def scan_iter(self, match=..., count=...): ... + def scan(self, cursor: int = ..., match: Optional[Text] = ..., count: Optional[int] = ...) -> List[Text]: ... + def scan_iter(self, match: Optional[Text] = ..., count: Optional[int] = ...) -> List[Text]: ... def sscan(self, name, cursor=..., match=..., count=...): ... def sscan_iter(self, name, match=..., count=...): ... def hscan(self, name, cursor=..., match=..., count=...): ... @@ -169,7 +203,38 @@ class StrictRedis: def srem(self, name, *values): ... def sunion(self, keys, *args): ... def sunionstore(self, dest, keys, *args): ... - def zadd(self, name, *args, **kwargs): ... + def xack(self, name, groupname, *ids): ... + def xadd(self, name, fields, id=..., maxlen=..., approximate=...): ... + def xclaim( + self, + name, + groupname, + consumername, + min_idle_time, + message_ids, + idle=..., + time=..., + retrycount=..., + force=..., + justid=..., + ): ... + def xdel(self, name, *ids): ... + def xgroup_create(self, name, groupname, id=..., mkstream=...): ... + def xgroup_delconsumer(self, name, groupname, consumername): ... + def xgroup_destroy(self, name, groupname): ... + def xgroup_setid(self, name, groupname, id): ... + def xinfo_consumers(self, name, groupname): ... + def xinfo_groups(self, name): ... + def xinfo_stream(self, name): ... + def xlen(self, name): ... + def xpending(self, name, groupname): ... + def xpending_range(self, name, groupname, min, max, count, consumername=...): ... + def xrange(self, name, min=..., max=..., count=...): ... + def xread(self, streams, count=..., block=...): ... + def xreadgroup(self, groupname, consumername, streams, count=..., block=..., noack=...): ... + def xrevrange(self, name, max=..., min=..., count=...): ... + def xtrim(self, name, maxlen, approximate=...): ... + def zadd(self, name, mapping, nx: bool = ..., xx: bool = ..., ch: bool = ..., incr: bool = ...): ... def zcard(self, name): ... def zcount(self, name, min, max): ... def zincrby(self, name, value, amount=...): ... @@ -204,7 +269,7 @@ class StrictRedis: def hmset(self, name, mapping): ... def hmget(self, name, keys, *args): ... def hvals(self, name): ... - def publish(self, channel, message): ... + def publish(self, channel: Text, message: _Str) -> int: ... def eval(self, script, numkeys, *keys_and_args): ... def evalsha(self, sha, numkeys, *keys_and_args): ... def script_exists(self, *args): ... @@ -213,12 +278,7 @@ class StrictRedis: def script_load(self, script): ... def register_script(self, script): ... -class Redis(StrictRedis): - RESPONSE_CALLBACKS: Any - def pipeline(self, transaction=..., shard_hint=...): ... - def setex(self, name, value, time): ... - def lrem(self, name, value, num=...): ... - def zadd(self, name, *args, **kwargs): ... +StrictRedis = Redis class PubSub: PUBLISH_MESSAGE_TYPES: Any @@ -235,19 +295,19 @@ class PubSub: channels: Any patterns: Any def reset(self): ... - def close(self): ... + def close(self) -> None: ... def on_connect(self, connection): ... def encode(self, value): ... @property def subscribed(self): ... def execute_command(self, *args, **kwargs): ... def parse_response(self, block=...): ... - def psubscribe(self, *args, **kwargs): ... - def punsubscribe(self, *args): ... - def subscribe(self, *args, **kwargs): ... - def unsubscribe(self, *args): ... + def psubscribe(self, *args: Text, **kwargs: Callable[[Any], None]): ... + def punsubscribe(self, *args: Text) -> None: ... + def subscribe(self, *args: Text, **kwargs: Callable[[Any], None]) -> None: ... + def unsubscribe(self, *args: Text) -> None: ... def listen(self): ... - def get_message(self, ignore_subscribe_messages=...): ... + def get_message(self, ignore_subscribe_messages: bool = ..., timeout: int = ...) -> Optional[bytes]: ... def handle_message(self, response, ignore_subscribe_messages=...): ... def run_in_thread(self, sleep_time=...): ... diff --git a/third_party/2and3/redis/connection.pyi b/third_party/2and3/redis/connection.pyi index 7b7ddeff25d1..4086b6d96fd6 100644 --- a/third_party/2and3/redis/connection.pyi +++ b/third_party/2and3/redis/connection.pyi @@ -1,4 +1,4 @@ -from typing import Any +from typing import Any, Text, Optional ssl_available: Any hiredis_version: Any @@ -109,7 +109,7 @@ class UnixDomainSocketConnection(Connection): class ConnectionPool: @classmethod - def from_url(cls, url, db=..., **kwargs): ... + def from_url(cls, url: Text, db: Optional[int] = ..., **kwargs) -> ConnectionPool: ... connection_class: Any connection_kwargs: Any max_connections: Any diff --git a/third_party/2and3/requests/api.pyi b/third_party/2and3/requests/api.pyi index df3003cfafc4..1f994aa9192c 100644 --- a/third_party/2and3/requests/api.pyi +++ b/third_party/2and3/requests/api.pyi @@ -4,37 +4,29 @@ import sys from typing import Optional, Union, Any, Iterable, Mapping, MutableMapping, Tuple, IO, Text from .models import Response +from .sessions import _Data -if sys.version_info >= (3,): - _Text = str -else: - _Text = Union[str, Text] - -_ParamsMappingValueType = Union[_Text, bytes, int, float, Iterable[Union[_Text, bytes, int, float]]] -_Data = Union[ - None, - _Text, - bytes, - MutableMapping[str, Any], - MutableMapping[Text, Any], - Iterable[Tuple[_Text, Optional[_Text]]], - IO -] +_ParamsMappingValueType = Union[Text, bytes, int, float, Iterable[Union[Text, bytes, int, float]]] def request(method: str, url: str, **kwargs) -> Response: ... -def get(url: Union[_Text, bytes], - params: Optional[ - Union[Mapping[Union[_Text, bytes, int, float], _ParamsMappingValueType], - Union[_Text, bytes], - Tuple[Union[_Text, bytes, int, float], _ParamsMappingValueType], - Mapping[_Text, _ParamsMappingValueType], - Mapping[bytes, _ParamsMappingValueType], - Mapping[int, _ParamsMappingValueType], - Mapping[float, _ParamsMappingValueType]]] = ..., - **kwargs) -> Response: ... -def options(url: _Text, **kwargs) -> Response: ... -def head(url: _Text, **kwargs) -> Response: ... -def post(url: _Text, data: _Data = ..., json=..., **kwargs) -> Response: ... -def put(url: _Text, data: _Data = ..., json=..., **kwargs) -> Response: ... -def patch(url: _Text, data: _Data = ..., json=..., **kwargs) -> Response: ... -def delete(url: _Text, **kwargs) -> Response: ... +def get( + url: Union[Text, bytes], + params: Optional[ + Union[ + Mapping[Union[Text, bytes, int, float], _ParamsMappingValueType], + Union[Text, bytes], + Tuple[Union[Text, bytes, int, float], _ParamsMappingValueType], + Mapping[Text, _ParamsMappingValueType], + Mapping[bytes, _ParamsMappingValueType], + Mapping[int, _ParamsMappingValueType], + Mapping[float, _ParamsMappingValueType], + ] + ] = ..., + **kwargs, +) -> Response: ... +def options(url: Union[Text, bytes], **kwargs) -> Response: ... +def head(url: Union[Text, bytes], **kwargs) -> Response: ... +def post(url: Union[Text, bytes], data: _Data = ..., json=..., **kwargs) -> Response: ... +def put(url: Union[Text, bytes], data: _Data = ..., json=..., **kwargs) -> Response: ... +def patch(url: Union[Text, bytes], data: _Data = ..., json=..., **kwargs) -> Response: ... +def delete(url: Union[Text, bytes], **kwargs) -> Response: ... diff --git a/third_party/2and3/requests/cookies.pyi b/third_party/2and3/requests/cookies.pyi index 1208dce503cd..cf25c255a5ee 100644 --- a/third_party/2and3/requests/cookies.pyi +++ b/third_party/2and3/requests/cookies.pyi @@ -41,7 +41,7 @@ def remove_cookie_by_name(cookiejar, name, domain=..., path=...): ... class CookieConflictError(RuntimeError): ... -class RequestsCookieJar(CookieJar, MutableMapping): +class RequestsCookieJar(CookieJar, MutableMapping[Any, Any]): def get(self, name, default=..., domain=..., path=...): ... def set(self, name, value, **kwargs): ... def iterkeys(self): ... diff --git a/third_party/2and3/requests/models.pyi b/third_party/2and3/requests/models.pyi index 2bcea9459bc4..adc64318f57a 100644 --- a/third_party/2and3/requests/models.pyi +++ b/third_party/2and3/requests/models.pyi @@ -83,7 +83,7 @@ class Request(RequestHooksMixin): class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): method: Optional[Union[str, Text]] url: Optional[Union[str, Text]] - headers: CaseInsensitiveDict + headers: CaseInsensitiveDict[str] body: Optional[Union[bytes, Text]] hooks: Any def __init__(self) -> None: ... diff --git a/third_party/2and3/requests/packages/urllib3/_collections.pyi b/third_party/2and3/requests/packages/urllib3/_collections.pyi index 64e3d22dc5b6..b9f1f443dc6b 100644 --- a/third_party/2and3/requests/packages/urllib3/_collections.pyi +++ b/third_party/2and3/requests/packages/urllib3/_collections.pyi @@ -1,11 +1,14 @@ -from typing import Any +from typing import Any, NoReturn, TypeVar from collections import MutableMapping +_KT = TypeVar("_KT") +_VT = TypeVar("_VT") + class RLock: def __enter__(self): ... def __exit__(self, exc_type, exc_value, traceback): ... -class RecentlyUsedContainer(MutableMapping): +class RecentlyUsedContainer(MutableMapping[_KT, _VT]): ContainerCls: Any dispose_func: Any lock: Any @@ -18,13 +21,15 @@ class RecentlyUsedContainer(MutableMapping): def clear(self): ... def keys(self): ... -class HTTPHeaderDict(dict): +class HTTPHeaderDict(MutableMapping[str, str]): def __init__(self, headers=..., **kwargs) -> None: ... def __setitem__(self, key, val): ... def __getitem__(self, key): ... def __delitem__(self, key): ... def __contains__(self, key): ... def __eq__(self, other): ... + def __iter__(self) -> NoReturn: ... + def __len__(self) -> int: ... def __ne__(self, other): ... values: Any get: Any diff --git a/third_party/2and3/requests/sessions.pyi b/third_party/2and3/requests/sessions.pyi index 33c7b79e1d95..f09dbec2e462 100644 --- a/third_party/2and3/requests/sessions.pyi +++ b/third_party/2and3/requests/sessions.pyi @@ -54,7 +54,7 @@ class SessionRedirectMixin: def rebuild_auth(self, prepared_request, response): ... def rebuild_proxies(self, prepared_request, proxies): ... -_Data = Union[None, bytes, MutableMapping[Text, Text], IO] +_Data = Union[None, Text, bytes, MutableMapping[str, Any], MutableMapping[Text, Any], Iterable[Tuple[Text, Optional[Text]]], IO] _Hook = Callable[[Response], Any] _Hooks = MutableMapping[Text, List[_Hook]] @@ -62,7 +62,7 @@ _HooksInput = MutableMapping[Text, Union[Iterable[_Hook], _Hook]] class Session(SessionRedirectMixin): __attrs__: Any - headers: MutableMapping[Text, Text] + headers: CaseInsensitiveDict[Text] auth: Union[None, Tuple[Text, Text], _auth.AuthBase, Callable[[Request], Request]] proxies: MutableMapping[Text, Text] hooks: _Hooks @@ -73,18 +73,18 @@ class Session(SessionRedirectMixin): max_redirects: int trust_env: bool cookies: RequestsCookieJar - adapters: MutableMapping - redirect_cache: RecentlyUsedContainer + adapters: MutableMapping[Any, Any] + redirect_cache: RecentlyUsedContainer[Any, Any] def __init__(self) -> None: ... def __enter__(self) -> Session: ... def __exit__(self, *args) -> None: ... def prepare_request(self, request): ... - def request(self, method: str, url: str, + def request(self, method: str, url: Union[str, bytes, Text], params: Union[None, bytes, MutableMapping[Text, Text]] = ..., data: _Data = ..., headers: Optional[MutableMapping[Text, Text]] = ..., cookies: Union[None, RequestsCookieJar, MutableMapping[Text, Text]] = ..., - files: Optional[MutableMapping[Text, IO]] = ..., + files: Optional[MutableMapping[Text, IO[Any]]] = ..., auth: Union[None, Tuple[Text, Text], _auth.AuthBase, Callable[[Request], Request]] = ..., timeout: Union[None, float, Tuple[float, float]] = ..., allow_redirects: Optional[bool] = ..., diff --git a/third_party/2and3/requests/structures.pyi b/third_party/2and3/requests/structures.pyi index 92cf27aa1cd5..0ef1993643a5 100644 --- a/third_party/2and3/requests/structures.pyi +++ b/third_party/2and3/requests/structures.pyi @@ -10,6 +10,7 @@ class CaseInsensitiveDict(MutableMapping[str, _VT], Generic[_VT]): def __delitem__(self, key: str) -> None: ... def __iter__(self) -> Iterator[str]: ... def __len__(self) -> int: ... + def copy(self) -> CaseInsensitiveDict[_VT]: ... class LookupDict(Dict[str, _VT]): name: Any diff --git a/third_party/2and3/typing_extensions.pyi b/third_party/2and3/typing_extensions.pyi index c9a2ec435022..ef36d125cf7e 100644 --- a/third_party/2and3/typing_extensions.pyi +++ b/third_party/2and3/typing_extensions.pyi @@ -19,12 +19,14 @@ _F = TypeVar('_F', bound=Callable[..., Any]) _TC = TypeVar('_TC', bound=Type[object]) class _SpecialForm: def __getitem__(self, typeargs: Any) -> Any: ... -def runtime(cls: _TC) -> _TC: ... +def runtime_checkable(cls: _TC) -> _TC: ... +# This alias for above is kept here for backwards compatibility. +runtime = runtime_checkable Protocol: _SpecialForm = ... Final: _SpecialForm = ... def final(f: _F) -> _F: ... Literal: _SpecialForm = ... -def IntVar(__name: str) -> Type: ... +def IntVar(__name: str) -> Any: ... # returns a new TypeVar # Internal mypy fallback type for all typed dicts (does not exist at runtime) class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta): diff --git a/third_party/2and3/werkzeug/contrib/fixers.pyi b/third_party/2and3/werkzeug/contrib/fixers.pyi index 97c6e564a7ea..0593d9d8781e 100644 --- a/third_party/2and3/werkzeug/contrib/fixers.pyi +++ b/third_party/2and3/werkzeug/contrib/fixers.pyi @@ -1,38 +1,35 @@ -from typing import Any, Sequence, Optional, Iterable +from typing import Any, Iterable, List, Mapping, Optional, Sequence, Set, Text from wsgiref.types import WSGIApplication, WSGIEnvironment, StartResponse -class CGIRootFix: - app: Any - app_root: Any - def __init__(self, app, app_root: str = ...): ... - def __call__(self, environ, start_response): ... +from ..middleware.proxy_fix import ProxyFix as ProxyFix -LighttpdCGIRootFix: Any +class CGIRootFix(object): + app: WSGIApplication + app_root: Text + def __init__(self, app: WSGIApplication, app_root: Text = ...) -> None: ... + def __call__(self, environ: WSGIEnvironment, start_response: StartResponse) -> Iterable[bytes]: ... -class PathInfoFromRequestUriFix: - app: Any - def __init__(self, app): ... - def __call__(self, environ, start_response): ... +class LighttpdCGIRootFix(CGIRootFix): ... -class ProxyFix(object): +class PathInfoFromRequestUriFix(object): app: WSGIApplication - num_proxies: int - def __init__(self, app: WSGIApplication, num_proxies: int = ...) -> None: ... - def get_remote_addr(self, forwarded_for: Sequence[str]) -> Optional[str]: ... + def __init__(self, app: WSGIApplication) -> None: ... def __call__(self, environ: WSGIEnvironment, start_response: StartResponse) -> Iterable[bytes]: ... -class HeaderRewriterFix: - app: Any - remove_headers: Any - add_headers: Any - def __init__(self, app, remove_headers: Optional[Any] = ..., add_headers: Optional[Any] = ...): ... - def __call__(self, environ, start_response): ... +class HeaderRewriterFix(object): + app: WSGIApplication + remove_headers: Set[Text] + add_headers: List[Text] + def __init__( + self, app: WSGIApplication, remove_headers: Optional[Iterable[Text]] = ..., add_headers: Optional[Iterable[Text]] = ..., + ) -> None: ... + def __call__(self, environ: WSGIEnvironment, start_response: StartResponse) -> Iterable[bytes]: ... -class InternetExplorerFix: - app: Any - fix_vary: Any - fix_attach: Any - def __init__(self, app, fix_vary: bool = ..., fix_attach: bool = ...): ... - def fix_headers(self, environ, headers, status: Optional[Any] = ...): ... - def run_fixed(self, environ, start_response): ... - def __call__(self, environ, start_response): ... +class InternetExplorerFix(object): + app: WSGIApplication + fix_vary: bool + fix_attach: bool + def __init__(self, app: WSGIApplication, fix_vary: bool = ..., fix_attach: bool = ...) -> None: ... + def fix_headers(self, environ: WSGIEnvironment, headers: Mapping[str, str], status: Optional[Any] = ...) -> None: ... + def run_fixed(self, environ: WSGIEnvironment, start_response: StartResponse) -> Iterable[bytes]: ... + def __call__(self, environ: WSGIEnvironment, start_response: StartResponse) -> Iterable[bytes]: ... diff --git a/third_party/2and3/werkzeug/contrib/lint.pyi b/third_party/2and3/werkzeug/contrib/lint.pyi index 7fd7c6a3bd38..9a25daf5aab7 100644 --- a/third_party/2and3/werkzeug/contrib/lint.pyi +++ b/third_party/2and3/werkzeug/contrib/lint.pyi @@ -1,43 +1 @@ -from typing import Any - -class WSGIWarning(Warning): ... -class HTTPWarning(Warning): ... - -def check_string(context, obj, stacklevel: int = ...): ... - -class InputStream: - def __init__(self, stream): ... - def read(self, *args): ... - def readline(self, *args): ... - def __iter__(self): ... - def close(self): ... - -class ErrorStream: - def __init__(self, stream): ... - def write(self, s): ... - def flush(self): ... - def writelines(self, seq): ... - def close(self): ... - -class GuardedWrite: - def __init__(self, write, chunks): ... - def __call__(self, s): ... - -class GuardedIterator: - closed: Any - headers_set: Any - chunks: Any - def __init__(self, iterator, headers_set, chunks): ... - def __iter__(self): ... - def next(self): ... - def close(self): ... - def __del__(self): ... - -class LintMiddleware: - app: Any - def __init__(self, app): ... - def check_environ(self, environ): ... - def check_start_response(self, status, headers, exc_info): ... - def check_headers(self, headers): ... - def check_iterator(self, app_iter): ... - def __call__(self, *args, **kwargs): ... +from ..middleware.lint import * diff --git a/third_party/2and3/werkzeug/contrib/profiler.pyi b/third_party/2and3/werkzeug/contrib/profiler.pyi index 601c4f1bf46d..61608db978cf 100644 --- a/third_party/2and3/werkzeug/contrib/profiler.pyi +++ b/third_party/2and3/werkzeug/contrib/profiler.pyi @@ -1,15 +1,14 @@ -from typing import Any, Optional +from typing import Any, AnyStr, Generic, Optional, Protocol, Tuple, TypeVar -available: Any +from ..middleware.profiler import * -class MergeStream: - streams: Any - def __init__(self, *streams): ... - def write(self, data): ... +_T = TypeVar("_T") +_T_contra = TypeVar("_T_contra", contravariant=True) -class ProfilerMiddleware: - def __init__(self, app, stream: Optional[Any] = ..., sort_by=..., restrictions=..., profile_dir: Optional[Any] = ...): ... - def __call__(self, environ, start_response): ... +class _Writable(Protocol[_T_contra]): + def write(self, __s: _T_contra) -> Any: ... -def make_action(app_factory, hostname: str = ..., port: int = ..., threaded: bool = ..., processes: int = ..., - stream: Optional[Any] = ..., sort_by=..., restrictions=...): ... +class MergeStream(Generic[_T]): + streams: Tuple[_Writable[_T], ...] + def __init__(self, *streams: _Writable[_T]) -> None: ... + def write(self, data: _T) -> None: ... diff --git a/third_party/2and3/werkzeug/contrib/securecookie.pyi b/third_party/2and3/werkzeug/contrib/securecookie.pyi index 009ad2d6b9eb..667d4558a852 100644 --- a/third_party/2and3/werkzeug/contrib/securecookie.pyi +++ b/third_party/2and3/werkzeug/contrib/securecookie.pyi @@ -5,7 +5,7 @@ from werkzeug.contrib.sessions import ModificationTrackingDict class UnquoteError(Exception): ... -class SecureCookie(ModificationTrackingDict): +class SecureCookie(ModificationTrackingDict[Any, Any]): hash_method: Any serialization_method: Any quote_base64: Any diff --git a/third_party/2and3/werkzeug/contrib/sessions.pyi b/third_party/2and3/werkzeug/contrib/sessions.pyi index b4b4ec25d03d..ab09b9798e3e 100644 --- a/third_party/2and3/werkzeug/contrib/sessions.pyi +++ b/third_party/2and3/werkzeug/contrib/sessions.pyi @@ -1,15 +1,18 @@ -from typing import Any, Optional, Text +from typing import Any, Optional, Text, TypeVar from werkzeug.datastructures import CallbackDict +_K = TypeVar("_K") +_V = TypeVar("_V") + def generate_key(salt: Optional[Any] = ...): ... -class ModificationTrackingDict(CallbackDict): +class ModificationTrackingDict(CallbackDict[_K, _V]): modified: Any def __init__(self, *args, **kwargs): ... def copy(self): ... def __copy__(self): ... -class Session(ModificationTrackingDict): +class Session(ModificationTrackingDict[_K, _V]): sid: Any new: Any def __init__(self, data, sid, new: bool = ...): ... diff --git a/third_party/2and3/werkzeug/datastructures.pyi b/third_party/2and3/werkzeug/datastructures.pyi index f10665f98cdc..4d5f0ec146a3 100644 --- a/third_party/2and3/werkzeug/datastructures.pyi +++ b/third_party/2and3/werkzeug/datastructures.pyi @@ -1,5 +1,5 @@ import collections -from typing import Any, Optional, Mapping, Dict, TypeVar, Callable, Union, overload, Text +from typing import Any, Optional, Mapping, Dict, TypeVar, Callable, Union, overload, Text, Protocol, Iterator, IO from collections import Container, Iterable, MutableSet _K = TypeVar("_K") @@ -11,8 +11,8 @@ def is_immutable(self): ... def iter_multi_items(mapping): ... def native_itermethods(names): ... -class ImmutableListMixin: - def __hash__(self): ... +class ImmutableListMixin(object): + def __hash__(self) -> int: ... def __reduce_ex__(self, protocol): ... def __delitem__(self, key): ... def __delslice__(self, i, j): ... @@ -28,13 +28,13 @@ class ImmutableListMixin: def reverse(self): ... def sort(self, cmp: Optional[Any] = ..., key: Optional[Any] = ..., reverse: Optional[Any] = ...): ... -class ImmutableList(ImmutableListMixin, list): ... +class ImmutableList(ImmutableListMixin, list): ... # type: ignore -class ImmutableDictMixin: +class ImmutableDictMixin(object): @classmethod def fromkeys(cls, *args, **kwargs): ... def __reduce_ex__(self, protocol): ... - def __hash__(self): ... + def __hash__(self) -> int: ... def setdefault(self, key, default: Optional[Any] = ...): ... def update(self, *args, **kwargs): ... def pop(self, key, default: Optional[Any] = ...): ... @@ -51,7 +51,7 @@ class ImmutableMultiDictMixin(ImmutableDictMixin): def setlist(self, key, new_list): ... def setlistdefault(self, key, default_list: Optional[Any] = ...): ... -class UpdateDictMixin: +class UpdateDictMixin(object): on_update: Any def setdefault(self, key, default: Optional[Any] = ...): ... def pop(self, key, default=...): ... @@ -71,7 +71,7 @@ class TypeConversionDict(Dict[_K, _V]): @overload def get(self, key: _K, default: _D, type: Callable[[_V], _R]) -> Union[_R, _D]: ... -class ImmutableTypeConversionDict(ImmutableDictMixin, TypeConversionDict[_K, _V]): +class ImmutableTypeConversionDict(ImmutableDictMixin, TypeConversionDict[_K, _V]): # type: ignore def copy(self) -> TypeConversionDict[_K, _V]: ... def __copy__(self) -> ImmutableTypeConversionDict[_K, _V]: ... @@ -79,7 +79,7 @@ class ViewItems: def __init__(self, multi_dict, method, repr_name, *a, **kw): ... def __iter__(self): ... -class MultiDict(TypeConversionDict): +class MultiDict(TypeConversionDict[_K, _V]): def __init__(self, mapping: Optional[Any] = ...): ... def __getitem__(self, key): ... def __setitem__(self, key, value): ... @@ -113,7 +113,7 @@ class _omd_bucket: def __init__(self, omd, key, value): ... def unlink(self, omd): ... -class OrderedMultiDict(MultiDict): +class OrderedMultiDict(MultiDict[_K, _V]): def __init__(self, mapping: Optional[Any] = ...): ... def __eq__(self, other): ... def __ne__(self, other): ... @@ -137,7 +137,7 @@ class OrderedMultiDict(MultiDict): def popitem(self): ... def popitemlist(self): ... -class Headers(collections.Mapping): +class Headers(object): def __init__(self, defaults: Optional[Any] = ...): ... def __getitem__(self, key, _get_mode: bool = ...): ... def __eq__(self, other): ... @@ -207,7 +207,7 @@ class EnvironHeaders(ImmutableHeadersMixin, Headers): def __iter__(self): ... def copy(self): ... -class CombinedMultiDict(ImmutableMultiDictMixin, MultiDict): +class CombinedMultiDict(ImmutableMultiDictMixin, MultiDict[_K, _V]): # type: ignore def __reduce_ex__(self, protocol): ... dicts: Any def __init__(self, dicts: Optional[Any] = ...): ... @@ -228,18 +228,18 @@ class CombinedMultiDict(ImmutableMultiDictMixin, MultiDict): def __contains__(self, key): ... has_key: Any -class FileMultiDict(MultiDict): +class FileMultiDict(MultiDict[_K, _V]): def add_file(self, name, file, filename: Optional[Any] = ..., content_type: Optional[Any] = ...): ... -class ImmutableDict(ImmutableDictMixin, dict): +class ImmutableDict(ImmutableDictMixin, Dict[_K, _V]): # type: ignore def copy(self): ... def __copy__(self): ... -class ImmutableMultiDict(ImmutableMultiDictMixin, MultiDict): +class ImmutableMultiDict(ImmutableMultiDictMixin, MultiDict[_K, _V]): # type: ignore def copy(self): ... def __copy__(self): ... -class ImmutableOrderedMultiDict(ImmutableMultiDictMixin, OrderedMultiDict): +class ImmutableOrderedMultiDict(ImmutableMultiDictMixin, OrderedMultiDict[_K, _V]): # type: ignore def copy(self): ... def __copy__(self): ... @@ -270,7 +270,7 @@ class CharsetAccept(Accept): ... def cache_property(key, empty, type): ... -class _CacheControl(UpdateDictMixin, dict): +class _CacheControl(UpdateDictMixin, Dict[str, Any]): no_cache: Any no_store: Any max_age: Any @@ -280,7 +280,7 @@ class _CacheControl(UpdateDictMixin, dict): def __init__(self, values=..., on_update: Optional[Any] = ...): ... def to_header(self): ... -class RequestCacheControl(ImmutableDictMixin, _CacheControl): +class RequestCacheControl(ImmutableDictMixin, _CacheControl): # type: ignore max_stale: Any min_fresh: Any no_transform: Any @@ -293,11 +293,11 @@ class ResponseCacheControl(_CacheControl): proxy_revalidate: Any s_maxage: Any -class CallbackDict(UpdateDictMixin, dict): +class CallbackDict(UpdateDictMixin, Dict[_K, _V]): on_update: Any def __init__(self, initial: Optional[Any] = ..., on_update: Optional[Any] = ...): ... -class HeaderSet(MutableSet): +class HeaderSet(MutableSet[str]): on_update: Any def __init__(self, headers: Optional[Any] = ..., on_update: Optional[Any] = ...): ... def add(self, header): ... @@ -317,7 +317,7 @@ class HeaderSet(MutableSet): def __iter__(self): ... def __nonzero__(self): ... -class ETags(Container, Iterable): +class ETags(Container[str], Iterable[str]): star_tag: Any def __init__(self, strong_etags: Optional[Any] = ..., weak_etags: Optional[Any] = ..., star_tag: bool = ...): ... def as_set(self, include_weak: bool = ...): ... @@ -360,7 +360,7 @@ class ContentRange: def __nonzero__(self): ... __bool__: Any -class Authorization(ImmutableDictMixin, Dict[str, Any]): +class Authorization(ImmutableDictMixin, Dict[str, Any]): # type: ignore type: str def __init__(self, auth_type: str, data: Optional[Mapping[str, Any]] = ...) -> None: ... @property @@ -384,7 +384,7 @@ class Authorization(ImmutableDictMixin, Dict[str, Any]): @property def qop(self) -> Optional[str]: ... -class WWWAuthenticate(UpdateDictMixin, dict): +class WWWAuthenticate(UpdateDictMixin, Dict[str, Any]): on_update: Any def __init__(self, auth_type: Optional[Any] = ..., values: Optional[Any] = ..., on_update: Optional[Any] = ...): ... def set_basic(self, realm: str = ...): ... @@ -402,24 +402,34 @@ class WWWAuthenticate(UpdateDictMixin, dict): qop: Any stale: Any -class FileStorage: - name: Any - stream: Any - filename: Any - headers: Any - def __init__(self, stream: Optional[Any] = ..., filename: Optional[Any] = ..., name: Optional[Any] = ..., - content_type: Optional[Any] = ..., content_length: Optional[Any] = ..., headers: Optional[Any] = ...): ... +class _Writer(Protocol): + def write(self, data: bytes) -> Any: ... + +class FileStorage(object): + name: Optional[Text] + stream: IO[bytes] + filename: Optional[Text] + headers: Headers + def __init__( + self, + stream: Optional[IO[bytes]] = ..., + filename: Union[None, Text, bytes] = ..., + name: Optional[Text] = ..., + content_type: Optional[Text] = ..., + content_length: Optional[int] = ..., + headers: Optional[Headers] = ..., + ): ... @property - def content_type(self): ... + def content_type(self) -> Optional[Text]: ... @property - def content_length(self): ... + def content_length(self) -> int: ... @property - def mimetype(self): ... + def mimetype(self) -> str: ... @property - def mimetype_params(self): ... - def save(self, dst, buffer_size: int = ...): ... - def close(self): ... - def __nonzero__(self): ... - __bool__: Any - def __getattr__(self, name): ... - def __iter__(self): ... + def mimetype_params(self) -> Dict[str, str]: ... + def save(self, dst: Union[Text, _Writer], buffer_size: int = ...): ... + def close(self) -> None: ... + def __nonzero__(self) -> bool: ... + def __bool__(self) -> bool: ... + def __getattr__(self, name: Text) -> Any: ... + def __iter__(self) -> Iterator[bytes]: ... diff --git a/third_party/2and3/werkzeug/exceptions.pyi b/third_party/2and3/werkzeug/exceptions.pyi index 368604641266..b19ef0bda785 100644 --- a/third_party/2and3/werkzeug/exceptions.pyi +++ b/third_party/2and3/werkzeug/exceptions.pyi @@ -9,9 +9,9 @@ class _EnvironContainer(Protocol): class HTTPException(Exception): code: Optional[int] - description: Optional[str] + description: Optional[Text] response: Optional[Response] - def __init__(self, description: Optional[str] = ..., response: Optional[Response] = ...) -> None: ... + def __init__(self, description: Optional[Text] = ..., response: Optional[Response] = ...) -> None: ... @classmethod def wrap(cls, exception: Type[Exception], name: Optional[str] = ...) -> Any: ... @property @@ -26,7 +26,7 @@ default_exceptions: Dict[int, Type[HTTPException]] class BadRequest(HTTPException): code: int - description: str + description: Text class ClientDisconnected(BadRequest): ... class SecurityError(BadRequest): ... @@ -34,122 +34,127 @@ class BadHost(BadRequest): ... class Unauthorized(HTTPException): code: int - description: str + description: Text + www_authenticate: Optional[Iterable[object]] + def __init__( + self, + description: Optional[Text] = ..., + response: Optional[Response] = ..., + www_authenticate: Union[None, Tuple[object, ...], List[object], object] = ..., + ) -> None: ... class Forbidden(HTTPException): code: int - description: str + description: Text class NotFound(HTTPException): code: int - description: str + description: Text class MethodNotAllowed(HTTPException): code: int - description: str + description: Text valid_methods: Any def __init__(self, valid_methods: Optional[Any] = ..., description: Optional[Any] = ...): ... - def get_headers(self, environ): ... class NotAcceptable(HTTPException): code: int - description: str + description: Text class RequestTimeout(HTTPException): code: int - description: str + description: Text class Conflict(HTTPException): code: int - description: str + description: Text class Gone(HTTPException): code: int - description: str + description: Text class LengthRequired(HTTPException): code: int - description: str + description: Text class PreconditionFailed(HTTPException): code: int - description: str + description: Text class RequestEntityTooLarge(HTTPException): code: int - description: str + description: Text class RequestURITooLarge(HTTPException): code: int - description: str + description: Text class UnsupportedMediaType(HTTPException): code: int - description: str + description: Text class RequestedRangeNotSatisfiable(HTTPException): code: int - description: str + description: Text length: Any units: str def __init__(self, length: Optional[Any] = ..., units: str = ..., description: Optional[Any] = ...): ... - def get_headers(self, environ): ... class ExpectationFailed(HTTPException): code: int - description: str + description: Text class ImATeapot(HTTPException): code: int - description: str + description: Text class UnprocessableEntity(HTTPException): code: int - description: str + description: Text class Locked(HTTPException): code: int - description: str + description: Text class PreconditionRequired(HTTPException): code: int - description: str + description: Text class TooManyRequests(HTTPException): code: int - description: str + description: Text class RequestHeaderFieldsTooLarge(HTTPException): code: int - description: str + description: Text class UnavailableForLegalReasons(HTTPException): code: int - description: str + description: Text class InternalServerError(HTTPException): code: int - description: str + description: Text class NotImplemented(HTTPException): code: int - description: str + description: Text class BadGateway(HTTPException): code: int - description: str + description: Text class ServiceUnavailable(HTTPException): code: int - description: str + description: Text class GatewayTimeout(HTTPException): code: int - description: str + description: Text class HTTPVersionNotSupported(HTTPException): code: int - description: str + description: Text class Aborter: mapping: Any diff --git a/third_party/2and3/werkzeug/formparser.pyi b/third_party/2and3/werkzeug/formparser.pyi index d0e6a739170f..8f0b55254bb8 100644 --- a/third_party/2and3/werkzeug/formparser.pyi +++ b/third_party/2and3/werkzeug/formparser.pyi @@ -1,45 +1,87 @@ -from typing import Any, Optional, Text +from typing import Any, Optional, Text, Tuple, Callable, Iterable, TypeVar, NoReturn, Protocol, IO, Generator, Dict, Mapping, Union +from wsgiref.types import WSGIEnvironment -def default_stream_factory(total_content_length, filename, content_type, content_length: Optional[Any] = ...): ... -def parse_form_data(environ, stream_factory: Optional[Any] = ..., charset: Text = ..., errors: Text = ..., - max_form_memory_size: Optional[Any] = ..., max_content_length: Optional[Any] = ..., - cls: Optional[Any] = ..., silent: bool = ...): ... -def exhaust_stream(f): ... +from .datastructures import Headers -class FormDataParser: - stream_factory: Any +_Dict = Any +_ParseFunc = Callable[[IO[bytes], str, Optional[int], Mapping[str, str]], Tuple[IO[bytes], _Dict, _Dict]] + +_F = TypeVar("_F", bound=Callable[..., Any]) + +class _StreamFactory(Protocol): + def __call__( + self, total_content_length: Optional[int], filename: str, content_type: str, content_length: Optional[int] = ..., + ) -> IO[bytes]: ... + +def default_stream_factory( + total_content_length: Optional[int], filename: str, content_type: str, content_length: Optional[int] = ..., +) -> IO[bytes]: ... +def parse_form_data( + environ: WSGIEnvironment, + stream_factory: Optional[_StreamFactory] = ..., + charset: Text = ..., + errors: Text = ..., + max_form_memory_size: Optional[int] = ..., + max_content_length: Optional[int] = ..., + cls: Optional[Callable[[], _Dict]] = ..., + silent: bool = ..., +) -> Tuple[IO[bytes], _Dict, _Dict]: ... +def exhaust_stream(f: _F) -> _F: ... + +class FormDataParser(object): + stream_factory: _StreamFactory charset: Text errors: Text - max_form_memory_size: Any - max_content_length: Any - cls: Any - silent: Any - def __init__(self, stream_factory: Optional[Any] = ..., charset: Text = ..., errors: Text = ..., - max_form_memory_size: Optional[Any] = ..., max_content_length: Optional[Any] = ..., cls: Optional[Any] = ..., - silent: bool = ...): ... - def get_parse_func(self, mimetype, options): ... - def parse_from_environ(self, environ): ... - def parse(self, stream, mimetype, content_length, options: Optional[Any] = ...): ... - parse_functions: Any - -def is_valid_multipart_boundary(boundary): ... -def parse_multipart_headers(iterable): ... - -class MultiPartParser: + max_form_memory_size: Optional[int] + max_content_length: Optional[int] + cls: Callable[[], _Dict] + silent: bool + def __init__( + self, + stream_factory: Optional[_StreamFactory] = ..., + charset: Text = ..., + errors: Text = ..., + max_form_memory_size: Optional[int] = ..., + max_content_length: Optional[int] = ..., + cls: Optional[Callable[[], _Dict]] = ..., + silent: bool = ..., + ) -> None: ... + def get_parse_func(self, mimetype: str, options: Any) -> Optional[_ParseFunc]: ... + def parse_from_environ(self, environ: WSGIEnvironment) -> Tuple[IO[bytes], _Dict, _Dict]: ... + def parse( + self, stream: IO[bytes], mimetype: Text, content_length: Optional[int], options: Optional[Mapping[str, str]] = ..., + ) -> Tuple[IO[bytes], _Dict, _Dict]: ... + parse_functions: Dict[Text, _ParseFunc] + +def is_valid_multipart_boundary(boundary: str) -> bool: ... +def parse_multipart_headers(iterable: Iterable[Union[Text, bytes]]) -> Headers: ... + +class MultiPartParser(object): charset: Text errors: Text - max_form_memory_size: Any - stream_factory: Any - cls: Any - buffer_size: Any - def __init__(self, stream_factory: Optional[Any] = ..., charset: Text = ..., errors: Text = ..., - max_form_memory_size: Optional[Any] = ..., cls: Optional[Any] = ..., buffer_size=...): ... - def fail(self, message): ... - def get_part_encoding(self, headers): ... - def get_part_charset(self, headers) -> Text: ... - def start_file_streaming(self, filename, headers, total_content_length): ... - def in_memory_threshold_reached(self, bytes): ... - def validate_boundary(self, boundary): ... - def parse_lines(self, file, boundary, content_length, cap_at_buffer: bool = ...): ... - def parse_parts(self, file, boundary, content_length): ... - def parse(self, file, boundary, content_length): ... + max_form_memory_size: Optional[int] + stream_factory: _StreamFactory + cls: Callable[[], _Dict] + buffer_size: int + def __init__( + self, + stream_factory: Optional[_StreamFactory] = ..., + charset: Text = ..., + errors: Text = ..., + max_form_memory_size: Optional[int] = ..., + cls: Optional[Callable[[], _Dict]] = ..., + buffer_size: int = ..., + ) -> None: ... + def fail(self, message: Text) -> NoReturn: ... + def get_part_encoding(self, headers: Mapping[str, str]) -> Optional[str]: ... + def get_part_charset(self, headers: Mapping[str, str]) -> Text: ... + def start_file_streaming( + self, filename: Union[Text, bytes], headers: Mapping[str, str], total_content_length: Optional[int], + ) -> Tuple[Text, IO[bytes]]: ... + def in_memory_threshold_reached(self, bytes: Any) -> NoReturn: ... + def validate_boundary(self, boundary: Optional[str]) -> None: ... + def parse_lines( + self, file: Any, boundary: bytes, content_length: int, cap_at_buffer: bool = ..., + ) -> Generator[Tuple[str, Any], None, None]: ... + def parse_parts(self, file: Any, boundary: bytes, content_length: int) -> Generator[Tuple[str, Any], None, None]: ... + def parse(self, file: Any, boundary: bytes, content_length: int) -> Tuple[_Dict, _Dict]: ... diff --git a/third_party/2and3/werkzeug/http.pyi b/third_party/2and3/werkzeug/http.pyi index 2e078ff843b5..e3ca6fe00883 100644 --- a/third_party/2and3/werkzeug/http.pyi +++ b/third_party/2and3/werkzeug/http.pyi @@ -81,12 +81,12 @@ def is_entity_header(header: Text) -> bool: ... def is_hop_by_hop_header(header: Text) -> bool: ... @overload def parse_cookie(header: Union[None, WSGIEnvironment, Text, bytes], charset: Text = ..., - errors: Text = ...) -> TypeConversionDict: ... + errors: Text = ...) -> TypeConversionDict[Any, Any]: ... @overload def parse_cookie(header: Union[None, WSGIEnvironment, Text, bytes], charset: Text = ..., errors: Text = ..., cls: Optional[Callable[[Iterable[Tuple[Text, Text]]], _T]] = ...) -> _T: ... def dump_cookie(key: _ToBytes, value: _ToBytes = ..., max_age: Union[None, float, timedelta] = ..., - expires: Union[None, Text, float, datetime] = ..., path: Union[None, tuple, str, bytes] = ..., + expires: Union[None, Text, float, datetime] = ..., path: Union[None, Tuple[Any, ...], str, bytes] = ..., domain: Union[None, str, bytes] = ..., secure: bool = ..., httponly: bool = ..., charset: Text = ..., sync_expires: bool = ...) -> str: ... def is_byte_range_valid(start: Optional[int], stop: Optional[int], length: Optional[int]) -> bool: ... diff --git a/third_party/2and3/werkzeug/middleware/__init__.pyi b/third_party/2and3/werkzeug/middleware/__init__.pyi new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/third_party/2and3/werkzeug/middleware/dispatcher.pyi b/third_party/2and3/werkzeug/middleware/dispatcher.pyi new file mode 100644 index 000000000000..f107c435660a --- /dev/null +++ b/third_party/2and3/werkzeug/middleware/dispatcher.pyi @@ -0,0 +1,8 @@ +from typing import Any, Iterable, Mapping, Optional, Text +from wsgiref.types import StartResponse, WSGIApplication, WSGIEnvironment + +class DispatcherMiddleware(object): + app: WSGIApplication + mounts: Mapping[Text, WSGIApplication] + def __init__(self, app: WSGIApplication, mounts: Optional[Mapping[Text, WSGIApplication]] = ...) -> None: ... + def __call__(self, environ: WSGIEnvironment, start_response: StartResponse) -> Iterable[bytes]: ... diff --git a/third_party/2and3/werkzeug/middleware/http_proxy.pyi b/third_party/2and3/werkzeug/middleware/http_proxy.pyi new file mode 100644 index 000000000000..4056cacc26a5 --- /dev/null +++ b/third_party/2and3/werkzeug/middleware/http_proxy.pyi @@ -0,0 +1,18 @@ +from typing import Any, Dict, Iterable, Mapping, MutableMapping, Text +from wsgiref.types import StartResponse, WSGIApplication, WSGIEnvironment + +_Opts = Mapping[Text, Any] +_MutableOpts = MutableMapping[Text, Any] + +class ProxyMiddleware(object): + app: WSGIApplication + targets: Dict[Text, _MutableOpts] + def __init__( + self, + app: WSGIApplication, + targets: Mapping[Text, _MutableOpts], + chunk_size: int = ..., + timeout: int = ..., + ) -> None: ... + def proxy_to(self, opts: _Opts, path: Text, prefix: Text) -> WSGIApplication: ... + def __call__(self, environ: WSGIEnvironment, start_response: StartResponse) -> Iterable[bytes]: ... diff --git a/third_party/2and3/werkzeug/middleware/lint.pyi b/third_party/2and3/werkzeug/middleware/lint.pyi new file mode 100644 index 000000000000..95922cc4afc4 --- /dev/null +++ b/third_party/2and3/werkzeug/middleware/lint.pyi @@ -0,0 +1,67 @@ +import sys +from typing import Any, Iterable, Iterator, List, Mapping, Optional, Protocol, Tuple +from wsgiref.types import StartResponse, WSGIApplication, WSGIEnvironment + +from ..datastructures import Headers + +class WSGIWarning(Warning): ... +class HTTPWarning(Warning): ... + +def check_string(context: str, obj: object, stacklevel: int = ...) -> None: ... + +class _Readable(Protocol): + def read(self, __size: int = ...) -> bytes: ... + def readline(self, __size: int = ...) -> bytes: ... + def __iter__(self) -> Iterator[bytes]: ... + def close(self) -> Any: ... + +class InputStream(object): + def __init__(self, stream: _Readable) -> None: ... + def read(self, __size: int = ...) -> bytes: ... + def readline(self, __size: int = ...) -> bytes: ... + def __iter__(self) -> Iterator[bytes]: ... + def close(self) -> None: ... + +class _FullyWritable(Protocol): + def write(self, __s: str) -> Any: ... + def flush(self) -> Any: ... + def close(self) -> Any: ... + +class ErrorStream(object): + def __init__(self, stream: _FullyWritable) -> None: ... + def write(self, s: str) -> None: ... + def flush(self) -> None: ... + def writelines(self, seq: Iterable[str]) -> None: ... + def close(self) -> None: ... + +class _Writable(Protocol): + def write(self, __s: str) -> Any: ... + +class GuardedWrite(object): + def __init__(self, write: _Writable, chunks: List[int]) -> None: ... + def __call__(self, s: str) -> None: ... + +class GuardedIterator(object): + closed: bool + headers_set: bool + chunks: List[int] + def __init__(self, iterator: Iterable[str], headers_set: bool, chunks: List[int]) -> None: ... + def __iter__(self) -> GuardedIterator: ... + if sys.version_info < (3,): + def next(self) -> str: ... + else: + def __next__(self) -> str: ... + def close(self) -> None: ... + +class LintMiddleware(object): + def __init__(self, app: WSGIApplication) -> None: ... + def check_environ(self, environ: WSGIEnvironment) -> None: ... + def check_start_response( + self, + status: str, + headers: List[Tuple[str, str]], + exc_info: Optional[Tuple[Any, ...]], + ) -> Tuple[int, Headers]: ... + def check_headers(self, headers: Mapping[str, str]) -> None: ... + def check_iterator(self, app_iter: Iterable[bytes]) -> None: ... + def __call__(self, environ: WSGIEnvironment, start_response: StartResponse) -> GuardedIterator: ... diff --git a/third_party/2and3/werkzeug/middleware/profiler.pyi b/third_party/2and3/werkzeug/middleware/profiler.pyi new file mode 100644 index 000000000000..75051220fa48 --- /dev/null +++ b/third_party/2and3/werkzeug/middleware/profiler.pyi @@ -0,0 +1,14 @@ +from typing import IO, Iterable, List, Optional, Text, Tuple, Union +from wsgiref.types import StartResponse, WSGIApplication, WSGIEnvironment + +class ProfilerMiddleware(object): + def __init__( + self, + app: WSGIApplication, + stream: IO[str] = ..., + sort_by: Tuple[Text, Text] = ..., + restrictions: Iterable[Union[str, float]] = ..., + profile_dir: Optional[Text] = ..., + filename_format: Text = ..., + ) -> None: ... + def __call__(self, environ: WSGIEnvironment, start_response: StartResponse) -> List[bytes]: ... diff --git a/third_party/2and3/werkzeug/middleware/proxy_fix.pyi b/third_party/2and3/werkzeug/middleware/proxy_fix.pyi new file mode 100644 index 000000000000..46aec1528360 --- /dev/null +++ b/third_party/2and3/werkzeug/middleware/proxy_fix.pyi @@ -0,0 +1,23 @@ +from typing import Iterable, Optional +from wsgiref.types import StartResponse, WSGIApplication, WSGIEnvironment + +class ProxyFix(object): + app: WSGIApplication + x_for: int + x_proto: int + x_host: int + x_port: int + x_prefix: int + num_proxies: int + def __init__( + self, + app: WSGIApplication, + num_proxies: Optional[int] = ..., + x_for: int = ..., + x_proto: int = ..., + x_host: int = ..., + x_port: int = ..., + x_prefix: int = ..., + ) -> None: ... + def get_remote_addr(self, forwarded_for: Iterable[str]) -> Optional[str]: ... + def __call__(self, environ: WSGIEnvironment, start_response: StartResponse) -> WSGIApplication: ... diff --git a/third_party/2and3/werkzeug/middleware/shared_data.pyi b/third_party/2and3/werkzeug/middleware/shared_data.pyi new file mode 100644 index 000000000000..d1284e8318ec --- /dev/null +++ b/third_party/2and3/werkzeug/middleware/shared_data.pyi @@ -0,0 +1,29 @@ +import datetime +from typing import Callable, IO, Iterable, List, Mapping, Optional, Text, Tuple, Union +from wsgiref.types import StartResponse, WSGIApplication, WSGIEnvironment + +_V = Union[Tuple[Text, Text], Text] + +_Opener = Callable[[], Tuple[IO[bytes], datetime.datetime, int]] +_Loader = Callable[[Optional[Text]], Union[Tuple[None, None], Tuple[Text, _Opener]]] + +class SharedDataMiddleware(object): + app: WSGIApplication + exports: List[Tuple[Text, _Loader]] + cache: bool + cache_timeout: float + def __init__( + self, + app: WSGIApplication, + exports: Union[Mapping[Text, _V], Iterable[Tuple[Text, _V]]], + disallow: Optional[Text] = ..., + cache: bool = ..., + cache_timeout: float = ..., + fallback_mimetype: Text = ..., + ) -> None: ... + def is_allowed(self, filename: Text) -> bool: ... + def get_file_loader(self, filename: Text) -> _Loader: ... + def get_package_loader(self, package: Text, package_path: Text) -> _Loader: ... + def get_directory_loader(self, directory: Text) -> _Loader: ... + def generate_etag(self, mtime: datetime.datetime, file_size: int, real_filename: Union[Text, bytes]) -> str: ... + def __call__(self, environment: WSGIEnvironment, start_response: StartResponse) -> WSGIApplication: ... diff --git a/third_party/2and3/werkzeug/test.pyi b/third_party/2and3/werkzeug/test.pyi index c67189e0b513..764b76d8e78b 100644 --- a/third_party/2and3/werkzeug/test.pyi +++ b/third_party/2and3/werkzeug/test.pyi @@ -1,5 +1,7 @@ import sys -from typing import Any, Optional, Text +from wsgiref.types import WSGIEnvironment +from typing import Any, Generic, Optional, Text, Tuple, Type, TypeVar, overload +from typing_extensions import Literal if sys.version_info < (3,): from urllib2 import Request as U2Request @@ -67,12 +69,16 @@ class EnvironBuilder: class ClientRedirectError(Exception): ... -class Client: +# Response type for the client below. +# By default _R is Tuple[Iterable[Any], Union[Text, int], datastructures.Headers] +_R = TypeVar('_R') + +class Client(Generic[_R]): application: Any - response_wrapper: Any + response_wrapper: Optional[Type[_R]] cookie_jar: Any allow_subdomain_redirects: Any - def __init__(self, application, response_wrapper: Optional[Any] = ..., use_cookies: bool = ..., + def __init__(self, application, response_wrapper: Optional[Type[_R]] = ..., use_cookies: bool = ..., allow_subdomain_redirects: bool = ...): ... def set_cookie(self, server_name, key, value: str = ..., max_age: Optional[Any] = ..., expires: Optional[Any] = ..., path: str = ..., domain: Optional[Any] = ..., secure: Optional[Any] = ..., httponly: bool = ..., @@ -80,15 +86,69 @@ class Client: def delete_cookie(self, server_name, key, path: str = ..., domain: Optional[Any] = ...): ... def run_wsgi_app(self, environ, buffered: bool = ...): ... def resolve_redirect(self, response, new_location, environ, buffered: bool = ...): ... - def open(self, *args, **kwargs): ... - def get(self, *args, **kw): ... - def patch(self, *args, **kw): ... - def post(self, *args, **kw): ... - def head(self, *args, **kw): ... - def put(self, *args, **kw): ... - def delete(self, *args, **kw): ... - def options(self, *args, **kw): ... - def trace(self, *args, **kw): ... + + @overload + def open(self, *args, as_tuple: Literal[True], **kwargs) -> Tuple[WSGIEnvironment, _R]: ... + @overload + def open(self, *args, as_tuple: Literal[False] = ..., **kwargs) -> _R: ... + @overload + def open(self, *args, as_tuple: bool, **kwargs) -> Any: ... + + @overload + def get(self, *args, as_tuple: Literal[True], **kw) -> Tuple[WSGIEnvironment, _R]: ... + @overload + def get(self, *args, as_tuple: Literal[False] = ..., **kw) -> _R: ... + @overload + def get(self, *args, as_tuple: bool, **kw) -> Any: ... + + @overload + def patch(self, *args, as_tuple: Literal[True], **kw) -> Tuple[WSGIEnvironment, _R]: ... + @overload + def patch(self, *args, as_tuple: Literal[False] = ..., **kw) -> _R: ... + @overload + def patch(self, *args, as_tuple: bool, **kw) -> Any: ... + + @overload + def post(self, *args, as_tuple: Literal[True], **kw) -> Tuple[WSGIEnvironment, _R]: ... + @overload + def post(self, *args, as_tuple: Literal[False] = ..., **kw) -> _R: ... + @overload + def post(self, *args, as_tuple: bool, **kw) -> Any: ... + + @overload + def head(self, *args, as_tuple: Literal[True], **kw) -> Tuple[WSGIEnvironment, _R]: ... + @overload + def head(self, *args, as_tuple: Literal[False] = ..., **kw) -> _R: ... + @overload + def head(self, *args, as_tuple: bool, **kw) -> Any: ... + + @overload + def put(self, *args, as_tuple: Literal[True], **kw) -> Tuple[WSGIEnvironment, _R]: ... + @overload + def put(self, *args, as_tuple: Literal[False] = ..., **kw) -> _R: ... + @overload + def put(self, *args, as_tuple: bool, **kw) -> Any: ... + + @overload + def delete(self, *args, as_tuple: Literal[True], **kw) -> Tuple[WSGIEnvironment, _R]: ... + @overload + def delete(self, *args, as_tuple: Literal[False] = ..., **kw) -> _R: ... + @overload + def delete(self, *args, as_tuple: bool, **kw) -> Any: ... + + @overload + def options(self, *args, as_tuple: Literal[True], **kw) -> Tuple[WSGIEnvironment, _R]: ... + @overload + def options(self, *args, as_tuple: Literal[False] = ..., **kw) -> _R: ... + @overload + def options(self, *args, as_tuple: bool, **kw) -> Any: ... + + @overload + def trace(self, *args, as_tuple: Literal[True], **kw) -> Tuple[WSGIEnvironment, _R]: ... + @overload + def trace(self, *args, as_tuple: Literal[False] = ..., **kw) -> _R: ... + @overload + def trace(self, *args, as_tuple: bool, **kw) -> Any: ... def create_environ(*args, **kwargs): ... def run_wsgi_app(app, environ, buffered: bool = ...): ... diff --git a/third_party/2and3/werkzeug/wrappers.pyi b/third_party/2and3/werkzeug/wrappers.pyi index 74cb6ffa870b..c1635b9fcdcb 100644 --- a/third_party/2and3/werkzeug/wrappers.pyi +++ b/third_party/2and3/werkzeug/wrappers.pyi @@ -1,8 +1,8 @@ +import sys from datetime import datetime from typing import ( - Any, Callable, Iterable, Iterator, Mapping, MutableMapping, Optional, Sequence, Text, Tuple, Type, TypeVar, Union, + Any, Callable, Iterable, Iterator, Mapping, MutableMapping, Optional, Sequence, Text, Tuple, Type, TypeVar, Union, overload ) - from wsgiref.types import WSGIEnvironment, InputStream from .datastructures import ( @@ -12,15 +12,20 @@ from .datastructures import ( ) from .useragents import UserAgent +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + class BaseRequest: charset: str encoding_errors: str max_content_length: Optional[int] max_form_memory_size: int - parameter_storage_class: Type - list_storage_class: Type - dict_storage_class: Type - form_data_parser_class: Type + parameter_storage_class: Type[Any] + list_storage_class: Type[Any] + dict_storage_class: Type[Any] + form_data_parser_class: Type[Any] trusted_hosts: Optional[Sequence[Text]] disable_data_descriptor: Any environ: WSGIEnvironment = ... @@ -41,14 +46,22 @@ class BaseRequest: @property def stream(self) -> InputStream: ... input_stream: InputStream - args: ImmutableMultiDict + args: ImmutableMultiDict[Any, Any] @property def data(self) -> bytes: ... - # TODO: once Literal types are supported, overload with as_text - def get_data(self, cache: bool = ..., as_text: bool = ..., parse_form_data: bool = ...) -> Any: ... # returns bytes if as_text is False (the default), else Text - form: ImmutableMultiDict - values: CombinedMultiDict - files: MultiDict + @overload + def get_data(self, cache: bool = ..., as_text: Literal[False] = ..., parse_form_data: bool = ...) -> bytes: ... + @overload + def get_data(self, cache: bool, as_text: Literal[True], parse_form_data: bool = ...) -> Text: ... + @overload + def get_data(self, *, as_text: Literal[True], parse_form_data: bool = ...) -> Text: ... + @overload + def get_data(self, cache: bool, as_text: bool, parse_form_data: bool = ...) -> Any: ... + @overload + def get_data(self, *, as_text: bool, parse_form_data: bool = ...) -> Any: ... + form: ImmutableMultiDict[Any, Any] + values: CombinedMultiDict[Any, Any] + files: MultiDict[Any, Any] @property def cookies(self) -> ImmutableTypeConversionDict[str, str]: ... headers: EnvironHeaders @@ -107,8 +120,12 @@ class BaseResponse: def force_type(cls: Type[_SelfT], response: object, environ: Optional[WSGIEnvironment] = ...) -> _SelfT: ... @classmethod def from_app(cls: Type[_SelfT], app: Any, environ: WSGIEnvironment, buffered: bool = ...) -> _SelfT: ... - # TODO: once Literal types are supported, overload with as_text - def get_data(self, as_text: bool = ...) -> Any: ... # returns bytes if as_text is False (the default), else Text + @overload + def get_data(self, as_text: Literal[False] = ...) -> bytes: ... + @overload + def get_data(self, as_text: Literal[True]) -> Text: ... + @overload + def get_data(self, as_text: bool) -> Any: ... def set_data(self, value: Union[bytes, Text]) -> None: ... data: Any def calculate_content_length(self) -> Optional[int]: ... diff --git a/third_party/2and3/werkzeug/wsgi.pyi b/third_party/2and3/werkzeug/wsgi.pyi index 87deff409dda..c7863cdd63a3 100644 --- a/third_party/2and3/werkzeug/wsgi.pyi +++ b/third_party/2and3/werkzeug/wsgi.pyi @@ -1,6 +1,10 @@ from typing import Any, Optional, Protocol, Iterable, Text from wsgiref.types import WSGIEnvironment, InputStream +from .middleware.dispatcher import DispatcherMiddleware as DispatcherMiddleware +from .middleware.http_proxy import ProxyMiddleware as ProxyMiddleware +from .middleware.shared_data import SharedDataMiddleware as SharedDataMiddleware + def responder(f): ... def get_current_url(environ, root_only: bool = ..., strip_querystring: bool = ..., host_only: bool = ..., trusted_hosts: Optional[Any] = ...): ... @@ -16,27 +20,6 @@ def peek_path_info(environ, charset: Text = ..., errors: Text = ...): ... def extract_path_info(environ_or_baseurl, path_or_url, charset: Text = ..., errors: Text = ..., collapse_http_schemes: bool = ...): ... -class SharedDataMiddleware: - app: Any - exports: Any - cache: Any - cache_timeout: Any - fallback_mimetype: Any - def __init__(self, app, exports, disallow: Optional[Any] = ..., cache: bool = ..., cache_timeout=..., - fallback_mimetype: str = ...): ... - def is_allowed(self, filename): ... - def get_file_loader(self, filename): ... - def get_package_loader(self, package, package_path): ... - def get_directory_loader(self, directory): ... - def generate_etag(self, mtime, file_size, real_filename): ... - def __call__(self, environ, start_response): ... - -class DispatcherMiddleware: - app: Any - mounts: Any - def __init__(self, app, mounts: Optional[Any] = ...): ... - def __call__(self, environ, start_response): ... - class ClosingIterator: def __init__(self, iterable, callbacks: Optional[Any] = ...): ... def __iter__(self): ... diff --git a/third_party/2and3/yaml/__init__.pyi b/third_party/2and3/yaml/__init__.pyi index c0fc6a98270c..8af0d23ff4c5 100644 --- a/third_party/2and3/yaml/__init__.pyi +++ b/third_party/2and3/yaml/__init__.pyi @@ -23,12 +23,12 @@ def scan(stream, Loader=...): ... def parse(stream, Loader=...): ... def compose(stream, Loader=...): ... def compose_all(stream, Loader=...): ... -def load(stream: Union[str, IO[str]], Loader=...) -> Any: ... -def load_all(stream: Union[str, IO[str]], Loader=...) -> Iterator[Any]: ... -def full_load(stream: Union[str, IO[str]]) -> Any: ... -def full_load_all(stream: Union[str, IO[str]]) -> Iterator[Any]: ... -def safe_load(stream: Union[str, IO[str]]) -> Any: ... -def safe_load_all(stream: Union[str, IO[str]]) -> Iterator[Any]: ... +def load(stream: Union[bytes, IO[bytes], str, IO[str]], Loader=...) -> Any: ... +def load_all(stream: Union[bytes, IO[bytes], str, IO[str]], Loader=...) -> Iterator[Any]: ... +def full_load(stream: Union[bytes, IO[bytes], str, IO[str]]) -> Any: ... +def full_load_all(stream: Union[bytes, IO[bytes], str, IO[str]]) -> Iterator[Any]: ... +def safe_load(stream: Union[bytes, IO[bytes], str, IO[str]]) -> Any: ... +def safe_load_all(stream: Union[bytes, IO[bytes], str, IO[str]]) -> Iterator[Any]: ... def emit(events, stream=..., Dumper=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=...): ... @overload diff --git a/third_party/3.5/contextvars.pyi b/third_party/3/contextvars.pyi similarity index 100% rename from third_party/3.5/contextvars.pyi rename to third_party/3/contextvars.pyi diff --git a/third_party/3/dataclasses.pyi b/third_party/3/dataclasses.pyi index f8bcd52634df..e3bf1d1365b9 100644 --- a/third_party/3/dataclasses.pyi +++ b/third_party/3/dataclasses.pyi @@ -34,7 +34,7 @@ class Field(Generic[_T]): hash: Optional[bool] init: bool compare: bool - metadata: Optional[Mapping[str, Any]] + metadata: Mapping[str, Any] # NOTE: Actual return type is 'Field[_T]', but we want to help type checkers diff --git a/third_party/3/docutils/parsers/rst/roles.pyi b/third_party/3/docutils/parsers/rst/roles.pyi index 58b9cd73c350..622db836d2e9 100644 --- a/third_party/3/docutils/parsers/rst/roles.pyi +++ b/third_party/3/docutils/parsers/rst/roles.pyi @@ -3,10 +3,11 @@ import docutils.parsers.rst.states from typing import Callable, Any, List, Dict, Tuple -def register_local_role(name: str, - role_fn: Callable[[str, str, str, int, docutils.parsers.rst.states.Inliner, Dict, List], - Tuple[List[docutils.nodes.reference], List[docutils.nodes.reference]]] - ) -> None: - ... +_RoleFn = Callable[ + [str, str, str, int, docutils.parsers.rst.states.Inliner, Dict[str, Any], List[str]], + Tuple[List[docutils.nodes.reference], List[docutils.nodes.reference]], +] -def __getattr__(name) -> Any: ... +def register_local_role(name: str, role_fn: _RoleFn) -> None: ... + +def __getattr__(name: str) -> Any: ... # incomplete diff --git a/third_party/3/jwt/__init__.pyi b/third_party/3/jwt/__init__.pyi index da8eb4095b2b..b98e0f57fa97 100644 --- a/third_party/3/jwt/__init__.pyi +++ b/third_party/3/jwt/__init__.pyi @@ -11,9 +11,7 @@ def encode(payload: Mapping[str, Any], key: Union[str, bytes], algorithm: str = ..., headers: Optional[Mapping[str, Any]] = ..., json_encoder: Optional[Any] = ...) -> bytes: ... -def register_algorithm(alg_id: str, - alg_obj: algorithms.Algorithm) -> None: ... - +def register_algorithm(alg_id: str, alg_obj: algorithms.Algorithm[Any]) -> None: ... def unregister_algorithm(alg_id: str) -> None: ... class PyJWTError(Exception): ... diff --git a/third_party/3/jwt/algorithms.pyi b/third_party/3/jwt/algorithms.pyi index 7177dc7d1252..a93f44f5aa6d 100644 --- a/third_party/3/jwt/algorithms.pyi +++ b/third_party/3/jwt/algorithms.pyi @@ -4,7 +4,7 @@ from typing import Any, Set, Dict, Optional, ClassVar, Union, Generic, TypeVar requires_cryptography = Set[str] -def get_default_algorithms() -> Dict[str, Algorithm]: ... +def get_default_algorithms() -> Dict[str, Algorithm[Any]]: ... _K = TypeVar("_K") @@ -13,10 +13,9 @@ class Algorithm(Generic[_K]): def sign(self, msg: bytes, key: _K) -> bytes: ... def verify(self, msg: bytes, key: _K, sig: bytes) -> bool: ... @staticmethod - def to_jwk(key_obj: Any) -> str: ... # should be key_obj: _K, see python/mypy#1337 + def to_jwk(key_obj: _K) -> str: ... @staticmethod - def from_jwk(jwk: str) -> Any: ... # should return _K, see python/mypy#1337 - + def from_jwk(jwk: str) -> _K: ... class NoneAlgorithm(Algorithm[None]): def prepare_key(self, key: Optional[str]) -> None: ... @@ -44,7 +43,7 @@ class HMACAlgorithm(Algorithm[bytes]): # Only defined if cryptography is installed. Types should be tightened when # cryptography gets type hints. # See https://github.com/python/typeshed/issues/2542 -class RSAAlgorithm(Algorithm): +class RSAAlgorithm(Algorithm[Any]): SHA256: ClassVar[Any] SHA384: ClassVar[Any] SHA512: ClassVar[Any] @@ -61,7 +60,7 @@ class RSAAlgorithm(Algorithm): # Only defined if cryptography is installed. Types should be tightened when # cryptography gets type hints. # See https://github.com/python/typeshed/issues/2542 -class ECAlgorithm(Algorithm): +class ECAlgorithm(Algorithm[Any]): SHA256: ClassVar[Any] SHA384: ClassVar[Any] SHA512: ClassVar[Any] diff --git a/third_party/3/jwt/contrib/algorithms/py_ecdsa.pyi b/third_party/3/jwt/contrib/algorithms/py_ecdsa.pyi index e1342cced745..93f0e1a25fdb 100644 --- a/third_party/3/jwt/contrib/algorithms/py_ecdsa.pyi +++ b/third_party/3/jwt/contrib/algorithms/py_ecdsa.pyi @@ -3,7 +3,7 @@ from jwt.algorithms import Algorithm from . import _HashAlg -class ECAlgorithm(Algorithm): +class ECAlgorithm(Algorithm[Any]): SHA256: _HashAlg SHA384: _HashAlg SHA512: _HashAlg diff --git a/third_party/3/jwt/contrib/algorithms/pycrypto.pyi b/third_party/3/jwt/contrib/algorithms/pycrypto.pyi index 763b46a32428..a86233fcda60 100644 --- a/third_party/3/jwt/contrib/algorithms/pycrypto.pyi +++ b/third_party/3/jwt/contrib/algorithms/pycrypto.pyi @@ -3,7 +3,7 @@ from jwt.algorithms import Algorithm from . import _HashAlg -class RSAAlgorithm(Algorithm): +class RSAAlgorithm(Algorithm[Any]): SHA256: _HashAlg SHA384: _HashAlg SHA512: _HashAlg diff --git a/third_party/3/maxminddb/__init__.pyi b/third_party/3/maxminddb/__init__.pyi new file mode 100644 index 000000000000..040872fed4ec --- /dev/null +++ b/third_party/3/maxminddb/__init__.pyi @@ -0,0 +1,9 @@ +# Stubs for maxminddb (Python 3) + +from typing import Any + +from maxminddb import reader + +def open_database(database: str, mode: int = ...) -> reader.Reader: ... + +def Reader(database: str) -> reader.Reader: ... diff --git a/third_party/3/maxminddb/compat.pyi b/third_party/3/maxminddb/compat.pyi new file mode 100644 index 000000000000..236b0797ea94 --- /dev/null +++ b/third_party/3/maxminddb/compat.pyi @@ -0,0 +1,10 @@ +# Stubs for maxminddb.compat (Python 3) + +from ipaddress import IPv4Address, IPv6Address + +from typing import Any + +def compat_ip_address(address: object) -> Any: ... +def int_from_byte(x: int) -> int: ... +def int_from_bytes(x: bytes) -> int: ... +def byte_from_int(x: int) -> bytes: ... diff --git a/third_party/3/maxminddb/const.pyi b/third_party/3/maxminddb/const.pyi new file mode 100644 index 000000000000..36d11a7fa55f --- /dev/null +++ b/third_party/3/maxminddb/const.pyi @@ -0,0 +1,8 @@ +# Stubs for maxminddb.const (Python 3) + +MODE_AUTO: int = ... +MODE_MMAP_EXT: int = ... +MODE_MMAP: int = ... +MODE_FILE: int = ... +MODE_MEMORY: int = ... +MODE_FD: int = ... diff --git a/third_party/3/maxminddb/decoder.pyi b/third_party/3/maxminddb/decoder.pyi new file mode 100644 index 000000000000..1b7aa6e154a6 --- /dev/null +++ b/third_party/3/maxminddb/decoder.pyi @@ -0,0 +1,7 @@ +# Stubs for maxminddb.decoder (Python 3) + +from typing import Any, Tuple + +class Decoder: + def __init__(self, database_buffer: bytes, pointer_base: int = ..., pointer_test: bool = ...) -> None: ... + def decode(self, offset: int) -> Tuple[Any, int]: ... diff --git a/third_party/3/maxminddb/errors.pyi b/third_party/3/maxminddb/errors.pyi new file mode 100644 index 000000000000..46b1f5aee972 --- /dev/null +++ b/third_party/3/maxminddb/errors.pyi @@ -0,0 +1,3 @@ +# Stubs for maxminddb.errors (Python 3) + +class InvalidDatabaseError(RuntimeError): ... diff --git a/third_party/3/maxminddb/extension.pyi b/third_party/3/maxminddb/extension.pyi new file mode 100644 index 000000000000..24fb851803f3 --- /dev/null +++ b/third_party/3/maxminddb/extension.pyi @@ -0,0 +1,35 @@ +# Stubs for maxminddb.extension (Python 3) + +from typing import Any, Mapping, Sequence + +from maxminddb.errors import InvalidDatabaseError as InvalidDatabaseError + +class Reader: + closed: bool = ... + def __init__(self, *args: Any, **kwargs: Any) -> None: ... + def close(self, *args: Any, **kwargs: Any) -> Any: ... + def get(self, *args: Any, **kwargs: Any) -> Any: ... + def metadata(self, *args: Any, **kwargs: Any) -> Any: ... + def __enter__(self, *args: Any, **kwargs: Any) -> Any: ... + def __exit__(self, *args: Any, **kwargs: Any) -> Any: ... + +class extension: + @property + def node_count(self) -> int: ... + @property + def record_size(self) -> int: ... + @property + def ip_version(self) -> int: ... + @property + def database_type(self) -> str: ... + @property + def languages(self) -> Sequence[str]: ... + @property + def binary_format_major_version(self) -> int: ... + @property + def binary_format_minor_version(self) -> int: ... + @property + def build_epoch(self) -> int: ... + @property + def description(self) -> Mapping[str, str]: ... + def __init__(self, **kwargs: Any) -> None: ... diff --git a/third_party/3/maxminddb/reader.pyi b/third_party/3/maxminddb/reader.pyi new file mode 100644 index 000000000000..47e7f6493a8f --- /dev/null +++ b/third_party/3/maxminddb/reader.pyi @@ -0,0 +1,32 @@ +# Stubs for maxminddb.reader (Python 3) + +from ipaddress import IPv4Address, IPv6Address + +from types import TracebackType +from typing import Any, Mapping, Optional, Sequence, Tuple, Type, Union + +class Reader: + closed: bool = ... + def __init__(self, database: bytes, mode: int = ...) -> None: ... + def metadata(self) -> Metadata: ... + def get(self, ip_address: Union[str, IPv4Address, IPv6Address]) -> Optional[Any]: ... + def get_with_prefix_len(self, ip_address: Union[str, IPv4Address, IPv6Address]) -> Tuple[Optional[Any], int]: ... + def close(self) -> None: ... + def __enter__(self) -> Reader: ... + def __exit__(self, exc_type: Optional[Type[BaseException]] = ..., exc_val: Optional[BaseException] = ..., exc_tb: Optional[TracebackType] = ...) -> None: ... + +class Metadata: + node_count: int = ... + record_size: int = ... + ip_version: int = ... + database_type: str = ... + languages: Sequence[str] = ... + binary_format_major_version: int = ... + binary_format_minor_version: int = ... + build_epoch: int = ... + description: Mapping[str, str] = ... + def __init__(self, **kwargs: Any) -> None: ... + @property + def node_byte_size(self) -> int: ... + @property + def search_tree_size(self) -> int: ... diff --git a/third_party/3/pkg_resources/py31compat.pyi b/third_party/3/pkg_resources/py31compat.pyi index e7b17a3c4ec6..aefe113011e1 100644 --- a/third_party/3/pkg_resources/py31compat.pyi +++ b/third_party/3/pkg_resources/py31compat.pyi @@ -4,11 +4,4 @@ import sys needs_makedirs: bool -def _makedirs_31(path: Text, exist_ok: bool = ...) -> None: ... - -# _makedirs_31 has special behavior to handle an edge case that was removed in -# 3.4.1. No one should be using 3.4 instead of 3.4.1, so this should be fine. -if sys.version_info >= (3,): - makedirs = os.makedirs -else: - makedirs = _makedirs_31 +makedirs = os.makedirs diff --git a/third_party/3/six/moves/urllib/parse.pyi b/third_party/3/six/moves/urllib/parse.pyi index 8b4310a4e7c6..265660d30bda 100644 --- a/third_party/3/six/moves/urllib/parse.pyi +++ b/third_party/3/six/moves/urllib/parse.pyi @@ -16,6 +16,7 @@ from urllib.parse import quote as quote from urllib.parse import quote_plus as quote_plus from urllib.parse import unquote as unquote from urllib.parse import unquote_plus as unquote_plus +from urllib.parse import unquote_to_bytes as unquote_to_bytes from urllib.parse import urlencode as urlencode # from urllib.parse import splitquery as splitquery # from urllib.parse import splittag as splittag