From e7184d6dfc3d8d8dfbecd4f04f1852ce441effd6 Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Sat, 8 Jun 2019 07:06:14 -0700 Subject: [PATCH 001/201] Add undocumented but used method LWPCookieJar.as_lwp_str. (#3041) The method is defined here: https://github.com/python/cpython/blob/e36ed475ea429f7cc80a4d65f80b44686a74b246/Lib/http/cookiejar.py#L1864 --- stdlib/2/cookielib.pyi | 4 +++- stdlib/3/http/cookiejar.pyi | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) 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/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 From d64a26cf99a57b54fd5846dd7c0e88b020b58d09 Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Sat, 8 Jun 2019 07:07:29 -0700 Subject: [PATCH 002/201] Add missing constructor to types.CodeType. (#3040) I got the argument order from https://github.com/python/cpython/blob/2bfc2dc214445550521074f428245b502d215eac/Objects/codeobject.c#L263 and the types from the attributes already in the stub. --- stdlib/2/types.pyi | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/stdlib/2/types.pyi b/stdlib/2/types.pyi index 5984706aee8a..93360e7dec35 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 From 55a566340af1250660e14b77d35e411e9a9b4b52 Mon Sep 17 00:00:00 2001 From: Connor Skees <39542938+ConnorSkees@users.noreply.github.com> Date: Sat, 8 Jun 2019 15:19:57 -0400 Subject: [PATCH 003/201] Add `copy()` method to requests.Session.headers (#3043) * Add `copy()` method to requests.Session.headers * Use one type annotation --- third_party/2and3/requests/sessions.pyi | 2 +- third_party/2and3/requests/structures.pyi | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/third_party/2and3/requests/sessions.pyi b/third_party/2and3/requests/sessions.pyi index 33c7b79e1d95..db275ae4e6b3 100644 --- a/third_party/2and3/requests/sessions.pyi +++ b/third_party/2and3/requests/sessions.pyi @@ -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 diff --git a/third_party/2and3/requests/structures.pyi b/third_party/2and3/requests/structures.pyi index 92cf27aa1cd5..807f39a1c6b0 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: ... class LookupDict(Dict[str, _VT]): name: Any From ed2a851ed8d381b534408726ae93948239c695ea Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 10 Jun 2019 11:21:50 -0700 Subject: [PATCH 004/201] dateutil: byweekday can take weekday (#3046) --- third_party/2and3/dateutil/rrule.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/2and3/dateutil/rrule.pyi b/third_party/2and3/dateutil/rrule.pyi index f8ab9d29ad36..84e4eb5441bc 100644 --- a/third_party/2and3/dateutil/rrule.pyi +++ b/third_party/2and3/dateutil/rrule.pyi @@ -46,7 +46,7 @@ class rrule(rrulebase): 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]]] = ..., From 901cb33a3cfcbee21af4c2b825194fe151313292 Mon Sep 17 00:00:00 2001 From: Walter Scott Johnson Date: Mon, 10 Jun 2019 11:58:31 -0700 Subject: [PATCH 005/201] Mark asyncio loop parameters as Optional (#3047) --- stdlib/3/asyncio/tasks.pyi | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/stdlib/3/asyncio/tasks.pyi b/stdlib/3/asyncio/tasks.pyi index 6fe13f57eb5e..ef657aab1248 100644 --- a/stdlib/3/asyncio/tasks.pyi +++ b/stdlib/3/asyncio/tasks.pyi @@ -21,7 +21,7 @@ FIRST_EXCEPTION: str FIRST_COMPLETED: str ALL_COMPLETED: str -def as_completed(fs: Sequence[_FutureT[_T]], *, loop: AbstractEventLoop = ..., +def as_completed(fs: Sequence[_FutureT[_T]], *, loop: Optional[AbstractEventLoop] = ..., timeout: Optional[float] = ...) -> Iterator[Future[_T]]: ... def ensure_future(coro_or_future: _FutureT[_T], *, loop: Optional[AbstractEventLoop] = ...) -> Future[_T]: ... @@ -29,34 +29,34 @@ def ensure_future(coro_or_future: _FutureT[_T], # It became a keyword in 3.7. @overload def gather(coro_or_future1: _FutureT[_T1], - *, loop: AbstractEventLoop = ..., return_exceptions: bool = ...) -> Future[Tuple[_T1]]: ... + *, loop: Optional[AbstractEventLoop] = ..., return_exceptions: bool = ...) -> 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: bool = ...) -> 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: bool = ...) -> 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: bool = ...) -> 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: bool = ...) -> 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[Tuple[Any, ...]]: ... 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 From 5327484176f7d56dc72e68fc04f03bd3fd2cabdb Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Tue, 11 Jun 2019 04:20:59 +0100 Subject: [PATCH 006/201] Use type annotation syntax (#3048) --- stdlib/2and3/traceback.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/2and3/traceback.pyi b/stdlib/2and3/traceback.pyi index 7adc5eb7d5e7..cbefb62f020c 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] From b9101e9c5ec124cdf551e4000a046f14a65ebdbc Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 12 Jun 2019 18:18:48 +0200 Subject: [PATCH 007/201] Add a few Redis types (#3016) * StrictRedis is an alias for Redis in current redis * Add a few types * Add missing import * Add missing argument and types --- third_party/2and3/redis/client.pyi | 59 ++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/third_party/2and3/redis/client.pyi b/third_party/2and3/redis/client.pyi index f41676177336..cd655964463a 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, Text, Optional, Mapping, Union + +from .connection import ConnectionPool SYM_EMPTY: Any @@ -31,16 +34,37 @@ def parse_hscan(response, **options): ... def parse_zscan(response, **options): ... def parse_slowlog_get(response, **options): ... -class StrictRedis: +class Redis(object): RESPONSE_CALLBACKS: Any @classmethod def from_url(cls, url, db=..., **kwargs): ... 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): ... @@ -93,9 +117,9 @@ class StrictRedis: def dump(self, name): ... def exists(self, name): ... __contains__: Any - def expire(self, name, time): ... + def expire(self, name: Text, time: Union[int, timedelta]) -> bool: ... def expireat(self, name, when): ... - def get(self, name): ... + def get(self, name: Text) -> Optional[bytes]: ... def __getitem__(self, name): ... def getbit(self, name, offset): ... def getrange(self, key, start, end): ... @@ -117,7 +141,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: Text, + value: Any, + 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): ... @@ -169,7 +201,7 @@ 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 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=...): ... @@ -213,12 +245,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 From e4a9cd580c716e8d5194771f9c096ab27263f3ba Mon Sep 17 00:00:00 2001 From: John Freeman Date: Wed, 12 Jun 2019 13:03:14 -0500 Subject: [PATCH 008/201] Add missing path-like annotation (#3053) Fixes #3052 --- stdlib/3/importlib/util.pyi | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/stdlib/3/importlib/util.pyi b/stdlib/3/importlib/util.pyi index 706a5dd94027..32d97cf276cd 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,8 +30,15 @@ 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: ... From 8e7c32846fc2b07eff10296f815f053a5f6daaa5 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Thu, 13 Jun 2019 10:01:13 +0000 Subject: [PATCH 009/201] request.pyi: Change Union[] -> Any for attributing status. (#3045) Fixes #3026 --- stdlib/3/urllib/request.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index a1a556813fef..e096ef4ef7f8 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -13,7 +13,7 @@ import sys import os _T = TypeVar('_T') -_UrlopenRet = Union[_HTTPResponse, addinfourl] +_UrlopenRet = Any class _HTTPResponse(HTTPResponse): url: str From 8ffe20fc2251e236dbbd55fc206540ec35791a9c Mon Sep 17 00:00:00 2001 From: Joe Juzl Date: Thu, 13 Jun 2019 18:24:39 +0200 Subject: [PATCH 010/201] Add redis stream methods to the client stubs (#3051) --- third_party/2and3/redis/client.pyi | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/third_party/2and3/redis/client.pyi b/third_party/2and3/redis/client.pyi index cd655964463a..7049ff4e69c7 100644 --- a/third_party/2and3/redis/client.pyi +++ b/third_party/2and3/redis/client.pyi @@ -201,6 +201,37 @@ class Redis(object): def srem(self, name, *values): ... def sunion(self, keys, *args): ... def sunionstore(self, dest, keys, *args): ... + 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): ... From 1f740a7926049cbddc8d1b795c66381104a96aa6 Mon Sep 17 00:00:00 2001 From: Mark Mendoza Date: Thu, 13 Jun 2019 14:14:54 -0700 Subject: [PATCH 011/201] Adding stubs for pyre_extensions (#3056) --- third_party/2and3/pyre_extensions.pyi | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 third_party/2and3/pyre_extensions.pyi diff --git a/third_party/2and3/pyre_extensions.pyi b/third_party/2and3/pyre_extensions.pyi new file mode 100644 index 000000000000..04adc5093f13 --- /dev/null +++ b/third_party/2and3/pyre_extensions.pyi @@ -0,0 +1,6 @@ +from typing import List, Optional, Type, TypeVar + +_T = TypeVar("_T") + +def none_throws(optional: Optional[_T]) -> _T: ... +def ParameterSpecification(__name: str) -> List[Type]: ... From d36a519b95e4f550788c3d8064385604a32c68fd Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sat, 15 Jun 2019 16:35:18 -0700 Subject: [PATCH 012/201] Update select and selectors to use _HasFileno protocol (#3057) --- stdlib/2and3/select.pyi | 9 +++++---- stdlib/3/selectors.pyi | 10 ++++------ 2 files changed, 9 insertions(+), 10 deletions(-) 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/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 From 1efebf78e488a49708693c55c0fab1a0043f88de Mon Sep 17 00:00:00 2001 From: Sean Vig Date: Sun, 16 Jun 2019 10:17:26 -0400 Subject: [PATCH 013/201] Marshal dumps/loads uses bytes (#3061) The marshal.dumps and marshal.loads functions should return and accept bytes, respectively, rather than a string. --- stdlib/2and3/marshal.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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: ... From 6258e7ddfd92ac1a770013b8f5dc5aa719c3461d Mon Sep 17 00:00:00 2001 From: Alexander Fasching Date: Sun, 16 Jun 2019 23:11:10 +0200 Subject: [PATCH 014/201] ssl.pyi: fix types of cadata argument (#3063) --- stdlib/2and3/ssl.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/2and3/ssl.pyi b/stdlib/2and3/ssl.pyi index 4b51e409f0f4..52545f3e182f 100644 --- a/stdlib/2and3/ssl.pyi +++ b/stdlib/2and3/ssl.pyi @@ -51,7 +51,7 @@ if sys.version_info < (3,) or sys.version_info >= (3, 4): def create_default_context(purpose: Any = ..., *, cafile: Optional[str] = ..., capath: Optional[str] = ..., - cadata: Optional[str] = ...) -> SSLContext: ... + cadata: Union[str, bytes, None] = ...) -> SSLContext: ... if sys.version_info >= (3, 4): def _create_unverified_context(protocol: int = ..., *, @@ -62,7 +62,7 @@ if sys.version_info >= (3, 4): keyfile: Optional[str] = ..., cafile: Optional[str] = ..., capath: Optional[str] = ..., - cadata: Optional[str] = ...) -> SSLContext: ... + cadata: Union[str, bytes, None] = ...) -> SSLContext: ... _create_default_https_context: Callable[..., SSLContext] if sys.version_info >= (3, 3): From 5447ff6bfe080e2f6bc6c443203c32ee18c6cd60 Mon Sep 17 00:00:00 2001 From: Jadiker Date: Mon, 17 Jun 2019 14:09:11 -0400 Subject: [PATCH 015/201] str and unicode format functions take objects (#3068) --- stdlib/2/__builtin__.pyi | 4 ++-- stdlib/2and3/builtins.pyi | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 13a6ef968ecc..cf1428d86db0 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -332,7 +332,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 +421,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: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 13a6ef968ecc..cf1428d86db0 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -332,7 +332,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 +421,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: ... From fcb97fe8f17b21d6c4c87e4ed0618363455cd5db Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Mon, 17 Jun 2019 15:27:14 -0600 Subject: [PATCH 016/201] Overload ast.parse to recognize that mode=exec means Module return. (#3039) --- stdlib/3/ast.pyi | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/stdlib/3/ast.pyi b/stdlib/3/ast.pyi index 090d5f8aec84..e4c355dc20bb 100644 --- a/stdlib/3/ast.pyi +++ b/stdlib/3/ast.pyi @@ -5,7 +5,8 @@ import sys # 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 +from typing_extensions import Literal # The same unorthodox Bazel integration causes issues with sys, which # is imported in both modules. unfortunately we can't just rename sys, @@ -23,9 +24,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: ... From 01c2fa5a140071071ddccc414338cfcf9bf206a2 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Tue, 18 Jun 2019 02:31:54 +0100 Subject: [PATCH 017/201] Sync recent typing and typing_extensions updates (#3070) This includes two things to sync up with recent runtime updates: * Move `Final`, `@final`, `Literal`, and `TypedDict` to `typing` (`typing_extensions` still defines or re-exports them) * Rename `@typing.runtime` to `@typing.runtime_checkable`, while keeping `@runtime` as a backwards-compatible alias in `typing_extensions`. --- stdlib/2/typing.pyi | 45 ++++++++++++++----- stdlib/3/typing.pyi | 58 ++++++++++++++++--------- third_party/2and3/typing_extensions.pyi | 4 +- 3 files changed, 74 insertions(+), 33 deletions(-) diff --git a/stdlib/2/typing.pyi b/stdlib/2/typing.pyi index 6c159b963207..af22c7e1d9ec 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): ... @@ -65,39 +71,39 @@ _T_contra = TypeVar('_T_contra', contravariant=True) # Ditto contravariant. _TC = TypeVar('_TC', bound=Type[object]) _C = TypeVar("_C", bound=Callable) -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]], @@ -462,6 +468,21 @@ class NamedTuple(tuple): def _asdict(self) -> dict: ... 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/3/typing.pyi b/stdlib/3/typing.pyi index e83640a73d1e..43202e017355 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): ... @@ -67,34 +74,34 @@ _T_contra = TypeVar('_T_contra', contravariant=True) # Ditto contravariant. _TC = TypeVar('_TC', bound=Type[object]) _C = TypeVar("_C", bound=Callable) -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 +110,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 +128,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: ... @@ -162,7 +169,7 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]): # Awaitable, AsyncIterator, AsyncIterable, Coroutine, Collection. # See https: //github.com/python/typeshed/issues/655 for why this is not easy. -@runtime +@runtime_checkable class Awaitable(Protocol[_T_co]): @abstractmethod def __await__(self) -> Generator[Any, None, _T_co]: ... @@ -193,12 +200,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 +239,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 +254,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 @@ -359,7 +366,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]], @@ -367,7 +374,7 @@ class ContextManager(Protocol[_T_co]): __traceback: Optional[TracebackType]) -> Optional[bool]: ... if sys.version_info >= (3, 5): - @runtime + @runtime_checkable class AsyncContextManager(Protocol[_T_co]): def __aenter__(self) -> Awaitable[_T_co]: ... def __aexit__(self, exc_type: Optional[Type[BaseException]], @@ -600,6 +607,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/third_party/2and3/typing_extensions.pyi b/third_party/2and3/typing_extensions.pyi index c9a2ec435022..5531601469a1 100644 --- a/third_party/2and3/typing_extensions.pyi +++ b/third_party/2and3/typing_extensions.pyi @@ -19,7 +19,9 @@ _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: ... From 38f253ed698b792499f40784bd420a29ac6e69cb Mon Sep 17 00:00:00 2001 From: Mathieu Bridon Date: Tue, 18 Jun 2019 18:19:51 +0200 Subject: [PATCH 018/201] redis: Add some type hints (#3055) --- third_party/2and3/redis/client.pyi | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/third_party/2and3/redis/client.pyi b/third_party/2and3/redis/client.pyi index 7049ff4e69c7..f086a4be5249 100644 --- a/third_party/2and3/redis/client.pyi +++ b/third_party/2and3/redis/client.pyi @@ -1,5 +1,5 @@ from datetime import timedelta -from typing import Any, Text, Optional, Mapping, Union +from typing import Any, Iterable, Text, Optional, Mapping, Tuple, Union from .connection import ConnectionPool @@ -34,6 +34,8 @@ def parse_hscan(response, **options): ... def parse_zscan(response, **options): ... def parse_slowlog_get(response, **options): ... +_Str = Union[bytes, float, Text] + class Redis(object): RESPONSE_CALLBACKS: Any @classmethod @@ -161,14 +163,14 @@ class Redis(object): 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): ... @@ -176,7 +178,7 @@ class Redis(object): 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=...): ... From aa56af7dce9fc14d3ca81e7215dd3df031f39b70 Mon Sep 17 00:00:00 2001 From: Motoki Naruse Date: Wed, 19 Jun 2019 22:34:37 +0900 Subject: [PATCH 019/201] HTMLParser.get_starttag_text() can return None (#3072) --- stdlib/3/html/parser.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/html/parser.pyi b/stdlib/3/html/parser.pyi index 4b10331be99f..d4cfb5102225 100644 --- a/stdlib/3/html/parser.pyi +++ b/stdlib/3/html/parser.pyi @@ -12,7 +12,7 @@ class HTMLParser(ParserBase): 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: ... From d149fe435cf3b44a4d5b0d2a4e63b8b05845f49b Mon Sep 17 00:00:00 2001 From: Matthew Wilkes Date: Wed, 19 Jun 2019 23:14:15 +0100 Subject: [PATCH 020/201] Represent the use of IntEnums in functions in socket.py. (#3009) The Pull Request #1121 added the `AddressFamily` type to `socket.pyi` for Python 3.4+, so constants such as `AF_INET` are correctly represented as being an enum member rather than an int. The same is true of the `SocketKind` enums in the `SOCK_*` family. Various functions in the socket module can accept either an int or an `AF_*` enum member as arguments, which is allowed by the int argument type. However the `getaddrinfo` function returns an `AddressFamily` member rather than an int in the first position of its list members, so code that access enum specific members such as the `name` attribute causes a typing error to be found. This change corrects the return type of `getaddrinfo` but leaves the family parameters as int, given that `AddressFamily` members are `IntEnum` and only ever treated as `int`s internally. --- stdlib/2and3/socket.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/2and3/socket.pyi b/stdlib/2and3/socket.pyi index 22b2f91357a3..4089b225c0e7 100644 --- a/stdlib/2and3/socket.pyi +++ b/stdlib/2and3/socket.pyi @@ -590,7 +590,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: ... From 2e10326b5064621a2ac33b9b3afe280cf26fc46d Mon Sep 17 00:00:00 2001 From: Florian Ludwig Date: Thu, 20 Jun 2019 00:17:16 +0200 Subject: [PATCH 021/201] change http.cookies.Morsel to Dict[str, Any] (#3060) Morsel does cast any value to string and therfor any is the correct typehint. For some keys other types then strings are more appropiate anyway, max-age can take an integer (unix time) and http-only a boolean. Closes #3059 --- stdlib/3/http/cookies.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/3/http/cookies.pyi b/stdlib/3/http/cookies.pyi index 5e5d58a00583..1e1091ba1c4a 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]]] _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 From 1763f51c0db9ebd210b9908821c83ddb691a756f Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Wed, 19 Jun 2019 15:19:10 -0700 Subject: [PATCH 022/201] Refactor tests/pytype_test.py (#3065) --- tests/pytype_test.py | 257 +++++++++++++++++++++++-------------------- 1 file changed, 136 insertions(+), 121 deletions(-) diff --git a/tests/pytype_test.py b/tests/pytype_test.py index bb4793a20078..c67e85941931 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,21 @@ 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( + [ + "--module-name={}".format(_get_module_name(filename)), + "--parse-pyi", + "-V {}".format(python_version), + "--python_exe={}".format(python_exe), + filename, + ] + ) 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 +109,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 +121,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)) - 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) +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 + ) + ) - 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')): + +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 = [] + 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() From 58221cf20e22b2b5bee36c05965e06d77df65920 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Wed, 19 Jun 2019 18:20:57 -0400 Subject: [PATCH 023/201] Add types and functions in types.py that are new in 3.7 (#3066) * Add types and functions in types.py that are new in 3.7 * Update `resolve_bases` to accept any iterable of objects, and the same for `new_class` if the version is at least 3.7 * Add comparison overrides implemented by MethodWrapperType * Fix mypy error due to over-constrained `__eq__` --- stdlib/3/types.pyi | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/stdlib/3/types.pyi b/stdlib/3/types.pyi index 73b88899c53f..5d0acc7dd24c 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 @@ -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. From 2b6a99c39c25ffe3597d6b4dba38d46d7a1473e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E8=91=89?= Date: Fri, 21 Jun 2019 01:41:32 +0800 Subject: [PATCH 024/201] fix ssl.Purpose type in py3 (#3054) --- stdlib/2and3/ssl.pyi | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/stdlib/2and3/ssl.pyi b/stdlib/2and3/ssl.pyi index 52545f3e182f..0a198eb9f9c5 100644 --- a/stdlib/2and3/ssl.pyi +++ b/stdlib/2and3/ssl.pyi @@ -1,8 +1,9 @@ # Stubs for ssl from typing import ( - Any, Dict, Callable, List, NamedTuple, Optional, Set, Tuple, Union, + Any, Callable, ClassVar, Dict, List, NamedTuple, Optional, Set, Tuple, Union, ) +import enum import socket import sys @@ -172,12 +173,16 @@ if sys.version_info < (3,) or sys.version_info >= (3, 4): 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 - +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] +if sys.version_info >= (3, 4): + 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 @@ -224,7 +229,7 @@ class SSLContext: def load_cert_chain(self, certfile: str, keyfile: Optional[str] = ..., password: _PasswordType = ...) -> None: ... if sys.version_info < (3,) or sys.version_info >= (3, 4): - def load_default_certs(self, purpose: _PurposeType = ...) -> None: ... + def load_default_certs(self, purpose: Purpose = ...) -> None: ... def load_verify_locations(self, cafile: Optional[str] = ..., capath: Optional[str] = ..., cadata: Union[str, bytes, None] = ...) -> None: ... From 9941616b9efd31181bf3e5dd1d5f375791352fec Mon Sep 17 00:00:00 2001 From: crusaderky Date: Thu, 20 Jun 2019 18:42:26 +0100 Subject: [PATCH 025/201] Add mp_context parameter to concurrent.futures.ProcessPoolExecutor (#3078) Closes #3076 --- stdlib/3/concurrent/futures/_base.pyi | 2 +- stdlib/3/concurrent/futures/process.pyi | 5 ++++- stdlib/3/concurrent/futures/thread.pyi | 2 +- third_party/2/concurrent/futures/_base.pyi | 2 +- third_party/2/concurrent/futures/process.pyi | 5 ++++- third_party/2/concurrent/futures/thread.pyi | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/stdlib/3/concurrent/futures/_base.pyi b/stdlib/3/concurrent/futures/_base.pyi index 95189a741199..13037d87f968 100644 --- a/stdlib/3/concurrent/futures/_base.pyi +++ b/stdlib/3/concurrent/futures/_base.pyi @@ -1,4 +1,4 @@ -from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set, NamedTuple +from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set from types import TracebackType import sys 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..e2b236b8df6a 100644 --- a/stdlib/3/concurrent/futures/thread.pyi +++ b/stdlib/3/concurrent/futures/thread.pyi @@ -1,5 +1,5 @@ from typing import Any, Callable, Optional, Tuple -from ._base import Executor, Future +from ._base import Executor import sys class ThreadPoolExecutor(Executor): diff --git a/third_party/2/concurrent/futures/_base.pyi b/third_party/2/concurrent/futures/_base.pyi index 95189a741199..13037d87f968 100644 --- a/third_party/2/concurrent/futures/_base.pyi +++ b/third_party/2/concurrent/futures/_base.pyi @@ -1,4 +1,4 @@ -from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set, NamedTuple +from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set from types import TracebackType import sys 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..e2b236b8df6a 100644 --- a/third_party/2/concurrent/futures/thread.pyi +++ b/third_party/2/concurrent/futures/thread.pyi @@ -1,5 +1,5 @@ from typing import Any, Callable, Optional, Tuple -from ._base import Executor, Future +from ._base import Executor import sys class ThreadPoolExecutor(Executor): From ada0570efce723c470f7cd319f6421a375597847 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 20 Jun 2019 20:39:49 -0700 Subject: [PATCH 026/201] Revert "Define functools.partial as overloaded function instead of its own class (#2878)" (#3077) This reverts commit e45f443d8530f0dd9f9022720a994f222da6f0fd. --- stdlib/2/_functools.pyi | 79 ++++------------------------------------- stdlib/2/functools.pyi | 79 ++++------------------------------------- stdlib/3/functools.pyi | 79 ++++------------------------------------- 3 files changed, 18 insertions(+), 219 deletions(-) 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/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/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 From b0c9fa4530fbf28970a9fd0f2d24b3ba685a6ac7 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 21 Jun 2019 08:31:51 -0700 Subject: [PATCH 027/201] fix type of loop.sock_connect (#3073) --- stdlib/3/asyncio/base_events.pyi | 4 ++-- stdlib/3/asyncio/events.pyi | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/3/asyncio/base_events.pyi b/stdlib/3/asyncio/base_events.pyi index 2262a67f8b3c..31023abf1db3 100644 --- a/stdlib/3/asyncio/base_events.pyi +++ b/stdlib/3/asyncio/base_events.pyi @@ -1,5 +1,5 @@ import selectors -from socket import socket +from socket import socket, _Address import ssl import sys from typing import Any, Awaitable, Callable, Dict, Generator, List, Optional, Sequence, Tuple, TypeVar, Union, overload @@ -123,7 +123,7 @@ class BaseEventLoop(AbstractEventLoop): @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]: ... + def sock_connect(self, sock: socket, address: _Address) -> Generator[Any, None, None]: ... @coroutine def sock_accept(self, sock: socket) -> Generator[Any, None, Tuple[socket, Any]]: ... # Signal handling. diff --git a/stdlib/3/asyncio/events.pyi b/stdlib/3/asyncio/events.pyi index c81d027efc32..3dbd60944f53 100644 --- a/stdlib/3/asyncio/events.pyi +++ b/stdlib/3/asyncio/events.pyi @@ -1,5 +1,5 @@ import selectors -from socket import socket +from socket import socket, _Address import ssl import sys from typing import Any, Awaitable, Callable, Dict, Generator, List, Optional, Sequence, Tuple, TypeVar, Union, overload @@ -185,7 +185,7 @@ class AbstractEventLoop(metaclass=ABCMeta): 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]: ... + def sock_connect(self, sock: socket, address: _Address) -> Generator[Any, None, None]: ... @abstractmethod @coroutine def sock_accept(self, sock: socket) -> Generator[Any, None, Tuple[socket, Any]]: ... From bdd49d0f3a3469608b7581419b68699ed3350c34 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Sat, 22 Jun 2019 19:18:16 +0200 Subject: [PATCH 028/201] Fix annotation of re.Match 'lastindex' and 'lastgroup' in Python 3 (#3085) Both are None if there were no groups matched. Also 'lastgroup' will be None if the matched group was nameless. The Python 2 versions of these annotations already used Optional. --- stdlib/3/typing.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 43202e017355..d3aee9508aca 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -517,8 +517,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 From e25c0cb128f83f6aced904f4a8ec6be71d5ea878 Mon Sep 17 00:00:00 2001 From: Chad Dombrova Date: Sat, 22 Jun 2019 14:09:51 -0700 Subject: [PATCH 029/201] "key" argument of builtin function sorted should be optional in python 2.7 (#3086) --- stdlib/2/__builtin__.pyi | 2 +- stdlib/2and3/builtins.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index cf1428d86db0..6bc892f47ba7 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -1390,7 +1390,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]: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index cf1428d86db0..6bc892f47ba7 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -1390,7 +1390,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]: ... From 64b12bf7f14019bb86b84751beb4091b13d3da82 Mon Sep 17 00:00:00 2001 From: redshiftzero Date: Sat, 22 Jun 2019 14:15:37 -0700 Subject: [PATCH 030/201] itsdangerous: update JSONWebSignatureSerializer.dumps return type (#3082) On Python 2, a str is returned, however on Python 3 the return type is bytes. --- third_party/2and3/itsdangerous.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/2and3/itsdangerous.pyi b/third_party/2and3/itsdangerous.pyi index 32bbf2bb12be..37a7070518d7 100644 --- a/third_party/2and3/itsdangerous.pyi +++ b/third_party/2and3/itsdangerous.pyi @@ -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]] = ..., From 8131bfc3f6f16db173ce9391b91c7644e0234304 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sun, 23 Jun 2019 23:44:20 -0700 Subject: [PATCH 031/201] Install Black and isort autoformatters (#3069) * Install Black and isort * Add config via pyproject.toml Notably we keep the convention of 130 line length. * Add target python version --- pyproject.toml | 11 +++++++++++ requirements-tests-py3.txt | 2 ++ 2 files changed, 13 insertions(+) create mode 100644 pyproject.toml 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..00054fa1974a 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 +black==19.3b0 flake8==3.6.0 flake8-bugbear==18.8.0 flake8-pyi==18.3.1 +isort==4.3.20 pytype>=2019.5.15 From 7e9e91cb7b281a9d6fff15b8ecde027c7195e257 Mon Sep 17 00:00:00 2001 From: Gordon Ball Date: Wed, 26 Jun 2019 22:21:05 +0200 Subject: [PATCH 032/201] Restore default value to click.echo_via_pager (#3090) --- third_party/2and3/click/termui.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/2and3/click/termui.pyi b/third_party/2and3/click/termui.pyi index 4262e32306bb..1f838eb5787f 100644 --- a/third_party/2and3/click/termui.pyi +++ b/third_party/2and3/click/termui.pyi @@ -62,7 +62,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: ... From 5dc89fe8cfc69a4dd6741181d2a16ac86ddb7786 Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Wed, 26 Jun 2019 20:29:16 -0700 Subject: [PATCH 033/201] Add undocumented methods codecs.utf_16_be_{decode,encode}. (#3091) I found the signatures here: https://github.com/python/cpython/blob/6a16b18224fa98f6d192aa5014affeccc0376eb3/Modules/_codecsmodule.c#L729 https://github.com/google/pytype/issues/348 was opened against pytype about utf_16_be_encode being missing. --- stdlib/2and3/codecs.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stdlib/2and3/codecs.pyi b/stdlib/2and3/codecs.pyi index b99ce9134a6f..47ea963c6920 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 From 32723079339004737dcc05e29740e23cd891c470 Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Fri, 28 Jun 2019 18:28:50 -0700 Subject: [PATCH 034/201] Make dataclasses.Field.metadata non-optional (#3094) If `metadata` is `None` the Field constructor replaces it with an empty mapping object, so this value can never be None. https://github.com/python/cpython/blob/v3.7.3/Lib/dataclasses.py#L243 --- stdlib/3.7/dataclasses.pyi | 2 +- third_party/3/dataclasses.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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 From 47450629c924b0029da376077b2468843f4aec8c Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Mon, 1 Jul 2019 14:03:57 +0200 Subject: [PATCH 035/201] Add TLSVersion & related attributes to SSLContext (#3097) --- stdlib/2and3/ssl.pyi | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/stdlib/2and3/ssl.pyi b/stdlib/2and3/ssl.pyi index 0a198eb9f9c5..c0990d967f6f 100644 --- a/stdlib/2and3/ssl.pyi +++ b/stdlib/2and3/ssl.pyi @@ -211,6 +211,17 @@ class SSLSocket(socket.socket): 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 @@ -257,6 +268,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): From 8b66e08745bbc3cc4920fd50c037b84741a53512 Mon Sep 17 00:00:00 2001 From: Jason Gilholme Date: Mon, 1 Jul 2019 22:05:13 +1000 Subject: [PATCH 036/201] Add Generic Typing to Queue.PriorityQueue and Queue.LifoQueue in python 2 (#3036) --- stdlib/2/Queue.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/2/Queue.pyi b/stdlib/2/Queue.pyi index 11b01ed1c23e..1593eb1c6a67 100644 --- a/stdlib/2/Queue.pyi +++ b/stdlib/2/Queue.pyi @@ -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]): ... From c66699800ed3827f072670a2b63615a6d3f33ea3 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 1 Jul 2019 15:28:41 +0300 Subject: [PATCH 037/201] xml.etree.ElementTree: fix missing None in get(), findtext() return type (#3093) --- stdlib/2and3/xml/etree/ElementTree.pyi | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/stdlib/2and3/xml/etree/ElementTree.pyi b/stdlib/2and3/xml/etree/ElementTree.pyi index d5f64b67a96e..2f2c1a59ecca 100644 --- a/stdlib/2and3/xml/etree/ElementTree.pyi +++ b/stdlib/2and3/xml/etree/ElementTree.pyi @@ -1,6 +1,6 @@ # Stubs for xml.etree.ElementTree -from typing import Any, Callable, Dict, Generator, IO, ItemsView, Iterable, Iterator, KeysView, List, MutableSequence, Optional, overload, Sequence, Text, Tuple, TypeVar, Union +from typing import Any, Callable, Dict, Generator, IO, ItemsView, Iterable, Iterator, KeysView, List, MutableSequence, Optional, overload, Sequence, Text, Tuple, TypeVar, Union, overload import io import sys @@ -53,8 +53,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 +108,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): From e1e5c83795af3313216c937a39a3dd7091b3d6d1 Mon Sep 17 00:00:00 2001 From: Martijn Pieters Date: Mon, 1 Jul 2019 15:47:30 +0100 Subject: [PATCH 038/201] QueueHandler / QueueListener accept SimpleQueue too (#3098) The implementation of `logging.adapters.QueueHandler` and `logging.adapters.QueueListener` works great with `queue.SimpleQueue` too, so update the stub to reflect this. The new queue.SimpleQueue class (introduced in 3.7) is faster but is not a Queue subclass as it doesn't implement task handling (`handle_task()` / `join()`) or queue bounds (raising `queue.Full` / `full()`). The logging handler / listener implementations do not make use of those features however. Related Python bug, asking for an explicit documentation mention: https://bugs.python.org/issue37469 --- stdlib/2and3/logging/handlers.pyi | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/stdlib/2and3/logging/handlers.pyi b/stdlib/2and3/logging/handlers.pyi index c18ddccf568f..00a27c923b54 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,12 +197,19 @@ 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, Queue]) -> None: ... + else: + def __init__(self, queue: Queue) -> None: ... def prepare(self, record: LogRecord) -> Any: ... def enqueue(self, record: LogRecord) -> None: ... class QueueListener: - if sys.version_info >= (3, 5): + if sys.version_info >= (3, 7): + def __init__(self, queue: Union[SimpleQueue, Queue], + *handlers: Handler, + respect_handler_level: bool = ...) -> None: ... + elif sys.version_info >= (3, 5): def __init__(self, queue: Queue, *handlers: Handler, respect_handler_level: bool = ...) -> None: ... else: From 668d050476e6e02332d7d8f8557f368e5bc8bd37 Mon Sep 17 00:00:00 2001 From: Rafi Blecher Date: Tue, 2 Jul 2019 02:56:40 -0700 Subject: [PATCH 039/201] Fix contextlib GeneratorContextManager name for py>=3.2 (#3083) --- stdlib/2and3/contextlib.pyi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stdlib/2and3/contextlib.pyi b/stdlib/2and3/contextlib.pyi index dec1b411d515..7d092096bc0a 100644 --- a/stdlib/2and3/contextlib.pyi +++ b/stdlib/2and3/contextlib.pyi @@ -25,10 +25,12 @@ _ExitFunc = Callable[[Optional[Type[BaseException]], _CM_EF = TypeVar('_CM_EF', ContextManager, _ExitFunc) if sys.version_info >= (3, 2): - class GeneratorContextManager(ContextManager[_T], Generic[_T]): + class _GeneratorContextManager(ContextManager[_T], Generic[_T]): def __call__(self, func: Callable[..., _T]) -> Callable[..., _T]: ... - def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., GeneratorContextManager[_T]]: ... + def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., _GeneratorContextManager[_T]]: ... else: + class GeneratorContextManager(ContextManager[_T], Generic[_T]): + def __call__(self, func: Callable[..., _T]) -> Callable[..., _T]: ... def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., ContextManager[_T]]: ... if sys.version_info >= (3, 7): From 75d9228b02c04a13b46c1d976f32859a88daff0c Mon Sep 17 00:00:00 2001 From: Francis Colas Date: Tue, 2 Jul 2019 13:08:32 +0200 Subject: [PATCH 040/201] PurePath methods accept os.PathLike[str] from 3.6 (#3099) Closes #3095 --- stdlib/3/pathlib.pyi | 15 ++++++++++++--- third_party/2/pathlib2.pyi | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/stdlib/3/pathlib.pyi b/stdlib/3/pathlib.pyi index 42968fa98ec7..fb06c65e0544 100644 --- a/stdlib/3/pathlib.pyi +++ b/stdlib/3/pathlib.pyi @@ -30,7 +30,10 @@ 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: ... + else: + def __truediv__(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 +42,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/pathlib2.pyi b/third_party/2/pathlib2.pyi index 42968fa98ec7..fb06c65e0544 100644 --- a/third_party/2/pathlib2.pyi +++ b/third_party/2/pathlib2.pyi @@ -30,7 +30,10 @@ 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: ... + else: + def __truediv__(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 +42,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]: ... From 3e700224baf0012c4d18d9a147a5cebd548baa01 Mon Sep 17 00:00:00 2001 From: ikelos Date: Wed, 3 Jul 2019 07:49:16 +0100 Subject: [PATCH 041/201] Add in multiprocessing.managers.ValueProxy types (#3100) Fixes #1778 --- stdlib/3/multiprocessing/managers.pyi | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/stdlib/3/multiprocessing/managers.pyi b/stdlib/3/multiprocessing/managers.pyi index a5ec399d74cc..ceabefbd8223 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,6 +17,13 @@ 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: ... @@ -40,7 +47,7 @@ class SyncManager(BaseManager): 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]: ... From 4af283e1aca6fc44a3b0d0b2e8a5d58f1f968cea Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Tue, 2 Jul 2019 23:52:59 -0700 Subject: [PATCH 042/201] Fix HTTPConnection.putrequest parameter names (#3101) --- stdlib/3/http/client.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/http/client.pyi b/stdlib/3/http/client.pyi index 5528b0150865..687ca8ac60a5 100644 --- a/stdlib/3/http/client.pyi +++ b/stdlib/3/http/client.pyi @@ -181,7 +181,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): From 84e6492d7ea579c186f38bacbefea04ec6093e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Savo=20Kova=C4=8Devi=C4=87?= Date: Thu, 4 Jul 2019 21:57:06 +0200 Subject: [PATCH 043/201] Improving Flask stubs (#3003) * Fix flask render_template and render_template_string stubs * Add types for flask view function * Import TracebackType from the right location * Switch to bound typevar in route decorator stub * Change render_template and render_template_string parameters to Text --- third_party/2and3/flask/app.pyi | 44 ++++++++++++++++++++++++-- third_party/2and3/flask/blueprints.pyi | 8 +++-- third_party/2and3/flask/templating.pyi | 9 ++++-- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/third_party/2and3/flask/app.pyi b/third_party/2and3/flask/app.pyi index 5be3d6d5931b..e18fded513d1 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, Response, _WSGICallable] + +_ViewFunc = Union[ + Callable[..., Text], + Callable[..., ByteString], + Callable[..., NoReturn], + Callable[..., Response], + Callable[..., _WSGICallable], + Callable[..., Tuple[_Body, _Status, _Headers]], + Callable[..., Tuple[_Body, _Status]], + Callable[..., Tuple[_Body, _Headers]] +] +_VT = TypeVar('_VT', bound=_ViewFunc) + + class Flask(_PackageBoundObject): request_class: type = ... response_class: type = ... @@ -96,8 +134,8 @@ class Flask(_PackageBoundObject): 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/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: ... From 1436cfdef94802a2d57588f277624a423b27056d Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Thu, 4 Jul 2019 21:58:51 +0200 Subject: [PATCH 044/201] Add types to FileStorage (#3067) --- third_party/2and3/werkzeug/datastructures.pyi | 46 ++++--- third_party/2and3/werkzeug/formparser.pyi | 120 ++++++++++++------ 2 files changed, 109 insertions(+), 57 deletions(-) diff --git a/third_party/2and3/werkzeug/datastructures.pyi b/third_party/2and3/werkzeug/datastructures.pyi index f10665f98cdc..7ee49dda7021 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") @@ -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/formparser.pyi b/third_party/2and3/werkzeug/formparser.pyi index d0e6a739170f..16c91c350ecf 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]: ... From f5c107cacd7c17ef541278bf228ca411fdeaa11b Mon Sep 17 00:00:00 2001 From: Cole Maclean Date: Sun, 7 Jul 2019 22:03:07 -0700 Subject: [PATCH 045/201] BytesGenerator requires BinaryIO (#3106) --- stdlib/3/email/generator.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 = ..., From b43e1d674f0824b0d35d96145b970357d7c9c24a Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Wed, 10 Jul 2019 14:44:27 -0700 Subject: [PATCH 046/201] Use Literal overloads to give better types to subprocess (#3110) This gives better types to `subprocess.check_output` and `subprocess.run` by laboriously overloading using literals. To support `run`, I turned `CompletedProcess` into `_CompletedProcess[T]` with `CompletedProcess = _CompletedProcess[Any]`. I could pretty easily be convinced that it would be better to just make `CompletedProcess` generic, though. I'd like to do the same for Popen but need to make mypy support believing the type of `__new__` in order for that to work. --- stdlib/3/subprocess.pyi | 606 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 589 insertions(+), 17 deletions(-) diff --git a/stdlib/3/subprocess.pyi b/stdlib/3/subprocess.pyi index b2424494d25e..25ac19115e97 100644 --- a/stdlib/3/subprocess.pyi +++ b/stdlib/3/subprocess.pyi @@ -2,19 +2,26 @@ # 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, + overload, +) +from typing_extensions import Literal from types import TracebackType # 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,22 +36,159 @@ else: _CMD = Union[_TXT, Sequence[_PATH]] _ENV = Union[Mapping[bytes, _TXT], Mapping[Text, _TXT]] +_T = TypeVar('_T') + if sys.version_info >= (3, 5): - class CompletedProcess: + class _CompletedProcess(Generic[_T]): # morally: _CMD args: Any returncode: int - # morally: Optional[_TXT] - stdout: Any - stderr: Any + # 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[_TXT] = ..., - stderr: Optional[_TXT] = ...) -> None: ... + stdout: Optional[_T] = ..., + stderr: Optional[_T] = ...) -> None: ... def check_returncode(self) -> None: ... + CompletedProcess = _CompletedProcess[Any] + 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 = ..., @@ -69,9 +213,107 @@ if sys.version_info >= (3, 5): errors: Optional[str] = ..., input: Optional[_TXT] = ..., text: Optional[bool] = ..., - timeout: Optional[float] = ...) -> CompletedProcess: ... + 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 = ..., @@ -94,13 +336,56 @@ if sys.version_info >= (3, 5): encoding: Optional[str] = ..., errors: Optional[str] = ..., input: Optional[_TXT] = ..., - timeout: Optional[float] = ...) -> CompletedProcess: ... + timeout: Optional[float] = ...) -> _CompletedProcess[Any]: ... else: # Nearly same args as Popen.__init__ except for timeout, input, and check + @overload def run(args: _CMD, - timeout: Optional[float] = ..., - input: Optional[_TXT] = ..., + 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 = ..., @@ -116,7 +401,11 @@ if sys.version_info >= (3, 5): creationflags: int = ..., restore_signals: bool = ..., start_new_session: bool = ..., - pass_fds: Any = ...) -> CompletedProcess: ... + pass_fds: Any = ..., + *, + check: bool = ..., + input: Optional[_TXT] = ..., + timeout: Optional[float] = ...) -> _CompletedProcess[Any]: ... # Same args as Popen.__init__ def call(args: _CMD, @@ -160,6 +449,128 @@ def check_call(args: _CMD, if sys.version_info >= (3, 7): # 3.7 added text + @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: 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: 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: 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: 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: float = ..., + input: _TXT = ..., + encoding: None = ..., + errors: None = ..., + text: Literal[None, False] = ..., + ) -> bytes: ... + @overload def check_output(args: _CMD, bufsize: int = ..., executable: _PATH = ..., @@ -185,6 +596,99 @@ 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 = ..., + 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: 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: 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: 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: float = ..., + input: _TXT = ..., + encoding: None = ..., + errors: None = ..., + ) -> bytes: ... + @overload def check_output(args: _CMD, bufsize: int = ..., executable: _PATH = ..., @@ -208,6 +712,48 @@ elif sys.version_info >= (3, 6): 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: 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: float = ..., + input: _TXT = ..., + ) -> bytes: ... + @overload def check_output(args: _CMD, bufsize: int = ..., executable: _PATH = ..., @@ -264,13 +810,39 @@ class CalledProcessError(Exception): class Popen: args: _CMD + # We would like to give better types to these fields but currently + # have no way of overloading a constructor... stdin: IO[Any] stdout: IO[Any] stderr: IO[Any] pid = 0 returncode = 0 - if sys.version_info >= (3, 6): + if sys.version_info >= (3, 7): + # text is added in 3.7 + 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 = ..., + *, + text: Optional[bool] = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ...) -> None: ... + elif sys.version_info >= (3, 6): def __init__(self, args: _CMD, bufsize: int = ..., From 4ae4714e00b167d4280b379cab66ea6f15b0c0d3 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 11 Jul 2019 11:43:37 +0300 Subject: [PATCH 047/201] sys: refine the return type of sys.exc_info() (#3111) --- stdlib/2/sys.pyi | 2 +- stdlib/3/sys.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/3/sys.pyi b/stdlib/3/sys.pyi index 3f856bbc9c76..911ff4fe9344 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 From 34b47101dd5e57f6ed1e9a47fdb3e9080cf46c85 Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Thu, 11 Jul 2019 12:13:32 -0700 Subject: [PATCH 048/201] Slice attributes can be of any type. (#3024) --- stdlib/2/__builtin__.pyi | 10 +++++----- stdlib/2and3/builtins.pyi | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 6bc892f47ba7..99b9fbfaa050 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -841,13 +841,13 @@ 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: ... def indices(self, len: int) -> Tuple[int, int, int]: ... class tuple(Sequence[_T_co], Generic[_T_co]): diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 6bc892f47ba7..99b9fbfaa050 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -841,13 +841,13 @@ 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: ... def indices(self, len: int) -> Tuple[int, int, int]: ... class tuple(Sequence[_T_co], Generic[_T_co]): From 40124b5f4c45bc05f3a448dd04dbdd455ec3ac89 Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Thu, 11 Jul 2019 12:47:46 -0700 Subject: [PATCH 049/201] Update required pytype version to one that supports `async def`. (#3112) --- requirements-tests-py3.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-tests-py3.txt b/requirements-tests-py3.txt index 00054fa1974a..06711ec5c32f 100644 --- a/requirements-tests-py3.txt +++ b/requirements-tests-py3.txt @@ -5,4 +5,4 @@ flake8==3.6.0 flake8-bugbear==18.8.0 flake8-pyi==18.3.1 isort==4.3.20 -pytype>=2019.5.15 +pytype>=2019.7.11 From 2a57ce2cecc44ff4054742f6327f151c9ebae8f5 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 13 Jul 2019 07:50:13 -0700 Subject: [PATCH 050/201] Add curses.COLORS and curses.COLOR_PAIRS (#3115) --- stdlib/2and3/curses/__init__.pyi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stdlib/2and3/curses/__init__.pyi b/stdlib/2and3/curses/__init__.pyi index c327c7803931..e6c00da4372b 100644 --- a/stdlib/2and3/curses/__init__.pyi +++ b/stdlib/2and3/curses/__init__.pyi @@ -3,7 +3,12 @@ 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: ... From f76b7b273b732f587a1f05b388dd35091b87523e Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 13 Jul 2019 08:01:10 -0700 Subject: [PATCH 051/201] Re-export _curses._CursesWindow from curses (#3117) --- stdlib/2and3/curses/__init__.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/2and3/curses/__init__.pyi b/stdlib/2and3/curses/__init__.pyi index e6c00da4372b..8bd806b476b4 100644 --- a/stdlib/2and3/curses/__init__.pyi +++ b/stdlib/2and3/curses/__init__.pyi @@ -1,4 +1,5 @@ from _curses import * # noqa: F403 +from _curses import _CursesWindow as _CursesWindow from typing import TypeVar, Callable, Any _T = TypeVar('_T') From e2ec5d0525b89a889a714c7344eb5c9ffd7347f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E8=91=89?= Date: Mon, 15 Jul 2019 15:11:45 +0800 Subject: [PATCH 052/201] Make SyntaxError.text be optional (#3119) Closes #3118 --- stdlib/2/__builtin__.pyi | 2 +- stdlib/2and3/builtins.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 99b9fbfaa050..9e822fbe6640 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -1523,7 +1523,7 @@ class SyntaxError(_StandardError): msg: str lineno: int offset: Optional[int] - text: str + text: Optional[str] filename: str class SystemError(_StandardError): ... class TypeError(_StandardError): ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 99b9fbfaa050..9e822fbe6640 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -1523,7 +1523,7 @@ class SyntaxError(_StandardError): msg: str lineno: int offset: Optional[int] - text: str + text: Optional[str] filename: str class SystemError(_StandardError): ... class TypeError(_StandardError): ... From 3ad3ed82c75b4fb82f71f5500b50f18a98f12f49 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Tue, 16 Jul 2019 15:41:33 -0700 Subject: [PATCH 053/201] Overload the constructor of subprocess.Popen (#3113) This takes advantage of a recent mypy change to respect the return type of `__new__`. Using that it does the same tedious overloads as `run` and `check_output`. --- stdlib/3/subprocess.pyi | 423 +++++++++++++++++++++++++++++++--------- 1 file changed, 335 insertions(+), 88 deletions(-) diff --git a/stdlib/3/subprocess.pyi b/stdlib/3/subprocess.pyi index 25ac19115e97..fa7d10236487 100644 --- a/stdlib/3/subprocess.pyi +++ b/stdlib/3/subprocess.pyi @@ -4,7 +4,7 @@ import sys from typing import ( Sequence, Any, Mapping, Callable, Tuple, IO, Optional, Union, List, Type, Text, - Generic, TypeVar, + Generic, TypeVar, AnyStr, overload, ) from typing_extensions import Literal @@ -39,7 +39,7 @@ _ENV = Union[Mapping[bytes, _TXT], Mapping[Text, _TXT]] _T = TypeVar('_T') if sys.version_info >= (3, 5): - class _CompletedProcess(Generic[_T]): + class CompletedProcess(Generic[_T]): # morally: _CMD args: Any returncode: int @@ -53,8 +53,6 @@ if sys.version_info >= (3, 5): stderr: Optional[_T] = ...) -> None: ... def check_returncode(self) -> None: ... - CompletedProcess = _CompletedProcess[Any] - if sys.version_info >= (3, 7): # Nearly the same args as for 3.6, except for capture_output and text @overload @@ -82,7 +80,7 @@ if sys.version_info >= (3, 5): errors: Optional[str] = ..., input: Optional[str] = ..., text: Literal[True], - timeout: Optional[float] = ...) -> _CompletedProcess[str]: ... + timeout: Optional[float] = ...) -> CompletedProcess[str]: ... @overload def run(args: _CMD, bufsize: int = ..., @@ -108,7 +106,7 @@ if sys.version_info >= (3, 5): errors: Optional[str] = ..., input: Optional[str] = ..., text: Optional[bool] = ..., - timeout: Optional[float] = ...) -> _CompletedProcess[str]: ... + timeout: Optional[float] = ...) -> CompletedProcess[str]: ... @overload def run(args: _CMD, bufsize: int = ..., @@ -134,7 +132,7 @@ if sys.version_info >= (3, 5): errors: str, input: Optional[str] = ..., text: Optional[bool] = ..., - timeout: Optional[float] = ...) -> _CompletedProcess[str]: ... + timeout: Optional[float] = ...) -> CompletedProcess[str]: ... @overload def run(args: _CMD, bufsize: int = ..., @@ -161,7 +159,7 @@ if sys.version_info >= (3, 5): errors: Optional[str] = ..., input: Optional[str] = ..., text: Optional[bool] = ..., - timeout: Optional[float] = ...) -> _CompletedProcess[str]: ... + timeout: Optional[float] = ...) -> CompletedProcess[str]: ... @overload def run(args: _CMD, bufsize: int = ..., @@ -187,7 +185,7 @@ if sys.version_info >= (3, 5): errors: None = ..., input: Optional[bytes] = ..., text: Literal[None, False] = ..., - timeout: Optional[float] = ...) -> _CompletedProcess[bytes]: ... + timeout: Optional[float] = ...) -> CompletedProcess[bytes]: ... @overload def run(args: _CMD, bufsize: int = ..., @@ -213,7 +211,7 @@ if sys.version_info >= (3, 5): errors: Optional[str] = ..., input: Optional[_TXT] = ..., text: Optional[bool] = ..., - timeout: Optional[float] = ...) -> _CompletedProcess[Any]: ... + timeout: Optional[float] = ...) -> CompletedProcess[Any]: ... elif sys.version_info >= (3, 6): # Nearly same args as Popen.__init__ except for timeout, input, and check @overload @@ -239,7 +237,7 @@ if sys.version_info >= (3, 5): encoding: str, errors: Optional[str] = ..., input: Optional[str] = ..., - timeout: Optional[float] = ...) -> _CompletedProcess[str]: ... + timeout: Optional[float] = ...) -> CompletedProcess[str]: ... @overload def run(args: _CMD, bufsize: int = ..., @@ -263,7 +261,7 @@ if sys.version_info >= (3, 5): encoding: Optional[str] = ..., errors: str, input: Optional[str] = ..., - timeout: Optional[float] = ...) -> _CompletedProcess[str]: ... + timeout: Optional[float] = ...) -> CompletedProcess[str]: ... @overload def run(args: _CMD, bufsize: int = ..., @@ -288,7 +286,7 @@ if sys.version_info >= (3, 5): encoding: Optional[str] = ..., errors: Optional[str] = ..., input: Optional[str] = ..., - timeout: Optional[float] = ...) -> _CompletedProcess[str]: ... + timeout: Optional[float] = ...) -> CompletedProcess[str]: ... @overload def run(args: _CMD, bufsize: int = ..., @@ -312,7 +310,7 @@ if sys.version_info >= (3, 5): encoding: None = ..., errors: None = ..., input: Optional[bytes] = ..., - timeout: Optional[float] = ...) -> _CompletedProcess[bytes]: ... + timeout: Optional[float] = ...) -> CompletedProcess[bytes]: ... @overload def run(args: _CMD, bufsize: int = ..., @@ -336,7 +334,7 @@ if sys.version_info >= (3, 5): encoding: Optional[str] = ..., errors: Optional[str] = ..., input: Optional[_TXT] = ..., - timeout: Optional[float] = ...) -> _CompletedProcess[Any]: ... + timeout: Optional[float] = ...) -> CompletedProcess[Any]: ... else: # Nearly same args as Popen.__init__ except for timeout, input, and check @overload @@ -361,7 +359,7 @@ if sys.version_info >= (3, 5): # where the *real* keyword only args start check: bool = ..., input: Optional[str] = ..., - timeout: Optional[float] = ...) -> _CompletedProcess[str]: ... + timeout: Optional[float] = ...) -> CompletedProcess[str]: ... @overload def run(args: _CMD, bufsize: int = ..., @@ -383,7 +381,7 @@ if sys.version_info >= (3, 5): *, check: bool = ..., input: Optional[bytes] = ..., - timeout: Optional[float] = ...) -> _CompletedProcess[bytes]: ... + timeout: Optional[float] = ...) -> CompletedProcess[bytes]: ... @overload def run(args: _CMD, bufsize: int = ..., @@ -405,7 +403,7 @@ if sys.version_info >= (3, 5): *, check: bool = ..., input: Optional[_TXT] = ..., - timeout: Optional[float] = ...) -> _CompletedProcess[Any]: ... + timeout: Optional[float] = ...) -> CompletedProcess[Any]: ... # Same args as Popen.__init__ def call(args: _CMD, @@ -808,90 +806,339 @@ class CalledProcessError(Exception): output: Optional[_TXT] = ..., stderr: Optional[_TXT] = ...) -> None: ... -class Popen: +class Popen(Generic[AnyStr]): args: _CMD - # We would like to give better types to these fields but currently - # have no way of overloading a constructor... - stdin: IO[Any] - stdout: IO[Any] - stderr: IO[Any] + stdin: IO[AnyStr] + stdout: IO[AnyStr] + stderr: IO[AnyStr] pid = 0 returncode = 0 + # 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 - 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 = ..., - *, - text: Optional[bool] = ..., - encoding: Optional[str] = ..., - errors: Optional[str] = ...) -> 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: 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): - 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: ... + @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: ... From 8e89faa90ff04a3b7e7085d7ff2530cfe8735765 Mon Sep 17 00:00:00 2001 From: William Ayd Date: Wed, 17 Jul 2019 01:08:46 -0700 Subject: [PATCH 054/201] Added Optional (#3125) Fixes #3124 --- stdlib/3/io.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/io.pyi b/stdlib/3/io.pyi index 903fab2f6f93..e6489028151f 100644 --- a/stdlib/3/io.pyi +++ b/stdlib/3/io.pyi @@ -159,7 +159,7 @@ class TextIOWrapper(TextIO): def __init__( self, buffer: IO[bytes], - encoding: str = ..., + encoding: Optional[str] = ..., errors: Optional[str] = ..., newline: Optional[str] = ..., line_buffering: bool = ..., From 508f992730ce74c24348040efb96b44863fdd53e Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Wed, 17 Jul 2019 23:25:22 +0100 Subject: [PATCH 055/201] Add __eq__ to protobuf containers (#3126) See https://github.com/protocolbuffers/protobuf/blob/master/python/google/protobuf/internal/containers.py. Without these `mypy --strict-equality` causes false positives with protobufs. --- third_party/2and3/google/protobuf/internal/containers.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/third_party/2and3/google/protobuf/internal/containers.pyi b/third_party/2and3/google/protobuf/internal/containers.pyi index 33e603c93e58..1a2defc3c04d 100644 --- a/third_party/2and3/google/protobuf/internal/containers.pyi +++ b/third_party/2and3/google/protobuf/internal/containers.pyi @@ -35,6 +35,7 @@ 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: ... @@ -46,6 +47,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): ... From 09d1055cd32acfd1f6ed88552bbc6c8e5c0cc1b3 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Thu, 18 Jul 2019 17:02:12 +0200 Subject: [PATCH 056/201] Remove mypy new analyzer tests (#3128) Now that the new analyzer is the default, this does exactly the same as the normal mypy self test. --- .travis.yml | 8 -------- tests/mypy_test.py | 3 --- 2 files changed, 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 011b5212123c..99a3c65d4a2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,16 +13,8 @@ matrix: env: - TEST_CMD="./tests/mypy_test.py" - INSTALL="mypy" - - name: "mypy new analyzer" - env: - - TEST_CMD="./tests/mypy_test.py -a" - - INSTALL="mypy" - 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" - name: "check file consistency" env: TEST_CMD="./tests/check_consistent.py" - name: "flake8" diff --git a/tests/mypy_test.py b/tests/mypy_test.py index 7ac6f077b08f..d4ffca111296 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])") @@ -133,8 +132,6 @@ 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') if args.warn_unused_ignores: flags.append('--warn-unused-ignores') sys.argv = ['mypy'] + flags + files From 40215d1fa3ef33a31fe68624472c10dd62350f18 Mon Sep 17 00:00:00 2001 From: Yannack Date: Thu, 18 Jul 2019 15:38:28 -0400 Subject: [PATCH 057/201] Fix the definition of nsmallest() in stdlib/2 and 2and3/heapq.pyi (#3114) Missing support of the optional "key" kwarg in nsmallest. Also fixed nlargest syntax for 2and3 which was also missing. Use a protocol for heapq.py --- stdlib/2/heapq.pyi | 10 +++++++--- stdlib/2and3/_heapq.pyi | 8 +++++--- 2 files changed, 12 insertions(+), 6 deletions(-) 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/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]: ... From dad16f2d43de8d58a63d44204f942589b42744e7 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 19 Jul 2019 01:50:28 +0200 Subject: [PATCH 058/201] Update socket exceptions (#3127) * error is an alias for OSError in Python 3 * herror and gaierror can be constructed without arguments (tested in Python 2.7 and 3.7) * timeout uses the same arguments as herror and gaierror --- stdlib/2and3/socket.pyi | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/stdlib/2and3/socket.pyi b/stdlib/2and3/socket.pyi index 4089b225c0e7..36da84951145 100644 --- a/stdlib/2and3/socket.pyi +++ b/stdlib/2and3/socket.pyi @@ -481,17 +481,19 @@ else: # ----- 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, From 90c2c2296119e55454831e5197537f7d22b10ef1 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Fri, 19 Jul 2019 10:56:59 -0700 Subject: [PATCH 059/201] Make python 2 subprocess consistent with python 3 (#3132) --- stdlib/2/subprocess.pyi | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/stdlib/2/subprocess.pyi b/stdlib/2/subprocess.pyi index b60e89e677ac..3a76f509defd 100644 --- a/stdlib/2/subprocess.pyi +++ b/stdlib/2/subprocess.pyi @@ -2,7 +2,12 @@ # 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, +) + +# This is a dummy type variable used to make Popen generic like it is in python 3 +_T = TypeVar('_T', bound=bytes) _FILE = Union[None, int, IO[Any]] _TXT = Union[bytes, Text] @@ -63,17 +68,17 @@ 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]] +class Popen(Generic[_T]): + stdin: Optional[IO[bytes]] + stdout: Optional[IO[bytes]] + stderr: Optional[IO[bytes]] pid = 0 returncode = 0 @@ -96,7 +101,7 @@ class Popen: 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: ... From 4072ad82fbb63b3d8e77d99105d2e22fb8de546e Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Fri, 19 Jul 2019 14:17:32 -0700 Subject: [PATCH 060/201] Fix python 2 subprocess.Popen to produce Popen[bytes] (#3133) Otherwise this causes a lot of spurious errors. --- stdlib/2/subprocess.pyi | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/stdlib/2/subprocess.pyi b/stdlib/2/subprocess.pyi index 3a76f509defd..0c693a985ffd 100644 --- a/stdlib/2/subprocess.pyi +++ b/stdlib/2/subprocess.pyi @@ -6,9 +6,6 @@ from typing import ( Sequence, Any, Mapping, Callable, Tuple, IO, Union, Optional, List, Text, TypeVar, Generic, ) -# This is a dummy type variable used to make Popen generic like it is in python 3 -_T = TypeVar('_T', bound=bytes) - _FILE = Union[None, int, IO[Any]] _TXT = Union[bytes, Text] _CMD = Union[_TXT, Sequence[_TXT]] @@ -75,6 +72,9 @@ class CalledProcessError(Exception): cmd: _CMD, output: Optional[bytes] = ...) -> None: ... +# 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]] @@ -82,21 +82,21 @@ class Popen(Generic[_T]): 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__(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 = ...) -> Popen[bytes]: ... def poll(self) -> int: ... def wait(self) -> int: ... From 9379cedfa787a2ee608ec713be414a464f9cb771 Mon Sep 17 00:00:00 2001 From: Naman <1977419+metalogical@users.noreply.github.com> Date: Fri, 19 Jul 2019 22:31:32 -0700 Subject: [PATCH 061/201] remove itertools.accumulate from Python 2 stubs (#3135) --- stdlib/2/itertools.pyi | 2 -- 1 file changed, 2 deletions(-) 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: ... From 9dcdc7d481d37685714bdd8f5c899c12db4225ce Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 21 Jul 2019 01:04:25 +0200 Subject: [PATCH 062/201] faulthandler.dump_traceback_later: timeout can be float (#3134) --- stdlib/3/faulthandler.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/faulthandler.pyi b/stdlib/3/faulthandler.pyi index 1a87c9cf9e8c..2dfce7714d53 100644 --- a/stdlib/3/faulthandler.pyi +++ b/stdlib/3/faulthandler.pyi @@ -15,7 +15,7 @@ else: 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": From 67d091db15602c43ff1c58da09bafa9ae6d7a4c6 Mon Sep 17 00:00:00 2001 From: Nipunn Koorapati Date: Mon, 22 Jul 2019 00:00:22 -0700 Subject: [PATCH 063/201] Update google RepeatedCompositeFieldContainer (#3136) --- third_party/2and3/google/protobuf/internal/containers.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/third_party/2and3/google/protobuf/internal/containers.pyi b/third_party/2and3/google/protobuf/internal/containers.pyi index 1a2defc3c04d..06efb544d560 100644 --- a/third_party/2and3/google/protobuf/internal/containers.pyi +++ b/third_party/2and3/google/protobuf/internal/containers.pyi @@ -40,6 +40,8 @@ class RepeatedScalarFieldContainer(BaseContainer[_T]): 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: ... From 8e0d288ea49a34f9bd21b1598ec487414a339a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Tue, 23 Jul 2019 23:59:57 +0300 Subject: [PATCH 064/201] json: require a JSONDecoder/JSONEncoder in cls (#3138) --- stdlib/2/json.pyi | 10 +++++----- stdlib/3/json/__init__.pyi | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/stdlib/2/json.pyi b/stdlib/2/json.pyi index 9cc151b27f34..84ed8b9c3fae 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,7 +35,7 @@ def dump(obj: Any, def loads(s: Union[Text, bytes], encoding: Any = ..., - cls: Any = ..., + cls: Optional[Type[JSONDecoder]] = ..., object_hook: Optional[Callable[[Dict], Any]] = ..., parse_float: Optional[Callable[[str], Any]] = ..., parse_int: Optional[Callable[[str], Any]] = ..., @@ -48,7 +48,7 @@ class _Reader(Protocol): def load(fp: _Reader, encoding: Optional[str] = ..., - cls: Any = ..., + cls: Optional[Type[JSONDecoder]] = ..., object_hook: Optional[Callable[[Dict], Any]] = ..., parse_float: Optional[Callable[[str], Any]] = ..., parse_int: Optional[Callable[[str], Any]] = ..., diff --git a/stdlib/3/json/__init__.pyi b/stdlib/3/json/__init__.pyi index 620b239b46c8..cf42c36c72df 100644 --- a/stdlib/3/json/__init__.pyi +++ b/stdlib/3/json/__init__.pyi @@ -1,5 +1,5 @@ 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 @@ -11,7 +11,7 @@ def dumps(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]] = ..., @@ -24,7 +24,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,7 +37,7 @@ else: _LoadsString = str def loads(s: _LoadsString, encoding: Any = ..., # ignored and deprecated - cls: Any = ..., + cls: Optional[Type[JSONDecoder]] = ..., object_hook: Optional[Callable[[Dict], Any]] = ..., parse_float: Optional[Callable[[str], Any]] = ..., parse_int: Optional[Callable[[str], Any]] = ..., @@ -49,7 +49,7 @@ class _Reader(Protocol): def read(self) -> _LoadsString: ... def load(fp: _Reader, - cls: Any = ..., + cls: Optional[Type[JSONDecoder]] = ..., object_hook: Optional[Callable[[Dict], Any]] = ..., parse_float: Optional[Callable[[str], Any]] = ..., parse_int: Optional[Callable[[str], Any]] = ..., From 322be1b9e7542f316a23d097015677cc19112b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 24 Jul 2019 00:02:19 +0300 Subject: [PATCH 065/201] Upgrade flake8* and isort versions (#3141) --- requirements-tests-py3.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements-tests-py3.txt b/requirements-tests-py3.txt index 06711ec5c32f..f5e47a52bf5f 100644 --- a/requirements-tests-py3.txt +++ b/requirements-tests-py3.txt @@ -1,8 +1,8 @@ git+https://github.com/python/mypy.git@master typed-ast>=1.0.4 black==19.3b0 -flake8==3.6.0 -flake8-bugbear==18.8.0 -flake8-pyi==18.3.1 -isort==4.3.20 +flake8==3.7.8 +flake8-bugbear==19.3.0 +flake8-pyi==19.3.0 +isort==4.3.21 pytype>=2019.7.11 From 8794e40d41d0365e2d6d67980e076d95becd4434 Mon Sep 17 00:00:00 2001 From: Zsolt Dollenstein Date: Wed, 24 Jul 2019 13:10:51 +0100 Subject: [PATCH 066/201] Fix ast.Constant availability (#3142) --- stdlib/3/_ast.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 From 0177dedc423f8835d46e5053e0b47faf165d1e39 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 24 Jul 2019 17:51:55 +0200 Subject: [PATCH 067/201] Add werkzeug.middleware (#3103) HTTPConnection.timeout can be a float --- stdlib/3/http/client.pyi | 17 ++--- stdlib/3/urllib/request.pyi | 4 +- third_party/2and3/werkzeug/contrib/fixers.pyi | 55 +++++++-------- third_party/2and3/werkzeug/contrib/lint.pyi | 44 +----------- .../2and3/werkzeug/contrib/profiler.pyi | 21 +++--- .../2and3/werkzeug/middleware/__init__.pyi | 0 .../2and3/werkzeug/middleware/dispatcher.pyi | 8 +++ .../2and3/werkzeug/middleware/http_proxy.pyi | 18 +++++ .../2and3/werkzeug/middleware/lint.pyi | 67 +++++++++++++++++++ .../2and3/werkzeug/middleware/profiler.pyi | 14 ++++ .../2and3/werkzeug/middleware/proxy_fix.pyi | 23 +++++++ .../2and3/werkzeug/middleware/shared_data.pyi | 29 ++++++++ third_party/2and3/werkzeug/wsgi.pyi | 25 ++----- 13 files changed, 211 insertions(+), 114 deletions(-) create mode 100644 third_party/2and3/werkzeug/middleware/__init__.pyi create mode 100644 third_party/2and3/werkzeug/middleware/dispatcher.pyi create mode 100644 third_party/2and3/werkzeug/middleware/http_proxy.pyi create mode 100644 third_party/2and3/werkzeug/middleware/lint.pyi create mode 100644 third_party/2and3/werkzeug/middleware/profiler.pyi create mode 100644 third_party/2and3/werkzeug/middleware/proxy_fix.pyi create mode 100644 third_party/2and3/werkzeug/middleware/shared_data.pyi diff --git a/stdlib/3/http/client.pyi b/stdlib/3/http/client.pyi index 687ca8ac60a5..2b173993e143 100644 --- a/stdlib/3/http/client.pyi +++ b/stdlib/3/http/client.pyi @@ -138,32 +138,33 @@ else: # 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): @@ -196,7 +197,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: ... diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index e096ef4ef7f8..cac03ae1a61a 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 @@ -162,7 +162,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: ... 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/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..7ad4901f8a06 --- /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], + ) -> 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/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): ... From 9a7b286c66bbaba510f50085825c0132123386ec Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Wed, 24 Jul 2019 22:46:23 +0300 Subject: [PATCH 068/201] warnings: ignore the type of category when message is a Warning (#3121) --- stdlib/2and3/warnings.pyi | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/stdlib/2and3/warnings.pyi b/stdlib/2and3/warnings.pyi index a44e43e0162d..4d7419edbf90 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: ... From bf50612d767ef4e83466b39716591a1158b751e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 24 Jul 2019 23:05:02 +0300 Subject: [PATCH 069/201] inspect: get{doc,comments,module,sourcefile} can return None (#3137) --- stdlib/2/inspect.pyi | 8 ++++---- stdlib/3/inspect.pyi | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/stdlib/2/inspect.pyi b/stdlib/2/inspect.pyi index 8bc2eacb114f..654fa07734e0 100644 --- a/stdlib/2/inspect.pyi +++ b/stdlib/2/inspect.pyi @@ -55,11 +55,11 @@ def ismemberdescriptor(object: object) -> bool: ... def findsource(object: object) -> Tuple[List[str], int]: ... def getabsfile(object: object) -> str: ... def getblock(lines: Sequence[str]) -> Sequence[str]: ... -def getdoc(object: object) -> str: ... -def getcomments(object: object) -> str: ... +def getdoc(object: object) -> Optional[str]: ... +def getcomments(object: object) -> Optional[str]: ... def getfile(object: object) -> str: ... -def getmodule(object: object) -> ModuleType: ... -def getsourcefile(object: object) -> str: ... +def getmodule(object: object) -> Optional[ModuleType]: ... +def getsourcefile(object: object) -> Optional[str]: ... # TODO restrict to "module, class, method, function, traceback, frame, # or code object" def getsourcelines(object: object) -> Tuple[List[str], int]: ... diff --git a/stdlib/3/inspect.pyi b/stdlib/3/inspect.pyi index 61737158e0e4..320200c44d4e 100644 --- a/stdlib/3/inspect.pyi +++ b/stdlib/3/inspect.pyi @@ -80,11 +80,11 @@ def ismemberdescriptor(object: object) -> bool: ... def findsource(object: object) -> Tuple[List[str], int]: ... def getabsfile(object: object) -> str: ... def getblock(lines: Sequence[str]) -> Sequence[str]: ... -def getdoc(object: object) -> str: ... -def getcomments(object: object) -> str: ... +def getdoc(object: object) -> Optional[str]: ... +def getcomments(object: object) -> Optional[str]: ... def getfile(object: object) -> str: ... -def getmodule(object: object) -> ModuleType: ... -def getsourcefile(object: object) -> str: ... +def getmodule(object: object) -> Optional[ModuleType]: ... +def getsourcefile(object: object) -> Optional[str]: ... # TODO restrict to "module, class, method, function, traceback, frame, # or code object" def getsourcelines(object: object) -> Tuple[List[str], int]: ... From b3f7be523a398036bcd533bf69db3750b01292f0 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Wed, 24 Jul 2019 13:20:15 -0700 Subject: [PATCH 070/201] Fix __call__ type for GeneratorContextManager (#3143) --- stdlib/2and3/contextlib.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/2and3/contextlib.pyi b/stdlib/2and3/contextlib.pyi index 7d092096bc0a..4aa07471f842 100644 --- a/stdlib/2and3/contextlib.pyi +++ b/stdlib/2and3/contextlib.pyi @@ -18,6 +18,7 @@ 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], @@ -26,11 +27,11 @@ _CM_EF = TypeVar('_CM_EF', ContextManager, _ExitFunc) if sys.version_info >= (3, 2): class _GeneratorContextManager(ContextManager[_T], Generic[_T]): - def __call__(self, func: Callable[..., _T]) -> Callable[..., _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: Callable[..., _T]) -> Callable[..., _T]: ... + def __call__(self, func: _F) -> _F: ... def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., ContextManager[_T]]: ... if sys.version_info >= (3, 7): From c9f95302249445a4256250a544ac692eb1211598 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 25 Jul 2019 10:31:12 +0300 Subject: [PATCH 071/201] xml.etree.ElementTree: use literal type for a more precise return value for tostring() (#3120) --- stdlib/2and3/xml/etree/ElementTree.pyi | 30 +++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/stdlib/2and3/xml/etree/ElementTree.pyi b/stdlib/2and3/xml/etree/ElementTree.pyi index 2f2c1a59ecca..ebd4ae122d32 100644 --- a/stdlib/2and3/xml/etree/ElementTree.pyi +++ b/stdlib/2and3/xml/etree/ElementTree.pyi @@ -1,6 +1,7 @@ # Stubs for xml.etree.ElementTree -from typing import Any, Callable, Dict, Generator, IO, ItemsView, Iterable, Iterator, KeysView, List, MutableSequence, Optional, overload, Sequence, Text, Tuple, TypeVar, Union, overload +from typing import Any, Callable, Dict, Generator, IO, ItemsView, Iterable, Iterator, KeysView, List, MutableSequence, Optional, overload, Sequence, Text, Tuple, TypeVar, Union +from typing_extensions import Literal import io import sys @@ -26,20 +27,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 @@ -121,12 +117,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]]: ... From 32ee49c79cff3d08b468daa86e3d156512a32577 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Thu, 25 Jul 2019 11:26:39 +0200 Subject: [PATCH 072/201] Add zipfile.ZipFile.filename (#3104) --- stdlib/2and3/zipfile.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/2and3/zipfile.pyi b/stdlib/2and3/zipfile.pyi index a06d3fd98928..5b940a154c9d 100644 --- a/stdlib/2and3/zipfile.pyi +++ b/stdlib/2and3/zipfile.pyi @@ -24,6 +24,7 @@ error = BadZipfile class LargeZipFile(Exception): ... class ZipFile: + filename: Optional[Text] debug: int comment: bytes filelist: List[ZipInfo] From b20e5b6c144eb858ceb7b9571909809a35a33cde Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Thu, 25 Jul 2019 16:43:52 +0200 Subject: [PATCH 073/201] Travis: run mypy with Python 3.8 as well (#3146) This runs mypy both with Python 3.7 and 3.8. In Python 3.8, mypy switched from using typed-ast to using Python's built-in ast. This patch ensures that both are tested. --- .travis.yml | 9 +++++++-- tests/mypy_test.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 99a3c65d4a2c..2d96621b8e9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -dist: xenial +dist: bionic language: python python: 3.7 @@ -9,7 +9,12 @@ matrix: env: - TEST_CMD="./tests/pytype_test.py" - INSTALL="test" - - name: "mypy" + - name: "mypy (typed-ast)" + env: + - TEST_CMD="./tests/mypy_test.py" + - INSTALL="mypy" + - name: "mypy (ast)" + python: 3.8-dev env: - TEST_CMD="./tests/mypy_test.py" - INSTALL="mypy" diff --git a/tests/mypy_test.py b/tests/mypy_test.py index d4ffca111296..2d911910932f 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -88,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), (3, 4), (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)] From e9d1f8659178b94180b8400221237c872905aece Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Thu, 25 Jul 2019 17:57:14 +0300 Subject: [PATCH 074/201] gettext stubs fixed (#3130) --- stdlib/3/gettext.pyi | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/stdlib/3/gettext.pyi b/stdlib/3/gettext.pyi index eeb9b09768f9..7697404fb273 100644 --- a/stdlib/3/gettext.pyi +++ b/stdlib/3/gettext.pyi @@ -1,9 +1,11 @@ # Stubs for gettext (Python 3.4) -from typing import Any, IO, List, Optional, Union, Callable +from typing import overload, Any, Container, IO, Iterable, Optional, Type, TypeVar +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 +14,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: ... From df8ecf5a6728608a32d7262936b8dbf6c83e11f8 Mon Sep 17 00:00:00 2001 From: Connor Brinton Date: Thu, 25 Jul 2019 15:29:55 -0400 Subject: [PATCH 075/201] Fix incorrectly named parameters in logging module (#3148) --- stdlib/2and3/logging/__init__.pyi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stdlib/2and3/logging/__init__.pyi b/stdlib/2and3/logging/__init__.pyi index d736b0838230..bf62b466f257 100644 --- a/stdlib/2and3/logging/__init__.pyi +++ b/stdlib/2and3/logging/__init__.pyi @@ -51,7 +51,7 @@ class Logger(Filterer): 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 isEnabledFor(self, level: int) -> bool: ... def getEffectiveLevel(self) -> int: ... def getChild(self, suffix: str) -> Logger: ... if sys.version_info >= (3,): @@ -115,7 +115,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 +123,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 +151,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: Union[int, str]) -> 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: ... From c356316c6f74e32eac52d3263e992af65e2b0ab9 Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Thu, 25 Jul 2019 19:43:33 -0700 Subject: [PATCH 076/201] Use pytype.config.Options.create() for prettier code. (#3151) This is a small cosmetic change. I want to encourage use of the nicer-lookng pytype.config.Options.create() rather than direct construction of the command-line args, so I'm changing over all occurrences of the latter that I can find. --- tests/pytype_test.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/pytype_test.py b/tests/pytype_test.py index c67e85941931..d4f422827e2d 100755 --- a/tests/pytype_test.py +++ b/tests/pytype_test.py @@ -85,15 +85,12 @@ def load_blacklist(typeshed_location: str) -> List[str]: def run_pytype(*, filename: str, python_version: str, python_exe: str, typeshed_location: str) -> Optional[str]: """Runs pytype, returning the stderr if any.""" - options = pytype_config.Options( - [ - "--module-name={}".format(_get_module_name(filename)), - "--parse-pyi", - "-V {}".format(python_version), - "--python_exe={}".format(python_exe), - filename, - ] - ) + 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: From c8e7d98c1ffcbb4707f49cd523897aa8283e000e Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 26 Jul 2019 17:40:22 +0300 Subject: [PATCH 077/201] Allow function.__code__ in Python 2 (#3152) The following code works: >>> print(sys.version) 2.7.16 (default, Mar 11 2019, 18:59:25) >>> def f(): pass >>> print(f.__code__) ", line 1> >>> isinstance(f.__code__, types.CodeType) True but it didn't type-check with `mypy --python-version 2.7`. --- stdlib/2/__builtin__.pyi | 2 +- stdlib/2and3/builtins.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 9e822fbe6640..03e77bd33a76 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -876,9 +876,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]): diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 9e822fbe6640..03e77bd33a76 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -876,9 +876,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]): From 4697adcb1a36b2363df258b480c7207005b7c7b4 Mon Sep 17 00:00:00 2001 From: Kamil Bar Date: Fri, 26 Jul 2019 20:46:15 +0200 Subject: [PATCH 078/201] [stdlib][3] Add missing typing.OrderedDict generic stub for Python 3.7.2 (#3153) --- stdlib/3/typing.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index d3aee9508aca..042f86487f67 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -56,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) From 9ccf9356bf35082d298604f3604fecbdb9c06443 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sat, 27 Jul 2019 10:58:21 +0200 Subject: [PATCH 079/201] Remove Python 3.4 support (#3147) Closes #3123 --- CONTRIBUTING.md | 18 +- README.md | 2 +- stdlib/2and3/binascii.pyi | 11 +- stdlib/2and3/smtpd.pyi | 16 +- stdlib/2and3/ssl.pyi | 150 ++-- stdlib/2and3/tarfile.pyi | 3 - stdlib/2and3/webbrowser.pyi | 13 +- stdlib/3/_imp.pyi | 7 +- stdlib/3/_operator.pyi | 4 +- stdlib/3/asyncio/__init__.pyi | 13 +- stdlib/3/asyncio/base_events.pyi | 6 +- stdlib/3/asyncio/events.pyi | 10 +- stdlib/3/asyncio/futures.pyi | 3 +- stdlib/3/asyncio/queues.pyi | 6 - stdlib/3/collections/__init__.pyi | 46 +- stdlib/3/collections/abc.pyi | 16 +- stdlib/3/compileall.pyi | 5 +- stdlib/3/email/message.pyi | 3 +- stdlib/3/email/policy.pyi | 3 +- stdlib/3/faulthandler.pyi | 8 +- stdlib/3/glob.pyi | 8 +- stdlib/3/heapq.pyi | 6 +- stdlib/3/html/parser.pyi | 9 +- stdlib/3/http/__init__.pyi | 124 ++-- stdlib/3/http/client.pyi | 86 +-- stdlib/3/imp.pyi | 3 +- stdlib/3/importlib/abc.pyi | 9 +- stdlib/3/importlib/util.pyi | 23 +- stdlib/3/inspect.pyi | 41 +- stdlib/3/io.pyi | 6 +- stdlib/3/ipaddress.pyi | 6 +- stdlib/3/json/__init__.pyi | 3 +- stdlib/3/json/decoder.pyi | 15 +- stdlib/3/lzma.pyi | 5 +- stdlib/3/os/__init__.pyi | 384 +++++------ stdlib/3/posix.pyi | 3 +- stdlib/3/signal.pyi | 130 ++-- stdlib/3/smtplib.pyi | 24 +- stdlib/3/subprocess.pyi | 761 +++++++++++---------- stdlib/3/symbol.pyi | 9 +- stdlib/3/sys.pyi | 3 +- stdlib/3/tempfile.pyi | 164 ++--- stdlib/3/typing.pyi | 25 +- stdlib/3/unittest/loader.pyi | 10 +- stdlib/3/unittest/runner.pyi | 26 +- stdlib/3/urllib/parse.pyi | 21 +- stdlib/3/urllib/request.pyi | 19 +- stdlib/{3.5 => 3}/zipapp.pyi | 0 tests/check_consistent.py | 3 +- tests/mypy_test.py | 2 +- third_party/2and3/boto/utils.pyi | 2 +- third_party/2and3/markupsafe/__init__.pyi | 2 +- third_party/2and3/markupsafe/_compat.pyi | 2 +- third_party/{3.5 => 3}/contextvars.pyi | 0 third_party/3/pkg_resources/py31compat.pyi | 9 +- 55 files changed, 1004 insertions(+), 1282 deletions(-) rename stdlib/{3.5 => 3}/zipapp.pyi (100%) rename third_party/{3.5 => 3}/contextvars.pyi (100%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 045d07f654d0..d5f09b179a72 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -307,8 +307,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 +318,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 +331,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/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/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/ssl.pyi b/stdlib/2and3/ssl.pyi index c0990d967f6f..717c0edac005 100644 --- a/stdlib/2and3/ssl.pyi +++ b/stdlib/2and3/ssl.pyi @@ -48,11 +48,13 @@ 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 = ..., *, - cafile: Optional[str] = ..., - capath: Optional[str] = ..., - cadata: Union[str, bytes, None] = ...) -> SSLContext: ... +def create_default_context( + purpose: Any = ..., + *, + cafile: Optional[str] = ..., + capath: Optional[str] = ..., + cadata: Union[str, bytes, None] = ..., +) -> SSLContext: ... if sys.version_info >= (3, 4): def _create_unverified_context(protocol: int = ..., *, @@ -80,39 +82,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): @@ -123,9 +121,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 @@ -133,8 +130,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 @@ -144,41 +140,40 @@ 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 +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] -if sys.version_info >= (3, 4): +else: class _ASN1Object(NamedTuple('_ASN1Object', [('nid', int), ('shortname', str), ('longname', str), ('oid', str)])): ... class Purpose(_ASN1Object, enum.Enum): SERVER_AUTH = ... @@ -202,12 +197,10 @@ 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: ... @@ -223,37 +216,30 @@ if sys.version_info >= (3, 7): 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 cert_store_stats(self) -> Dict[str, int]: ... def load_cert_chain(self, certfile: str, keyfile: Optional[str] = ..., password: _PasswordType = ...) -> None: ... - if sys.version_info < (3,) or sys.version_info >= (3, 4): - def load_default_certs(self, purpose: Purpose = ...) -> 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[str, 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: ... def set_npn_protocols(self, protocols: List[str]) -> None: ... def set_servername_callback(self, server_name_callback: Optional[_SrvnmeCbType]) -> None: ... diff --git a/stdlib/2and3/tarfile.pyi b/stdlib/2and3/tarfile.pyi index f5984949d1db..07f78aeeb7d9 100644 --- a/stdlib/2and3/tarfile.pyi +++ b/stdlib/2and3/tarfile.pyi @@ -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/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/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/asyncio/__init__.pyi b/stdlib/3/asyncio/__init__.pyi index b98c2d1c8bd6..c89d5f77b73b 100644 --- a/stdlib/3/asyncio/__init__.pyi +++ b/stdlib/3/asyncio/__init__.pyi @@ -84,14 +84,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 31023abf1db3..4f84e4be940c 100644 --- a/stdlib/3/asyncio/base_events.pyi +++ b/stdlib/3/asyncio/base_events.pyi @@ -39,8 +39,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: ... @@ -131,8 +130,7 @@ class BaseEventLoop(AbstractEventLoop): 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 3dbd60944f53..5cab0044aa11 100644 --- a/stdlib/3/asyncio/events.pyi +++ b/stdlib/3/asyncio/events.pyi @@ -73,9 +73,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]: ... @@ -197,9 +196,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..b4323c0189d4 100644 --- a/stdlib/3/asyncio/futures.pyi +++ b/stdlib/3/asyncio/futures.pyi @@ -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/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/collections/__init__.pyi b/stdlib/3/collections/__init__.pyi index 524ff6f8f4e3..a6cecdfc794d 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') @@ -118,8 +115,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 +128,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 +136,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 +145,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 +153,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 +189,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,10 +229,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: ... + 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) 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..0e0b11748d73 100644 --- a/stdlib/3/compileall.pyi +++ b/stdlib/3/compileall.pyi @@ -12,9 +12,6 @@ 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_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_path(skip_curdir: bool = ..., maxlevels: int = ..., force: bool = ..., quiet: int = ..., legacy: bool = ..., optimize: int = ...) -> _SuccessType: ... 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 2dfce7714d53..736a4539c727 100644 --- a/stdlib/3/faulthandler.pyi +++ b/stdlib/3/faulthandler.pyi @@ -1,16 +1,10 @@ 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: ... 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/parser.pyi b/stdlib/3/html/parser.pyi index d4cfb5102225..55b99ea3407f 100644 --- a/stdlib/3/html/parser.pyi +++ b/stdlib/3/html/parser.pyi @@ -3,11 +3,7 @@ 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: ... @@ -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..adc6940aad02 100644 --- a/stdlib/3/http/__init__.pyi +++ b/stdlib/3/http/__init__.pyi @@ -2,68 +2,66 @@ import sys from enum import IntEnum -if sys.version_info >= (3, 5): - class HTTPStatus(IntEnum): +class HTTPStatus(IntEnum): + def __init__(self, *a) -> None: ... - def __init__(self, *a) -> None: ... + phrase: str + description: str - 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 = ... + 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 = ... diff --git a/stdlib/3/http/client.pyi b/stdlib/3/http/client.pyi index 2b173993e143..f4b5189d94d8 100644 --- a/stdlib/3/http/client.pyi +++ b/stdlib/3/http/client.pyi @@ -80,61 +80,34 @@ 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: ... +# 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: ... # This is an API stub only for the class below, not a class itself. # urllib.request uses it for a parameter. @@ -220,5 +193,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/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 32d97cf276cd..878d0652ee81 100644 --- a/stdlib/3/importlib/util.pyi +++ b/stdlib/3/importlib/util.pyi @@ -43,18 +43,11 @@ def spec_from_file_location( 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 320200c44d4e..91126028c335 100644 --- a/stdlib/3/inspect.pyi +++ b/stdlib/3/inspect.pyi @@ -28,9 +28,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 +54,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: ... @@ -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: ... # @@ -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 e6489028151f..5afbbcbf386e 100644 --- a/stdlib/3/io.pyi +++ b/stdlib/3/io.pyi @@ -56,8 +56,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: ... @@ -109,8 +108,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: ... diff --git a/stdlib/3/ipaddress.pyi b/stdlib/3/ipaddress.pyi index f706330b6426..c6855fe264b7 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: ... diff --git a/stdlib/3/json/__init__.pyi b/stdlib/3/json/__init__.pyi index cf42c36c72df..e60c4727dc51 100644 --- a/stdlib/3/json/__init__.pyi +++ b/stdlib/3/json/__init__.pyi @@ -3,8 +3,7 @@ from typing import Any, IO, Optional, Tuple, Callable, Dict, List, Union, Protoc 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 = ..., 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/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/os/__init__.pyi b/stdlib/3/os/__init__.pyi index b71792687e56..2a9656a3de10 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 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 @@ -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,36 +403,36 @@ 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: ... +def link( + src: _PathType, + link_name: _PathType, + *, + src_dir_fd: Optional[int] = ..., + dst_dir_fd: Optional[int] = ..., + follow_symlinks: bool = ..., +) -> None: ... if sys.version_info >= (3, 6): @overload @@ -465,41 +443,20 @@ if sys.version_info >= (3, 6): def listdir(path: int) -> List[str]: ... @overload def listdir(path: PathLike[str]) -> List[str]: ... -elif sys.version_info >= (3, 3): +else: @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 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 +464,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 +490,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,22 +503,25 @@ 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: ... if sys.version_info >= (3, 6): def walk(top: Union[AnyStr, PathLike[AnyStr]], topdown: bool = ..., @@ -592,7 +532,7 @@ else: def walk(top: AnyStr, topdown: bool = ..., onerror: Optional[Callable[[OSError], Any]] = ..., 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 = ..., @@ -643,17 +583,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 +594,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 +606,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 +619,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 +632,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/posix.pyi b/stdlib/3/posix.pyi index 6902e5f23240..a24001d7fe7d 100644 --- a/stdlib/3/posix.pyi +++ b/stdlib/3/posix.pyi @@ -65,8 +65,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 diff --git a/stdlib/3/signal.pyi b/stdlib/3/signal.pyi index 34a8cdd07f29..c520b9a6437e 100644 --- a/stdlib/3/signal.pyi +++ b/stdlib/3/signal.pyi @@ -13,77 +13,65 @@ 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] +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] SIGABRT: _SIG = ... SIGALRM: _SIG = ... 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/subprocess.pyi b/stdlib/3/subprocess.pyi index fa7d10236487..57bff805ee51 100644 --- a/stdlib/3/subprocess.pyi +++ b/stdlib/3/subprocess.pyi @@ -38,372 +38,396 @@ _ENV = Union[Mapping[bytes, _TXT], Mapping[Text, _TXT]] _T = TypeVar('_T') -if sys.version_info >= (3, 5): - 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: ... +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]: ... +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, @@ -795,10 +819,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, 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 911ff4fe9344..fa99bbb13be1 100644 --- a/stdlib/3/sys.pyi +++ b/stdlib/3/sys.pyi @@ -185,8 +185,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..e4aad54b4a03 100644 --- a/stdlib/3/tempfile.pyi +++ b/stdlib/3/tempfile.pyi @@ -13,111 +13,75 @@ tempdir: Optional[str] template: str -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]: - ... +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: ... +# 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: ... - # 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]: ... + # 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]: ... - 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: ... +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: ... - 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: ... +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: ... - 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: - 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: 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/typing.pyi b/stdlib/3/typing.pyi index 042f86487f67..1fefd23a2bf4 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -168,10 +168,6 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]): @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. - @runtime_checkable class Awaitable(Protocol[_T_co]): @abstractmethod @@ -271,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]: ... @@ -376,13 +369,15 @@ class ContextManager(Protocol[_T_co]): __exc_value: Optional[BaseException], __traceback: Optional[TracebackType]) -> Optional[bool]: ... -if sys.version_info >= (3, 5): - @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]]: ... +@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, 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/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/urllib/parse.pyi b/stdlib/3/urllib/parse.pyi index 8d7cc4a0db5c..b835119ec890 100644 --- a/stdlib/3/urllib/parse.pyi +++ b/stdlib/3/urllib/parse.pyi @@ -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 cac03ae1a61a..b043a115e4ec 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -115,14 +115,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, 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..47e455830067 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -13,7 +13,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 +21,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 2d911910932f..568f072b169a 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -88,7 +88,7 @@ def main(): print("Cannot import mypy. Did you install it?") sys.exit(1) - versions = [(3, 8), (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)] diff --git a/third_party/2and3/boto/utils.pyi b/third_party/2and3/boto/utils.pyi index 6552b0af1610..2132eb374a1d 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 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/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/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 From 15aa18d0a2ed26c263ce8102f1f7ee7d3b2cb8a0 Mon Sep 17 00:00:00 2001 From: Allison Kaptur Date: Sat, 27 Jul 2019 02:39:23 -0700 Subject: [PATCH 080/201] dateutil.rrule can take dates (#3154) --- third_party/2and3/dateutil/rrule.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/2and3/dateutil/rrule.pyi b/third_party/2and3/dateutil/rrule.pyi index 84e4eb5441bc..a459abe3efde 100644 --- a/third_party/2and3/dateutil/rrule.pyi +++ b/third_party/2and3/dateutil/rrule.pyi @@ -35,11 +35,11 @@ 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]]] = ..., From 568f1ea5558d5cef0e9863f8ae9b07a26158425b Mon Sep 17 00:00:00 2001 From: "Michael R. Shannon" Date: Tue, 30 Jul 2019 00:48:28 -0600 Subject: [PATCH 081/201] Add attributes to xml.etree.ElementTree.ParseError. (#3158) --- stdlib/2and3/xml/etree/ElementTree.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/2and3/xml/etree/ElementTree.pyi b/stdlib/2and3/xml/etree/ElementTree.pyi index ebd4ae122d32..6b765f6f4667 100644 --- a/stdlib/2and3/xml/etree/ElementTree.pyi +++ b/stdlib/2and3/xml/etree/ElementTree.pyi @@ -7,7 +7,9 @@ import sys VERSION: str -class ParseError(SyntaxError): ... +class ParseError(SyntaxError): + code: int + position: Tuple[int, int] def iselement(element: object) -> bool: ... From 32a89809f0c95ce51e4e9a1f6ad327c6ca6cecc6 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Tue, 30 Jul 2019 00:25:01 -0700 Subject: [PATCH 082/201] curses: getch returns an integer (#3156) --- stdlib/2and3/_curses.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/2and3/_curses.pyi b/stdlib/2and3/_curses.pyi index 836089f5b32d..efb7e7994531 100644 --- a/stdlib/2and3/_curses.pyi +++ b/stdlib/2and3/_curses.pyi @@ -350,9 +350,9 @@ 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: ... From bd2d0fcc8516512a5fa7919faee80d3535efc96d Mon Sep 17 00:00:00 2001 From: Brad Date: Tue, 30 Jul 2019 11:28:13 -0400 Subject: [PATCH 083/201] Add hints for 3 globals from logging/__init__.py (#3159) --- stdlib/2and3/logging/__init__.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/2and3/logging/__init__.pyi b/stdlib/2and3/logging/__init__.pyi index bf62b466f257..8f4e01f1ba7e 100644 --- a/stdlib/2and3/logging/__init__.pyi +++ b/stdlib/2and3/logging/__init__.pyi @@ -26,6 +26,9 @@ else: _Path = str raiseExceptions: bool +logThreads: bool +logMultiprocessing: bool +logProcesses: bool def currentframe() -> FrameType: ... From c6cbe4da66dfd98de11bdefbda47b3af326ba466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Tue, 30 Jul 2019 18:53:56 +0300 Subject: [PATCH 084/201] inspect: use more specific arg type for some source retrieve functions (#3155) --- stdlib/2/inspect.pyi | 21 ++++++++++----------- stdlib/3/inspect.pyi | 25 +++++++++++++------------ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/stdlib/2/inspect.pyi b/stdlib/2/inspect.pyi index 654fa07734e0..a7ad5029c4db 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,20 +52,19 @@ 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, 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) -> Optional[str]: ... def getcomments(object: object) -> Optional[str]: ... -def getfile(object: object) -> str: ... +def getfile(object: _SourceObjectType) -> str: ... def getmodule(object: object) -> Optional[ModuleType]: ... -def getsourcefile(object: object) -> Optional[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 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: ... diff --git a/stdlib/3/inspect.pyi b/stdlib/3/inspect.pyi index 91126028c335..737b22896e53 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 # @@ -75,20 +77,19 @@ 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, 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) -> Optional[str]: ... def getcomments(object: object) -> Optional[str]: ... -def getfile(object: object) -> str: ... +def getfile(object: _SourceObjectType) -> str: ... def getmodule(object: object) -> Optional[ModuleType]: ... -def getsourcefile(object: object) -> Optional[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 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: ... From 29dde6c8833697462fd4dc73d77e48047f418c60 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Tue, 30 Jul 2019 08:57:11 -0700 Subject: [PATCH 085/201] Fix type annotations for get_wch / unget_wch (#3157) --- stdlib/2and3/_curses.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/2and3/_curses.pyi b/stdlib/2and3/_curses.pyi index efb7e7994531..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): @@ -355,9 +355,9 @@ class _CursesWindow: 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 From c3b70d422477650cb65fb46f085f20aba9b00c74 Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Tue, 30 Jul 2019 13:50:51 -0700 Subject: [PATCH 086/201] Require the newest pytype version, with a pyi parser fix. (#3160) For https://github.com/python/typeshed/pull/3149. --- requirements-tests-py3.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-tests-py3.txt b/requirements-tests-py3.txt index f5e47a52bf5f..34c3a46716aa 100644 --- a/requirements-tests-py3.txt +++ b/requirements-tests-py3.txt @@ -5,4 +5,4 @@ flake8==3.7.8 flake8-bugbear==19.3.0 flake8-pyi==19.3.0 isort==4.3.21 -pytype>=2019.7.11 +pytype>=2019.7.30 From 4c8d577d686c643f0a2fa4e9dfe797cdb1411f1d Mon Sep 17 00:00:00 2001 From: Ilya Konstantinov Date: Tue, 30 Jul 2019 17:04:36 -0700 Subject: [PATCH 087/201] flask: allow view func body to be dict (#3149) --- third_party/2and3/flask/app.pyi | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/third_party/2and3/flask/app.pyi b/third_party/2and3/flask/app.pyi index e18fded513d1..308367d5ff70 100644 --- a/third_party/2and3/flask/app.pyi +++ b/third_party/2and3/flask/app.pyi @@ -43,17 +43,17 @@ _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, Response, _WSGICallable] +_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[..., Text], - Callable[..., ByteString], Callable[..., NoReturn], - Callable[..., Response], - Callable[..., _WSGICallable], - Callable[..., Tuple[_Body, _Status, _Headers]], - Callable[..., Tuple[_Body, _Status]], - Callable[..., Tuple[_Body, _Headers]] + Callable[..., _ViewFuncReturnType], ] _VT = TypeVar('_VT', bound=_ViewFunc) From edee7cfb3cc5af16afa557f1279c22ee6663a61f Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Wed, 31 Jul 2019 00:06:02 -0700 Subject: [PATCH 088/201] Remove unused import from stdlib/2/htmlentitydefs.pyi (#3162) --- stdlib/2/htmlentitydefs.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/2/htmlentitydefs.pyi b/stdlib/2/htmlentitydefs.pyi index 6ae88e757212..d1aadb3b8b92 100644 --- a/stdlib/2/htmlentitydefs.pyi +++ b/stdlib/2/htmlentitydefs.pyi @@ -1,4 +1,4 @@ -from typing import Any, Mapping +from typing import Mapping name2codepoint: Mapping[str, int] codepoint2name: Mapping[int, str] From f2fdb54765923929e752ef9e85e32b5a31669519 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Wed, 31 Jul 2019 06:45:50 -0700 Subject: [PATCH 089/201] Precise the type of Python 2 htmlentitydefs module (#3163) The code and documentation specifies the values specifically as dictionaries. --- stdlib/2/htmlentitydefs.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/2/htmlentitydefs.pyi b/stdlib/2/htmlentitydefs.pyi index d1aadb3b8b92..749b3039dfc3 100644 --- a/stdlib/2/htmlentitydefs.pyi +++ b/stdlib/2/htmlentitydefs.pyi @@ -1,5 +1,5 @@ -from typing import 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] From 02401c836f17cd96d3775d9184ebb26db535f074 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Wed, 31 Jul 2019 06:46:16 -0700 Subject: [PATCH 090/201] Add type annotations for Python 3 html.entities (#3161) --- stdlib/3/html/entities.pyi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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] From 3c4141982e22aba6966daba5785d1ba959d7fc49 Mon Sep 17 00:00:00 2001 From: Nicklas Lindgren Date: Wed, 31 Jul 2019 19:53:23 +0200 Subject: [PATCH 091/201] Declare asyncio.as_completed() as taking an Iterable (#3164) The stub for asyncio.as_completed declared it as taking a Sequence of Futures. This was unnecessarily strict. Just like asyncio.wait, asyncio.as_completed can be declared to take an Iterable of Futures instead. Both these functions iterate over their argument only once to store its items in a set, so an Iterable is sufficiently strict. This has been true since the initial implementation of the functions. --- stdlib/3/asyncio/tasks.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/asyncio/tasks.pyi b/stdlib/3/asyncio/tasks.pyi index ef657aab1248..d100605d91be 100644 --- a/stdlib/3/asyncio/tasks.pyi +++ b/stdlib/3/asyncio/tasks.pyi @@ -21,7 +21,7 @@ FIRST_EXCEPTION: str FIRST_COMPLETED: str ALL_COMPLETED: str -def as_completed(fs: Sequence[_FutureT[_T]], *, loop: Optional[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]: ... From 1dc24e1c6769fa5ce4c9608e87f4562b5ae153e0 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Sat, 3 Aug 2019 14:51:55 +0000 Subject: [PATCH 092/201] Add nbytes to the memoryview definition (#3167) `nbytes`, like `contiguous`, was added in Python 3.3. --- stdlib/2/__builtin__.pyi | 1 + stdlib/2and3/builtins.pyi | 1 + 2 files changed, 2 insertions(+) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 03e77bd33a76..bf12fc093233 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -784,6 +784,7 @@ 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: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 03e77bd33a76..bf12fc093233 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -784,6 +784,7 @@ 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: ... From d05a9d3d833625f251cc84f88b81afade9a95325 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 5 Aug 2019 08:08:57 -0700 Subject: [PATCH 093/201] Improve enums (#3168) I realized while working on srittau/type-stub-pep#64 that a few things we do in existing enum definitions in typeshed are problematic: - Using "= ..." doesn't allow type checkers to correctly type the result of Enum.MEMBER.value. In fact, mypy at least infers .value to be "Ellipsis" if you do this. - Properties on the enum values themselves, like HTTPStatus.phrase, should not be specified directly as attributes, because it makes type checkers think that the properties themselves are enum members. I ended up doing a bit more cleanup to the signal module: - Remove unnecessary ... initializers. - Remove unnecessary _SIG = Signals alias. - I don't have Windows to test, but the C code for _signal suggests that CTRL_C_EVENT and CTRL_BREAK events are not Signals, but just ints: https://github.com/python/cpython/blob/1dbd084f1f68d7293718b663df675cfbd0c65712/Modules/signalmodule.c#L1575 --- stdlib/2and3/plistlib.pyi | 4 +- stdlib/2and3/socket.pyi | 104 +++++++++++----------- stdlib/3/http/__init__.pyi | 124 +++++++++++++------------- stdlib/3/re.pyi | 72 +++++++-------- stdlib/3/signal.pyi | 178 ++++++++++++++++++------------------- 5 files changed, 239 insertions(+), 243 deletions(-) diff --git a/stdlib/2and3/plistlib.pyi b/stdlib/2and3/plistlib.pyi index 64201dd5b6dd..ad5d51dff150 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 diff --git a/stdlib/2and3/socket.pyi b/stdlib/2and3/socket.pyi index 36da84951145..4d1916a58a4d 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,23 +458,23 @@ 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 diff --git a/stdlib/3/http/__init__.pyi b/stdlib/3/http/__init__.pyi index adc6940aad02..54aae66660dc 100644 --- a/stdlib/3/http/__init__.pyi +++ b/stdlib/3/http/__init__.pyi @@ -1,67 +1,65 @@ -import sys - from enum import IntEnum class HTTPStatus(IntEnum): - def __init__(self, *a) -> None: ... - - phrase: str - description: str + @property + def phrase(self) -> str: ... + @property + def description(self) -> 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 = ... + 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 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/signal.pyi b/stdlib/3/signal.pyi index c520b9a6437e..670567b83650 100644 --- a/stdlib/3/signal.pyi +++ b/stdlib/3/signal.pyi @@ -1,120 +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 = ... +ITIMER_PROF: int +ITIMER_REAL: int +ITIMER_VIRTUAL: int -NSIG: int = ... +NSIG: int 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 = ... + 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 = ... - SIG_IGN = ... + SIG_DFL: int + SIG_IGN: int SIG_DFL = Handlers.SIG_DFL SIG_IGN = Handlers.SIG_IGN class Sigmasks(IntEnum): - SIG_BLOCK = ... - SIG_UNBLOCK = ... - SIG_SETMASK = ... + SIG_BLOCK: int + SIG_UNBLOCK: int + SIG_SETMASK: int 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] -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 = ... +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: ... From 29771aa1eeb9193dc8b8f7ec9987d69600725154 Mon Sep 17 00:00:00 2001 From: Cole Maclean Date: Mon, 5 Aug 2019 23:34:38 -0700 Subject: [PATCH 094/201] Add missing methods to asyncio stubs (#3088) --- stdlib/3/asyncio/base_events.pyi | 128 +++++++++++++++-------- stdlib/3/asyncio/events.pyi | 171 +++++++++++++++++++++---------- stdlib/3/asyncio/protocols.pyi | 4 + stdlib/3/asyncio/transports.pyi | 7 ++ 4 files changed, 211 insertions(+), 99 deletions(-) diff --git a/stdlib/3/asyncio/base_events.pyi b/stdlib/3/asyncio/base_events.pyi index 4f84e4be940c..373d8d87030b 100644 --- a/stdlib/3/asyncio/base_events.pyi +++ b/stdlib/3/asyncio/base_events.pyi @@ -1,8 +1,8 @@ import selectors -from socket import socket, _Address +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 asyncio.futures import Future from asyncio.coroutines import coroutine from asyncio.events import AbstractEventLoop, AbstractServer, Handle, TimerHandle @@ -59,37 +59,76 @@ class BaseEventLoop(AbstractEventLoop): 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]: ... + 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 = ...) -> AbstractServer: ... + @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 = ...) -> AbstractServer: ... + 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: ... + 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: ... + 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, 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]: ... + @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]] = ..., *, @@ -97,8 +136,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]: ... @@ -116,15 +153,18 @@ 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: _Address) -> 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: ... diff --git a/stdlib/3/asyncio/events.pyi b/stdlib/3/asyncio/events.pyi index 5cab0044aa11..a559809ea13a 100644 --- a/stdlib/3/asyncio/events.pyi +++ b/stdlib/3/asyncio/events.pyi @@ -1,8 +1,8 @@ import selectors -from socket import socket, _Address +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]: ... @@ -102,43 +108,93 @@ class AbstractEventLoop(metaclass=ABCMeta): @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]: ... + 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, @@ -147,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 @@ -175,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: _Address) -> 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: ... 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/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: ... From 50f19886509c305c4a93c0ae999f0d01c5c0277b Mon Sep 17 00:00:00 2001 From: "g.denis" Date: Wed, 7 Aug 2019 10:39:15 +0200 Subject: [PATCH 095/201] concurrent: add private classes and exceptions (#3169) --- stdlib/3/concurrent/futures/_base.pyi | 58 ++++++++++++++++++--- stdlib/3/concurrent/futures/thread.pyi | 20 ++++++- third_party/2/concurrent/futures/_base.pyi | 58 ++++++++++++++++++--- third_party/2/concurrent/futures/thread.pyi | 20 ++++++- 4 files changed, 138 insertions(+), 18 deletions(-) diff --git a/stdlib/3/concurrent/futures/_base.pyi b/stdlib/3/concurrent/futures/_base.pyi index 13037d87f968..fd04210936dc 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 +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]): @@ -54,3 +59,42 @@ def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> It 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] + def __init__(self) -> None: ... + def add_result(self, future: Future) -> None: ... + def add_exception(self, future: Future) -> None: ... + def add_cancelled(self, future: Future) -> None: ... + + +class _AsCompletedWaiter(_Waiter): + lock: threading.Lock + def __init__(self) -> None: ... + def add_result(self, future: Future) -> None: ... + def add_exception(self, future: Future) -> None: ... + def add_cancelled(self, future: Future) -> None: ... + + +class _FirstCompletedWaiter(_Waiter): + def add_result(self, future: Future) -> None: ... + def add_exception(self, future: Future) -> None: ... + def add_cancelled(self, future: Future) -> 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) -> None: ... + def add_exception(self, future: Future) -> None: ... + def add_cancelled(self, future: Future) -> None: ... + + +class _AcquireFutures: + futures: Iterable[Future] + def __init__(self, futures: Iterable[Future]) -> None: ... + def __enter__(self) -> None: ... + def __exit__(self, *args: Any) -> None: ... diff --git a/stdlib/3/concurrent/futures/thread.pyi b/stdlib/3/concurrent/futures/thread.pyi index e2b236b8df6a..c4f895d7a543 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 ._base import Executor +from typing import Any, Callable, 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,13 @@ class ThreadPoolExecutor(Executor): thread_name_prefix: str = ...) -> None: ... else: def __init__(self, max_workers: Optional[int] = ...) -> None: ... + + +class _WorkItem(Generic[_S]): + future: Future + fn: Callable[[Future[_S]], Any] + args: Any + kwargs: Any + def __init__(self, future: Future, fn: Callable[[Future[_S]], Any], args: Any, + kwargs: Any) -> None: ... + def run(self) -> None: ... diff --git a/third_party/2/concurrent/futures/_base.pyi b/third_party/2/concurrent/futures/_base.pyi index 13037d87f968..fd04210936dc 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 +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]): @@ -54,3 +59,42 @@ def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> It 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] + def __init__(self) -> None: ... + def add_result(self, future: Future) -> None: ... + def add_exception(self, future: Future) -> None: ... + def add_cancelled(self, future: Future) -> None: ... + + +class _AsCompletedWaiter(_Waiter): + lock: threading.Lock + def __init__(self) -> None: ... + def add_result(self, future: Future) -> None: ... + def add_exception(self, future: Future) -> None: ... + def add_cancelled(self, future: Future) -> None: ... + + +class _FirstCompletedWaiter(_Waiter): + def add_result(self, future: Future) -> None: ... + def add_exception(self, future: Future) -> None: ... + def add_cancelled(self, future: Future) -> 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) -> None: ... + def add_exception(self, future: Future) -> None: ... + def add_cancelled(self, future: Future) -> None: ... + + +class _AcquireFutures: + futures: Iterable[Future] + def __init__(self, futures: Iterable[Future]) -> None: ... + def __enter__(self) -> None: ... + def __exit__(self, *args: Any) -> None: ... diff --git a/third_party/2/concurrent/futures/thread.pyi b/third_party/2/concurrent/futures/thread.pyi index e2b236b8df6a..c4f895d7a543 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 ._base import Executor +from typing import Any, Callable, 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,13 @@ class ThreadPoolExecutor(Executor): thread_name_prefix: str = ...) -> None: ... else: def __init__(self, max_workers: Optional[int] = ...) -> None: ... + + +class _WorkItem(Generic[_S]): + future: Future + fn: Callable[[Future[_S]], Any] + args: Any + kwargs: Any + def __init__(self, future: Future, fn: Callable[[Future[_S]], Any], args: Any, + kwargs: Any) -> None: ... + def run(self) -> None: ... From 0dea39cb3c07f04abe5b15491e4bd62ce3e6739c Mon Sep 17 00:00:00 2001 From: Evgeny Dedov Date: Wed, 7 Aug 2019 11:43:05 +0300 Subject: [PATCH 096/201] make basicConfig parameters Optional[...] (#3170) --- stdlib/2and3/logging/__init__.pyi | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/stdlib/2and3/logging/__init__.pyi b/stdlib/2and3/logging/__init__.pyi index 8f4e01f1ba7e..290f62000ec2 100644 --- a/stdlib/2and3/logging/__init__.pyi +++ b/stdlib/2and3/logging/__init__.pyi @@ -357,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: ... From 6f01493edc8a6f563e571121483679fd46db336a Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Wed, 7 Aug 2019 23:45:08 -0700 Subject: [PATCH 097/201] Move some constants from tokenize to token in Python 3.7+. (#3175) --- stdlib/2and3/token.pyi | 4 ++++ stdlib/3/tokenize.pyi | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) 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/3/tokenize.pyi b/stdlib/3/tokenize.pyi index 33c8a2d5d258..9b6b50d2ee3c 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] From 3f6cec9872d0691fdd9b2b81440d1558bc926fbb Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Thu, 8 Aug 2019 16:59:20 +0200 Subject: [PATCH 098/201] Fix Match.group problems (#3172) * group() may return None values * group() allows to mix int and str arguments * Use concrete return type * Merge overloads --- stdlib/3/typing.pyi | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 1fefd23a2bf4..8b2481e55feb 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -5,6 +5,9 @@ from abc import abstractmethod, ABCMeta from types import CodeType, FrameType, TracebackType import collections # Needed by aliases like DefaultDict, see mypy issue 2986 +if sys.version_info < (3, 8): + from typing_extensions import Literal + # Definitions of special type checking related constructs. Their definition # are not used, so their value does not matter. @@ -526,15 +529,16 @@ class Match(Generic[AnyStr]): def expand(self, template: AnyStr) -> AnyStr: ... @overload - def group(self, group1: int = ...) -> AnyStr: ... - @overload - def group(self, group1: str) -> AnyStr: ... + def group(self, __group: Literal[0] = ...) -> AnyStr: ... @overload - def group(self, group1: int, group2: int, - *groups: int) -> Sequence[AnyStr]: ... + def group(self, __group: Union[str, int]) -> Optional[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[Optional[AnyStr], ...]: ... def groups(self, default: AnyStr = ...) -> Sequence[AnyStr]: ... def groupdict(self, default: AnyStr = ...) -> dict[str, AnyStr]: ... From c579f9107795e613d2927a6b12ef8a9efedad32a Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 9 Aug 2019 20:05:56 +0200 Subject: [PATCH 099/201] Improve werkzeug exceptions slightly (#3178) * Use Text for HTTPException.description * Add Unauthorized.www_authenticate * Remove wrong get_headers() overrides --- third_party/2and3/werkzeug/exceptions.pyi | 71 ++++++++++++----------- 1 file changed, 38 insertions(+), 33 deletions(-) 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 From 628eee29f7d154edecc6c8029cff3f14e2a0421c Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sat, 10 Aug 2019 22:08:18 +0200 Subject: [PATCH 100/201] Use Literal in a few more places (#3176) --- stdlib/2and3/xml/etree/ElementTree.pyi | 6 ++++- stdlib/3/_winapi.pyi | 13 ++++++++--- stdlib/3/ast.pyi | 8 ++++--- stdlib/3/gettext.pyi | 9 +++++--- stdlib/3/subprocess.pyi | 6 ++++- third_party/2and3/werkzeug/wrappers.pyi | 29 ++++++++++++++++++++----- 6 files changed, 54 insertions(+), 17 deletions(-) diff --git a/stdlib/2and3/xml/etree/ElementTree.pyi b/stdlib/2and3/xml/etree/ElementTree.pyi index 6b765f6f4667..0318bd8c2274 100644 --- a/stdlib/2and3/xml/etree/ElementTree.pyi +++ b/stdlib/2and3/xml/etree/ElementTree.pyi @@ -1,10 +1,14 @@ # Stubs for xml.etree.ElementTree from typing import Any, Callable, Dict, Generator, IO, ItemsView, Iterable, Iterator, KeysView, List, MutableSequence, Optional, overload, Sequence, Text, Tuple, TypeVar, Union -from typing_extensions import Literal 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): 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 e4c355dc20bb..8e89b2486d94 100644 --- a/stdlib/3/ast.pyi +++ b/stdlib/3/ast.pyi @@ -1,12 +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 overload, Any, Iterator, Optional, Union, TypeVar -from typing_extensions import Literal # The same unorthodox Bazel integration causes issues with sys, which # is imported in both modules. unfortunately we can't just rename sys, @@ -14,6 +11,11 @@ from typing_extensions import Literal # 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: ... diff --git a/stdlib/3/gettext.pyi b/stdlib/3/gettext.pyi index 7697404fb273..4b5398a46f20 100644 --- a/stdlib/3/gettext.pyi +++ b/stdlib/3/gettext.pyi @@ -1,7 +1,10 @@ -# Stubs for gettext (Python 3.4) - +import sys from typing import overload, Any, Container, IO, Iterable, Optional, Type, TypeVar -from typing_extensions import Literal + +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: ... diff --git a/stdlib/3/subprocess.pyi b/stdlib/3/subprocess.pyi index 57bff805ee51..0e5df2c5094c 100644 --- a/stdlib/3/subprocess.pyi +++ b/stdlib/3/subprocess.pyi @@ -7,9 +7,13 @@ from typing import ( Generic, TypeVar, AnyStr, overload, ) -from typing_extensions import Literal 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. # For outputs we use laborious literal based overloads to try to determine diff --git a/third_party/2and3/werkzeug/wrappers.pyi b/third_party/2and3/werkzeug/wrappers.pyi index 74cb6ffa870b..4ea56495a8b2 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,6 +12,11 @@ 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 @@ -44,8 +49,16 @@ class BaseRequest: args: ImmutableMultiDict @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 + @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 values: CombinedMultiDict files: MultiDict @@ -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]: ... From 0dc3bf941aac3e329b1f5d98fd90842cac191e6b Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 10 Aug 2019 13:08:59 -0700 Subject: [PATCH 101/201] Improve type of tornado.testing.gen_test. (#3174) gen_test can accept a timeout parameter. See https://www.tornadoweb.org/en/branch5.1/testing.html#tornado.testing.gen_test. --- third_party/2/tornado/testing.pyi | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/third_party/2/tornado/testing.pyi b/third_party/2/tornado/testing.pyi index 25fd0e59e583..adc7fcda6fc1 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,13 @@ 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]], Callable[..., None]]: + ... + +@overload +def gen_test(func: Callable[..., Generator]) -> Callable[..., None]: + ... class LogTrapTestCase(unittest.TestCase): def run(self, result: Optional[Any] = ...): ... From baea5a7bc3f2ab6f14d28d2037a5119972b43213 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 10 Aug 2019 13:15:46 -0700 Subject: [PATCH 102/201] Widen the annotation of os.write to include buffer. (#3109) --- stdlib/2/os/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/2/os/__init__.pyi b/stdlib/2/os/__init__.pyi index 2c66dc79d471..da2a35dd1f95 100644 --- a/stdlib/2/os/__init__.pyi +++ b/stdlib/2/os/__init__.pyi @@ -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: ... From 26f575130c7d5ef3c2f4dc4e5925c40d154e6e06 Mon Sep 17 00:00:00 2001 From: Patrick Valsecchi Date: Sat, 10 Aug 2019 22:22:40 +0200 Subject: [PATCH 103/201] Add some redis types (#3092) --- third_party/2and3/redis/client.pyi | 32 +++++++++++++------------- third_party/2and3/redis/connection.pyi | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/third_party/2and3/redis/client.pyi b/third_party/2and3/redis/client.pyi index f086a4be5249..c180df4254fe 100644 --- a/third_party/2and3/redis/client.pyi +++ b/third_party/2and3/redis/client.pyi @@ -1,5 +1,5 @@ from datetime import timedelta -from typing import Any, Iterable, Text, Optional, Mapping, Tuple, Union +from typing import Any, Iterable, Text, Optional, Mapping, Tuple, Union, Callable, List from .connection import ConnectionPool @@ -34,12 +34,12 @@ def parse_hscan(response, **options): ... def parse_zscan(response, **options): ... def parse_slowlog_get(response, **options): ... -_Str = Union[bytes, float, Text] +_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__( @@ -71,7 +71,7 @@ class Redis(object): 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): ... @@ -84,12 +84,12 @@ class Redis(object): 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): ... @@ -146,7 +146,7 @@ class Redis(object): def set( self, name: Text, - value: Any, + value: _Str, ex: Union[None, int, timedelta] = ..., px: Union[None, int, timedelta] = ..., nx: bool = ..., @@ -181,8 +181,8 @@ class Redis(object): 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=...): ... @@ -269,7 +269,7 @@ class Redis(object): 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): ... @@ -295,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 From 15b7cdaf40a6549d3228ff92ca6ca501c442f9ec Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Sat, 10 Aug 2019 16:25:03 -0400 Subject: [PATCH 104/201] Implement ZipExtFile in the zipfile type stubs (#3074) --- stdlib/2and3/zipfile.pyi | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/stdlib/2and3/zipfile.pyi b/stdlib/2and3/zipfile.pyi index 5b940a154c9d..a1ae7f3d2f14 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,6 +24,25 @@ error = BadZipfile class LargeZipFile(Exception): ... +class ZipExtFile(io.BufferedIOBase): + MAX_N: int = ... + MIN_READ_SIZE: int = ... + + if sys.version_info < (3, 6): + PATTERN: Pattern = ... + + 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 From 679e1a9a8cf358112bb71c07667c1ab204783cf1 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sat, 10 Aug 2019 13:31:58 -0700 Subject: [PATCH 105/201] =?UTF-8?q?Update=20URL:=20python/black=20?= =?UTF-8?q?=E2=86=92=20psf/black=20(#3180)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d5f09b179a72..4c871672360b 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 From 1edd6cd8a8820121cb5259f0af5f51f0422582a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 11 Aug 2019 06:21:54 +0300 Subject: [PATCH 106/201] Add Match.regs (#2819) --- stdlib/2/_sre.pyi | 2 ++ stdlib/2/typing.pyi | 2 ++ stdlib/3/typing.pyi | 2 ++ 3 files changed, 6 insertions(+) diff --git a/stdlib/2/_sre.pyi b/stdlib/2/_sre.pyi index 0692b4c17085..9b327d1c91d7 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 diff --git a/stdlib/2/typing.pyi b/stdlib/2/typing.pyi index af22c7e1d9ec..52042ff2be6c 100644 --- a/stdlib/2/typing.pyi +++ b/stdlib/2/typing.pyi @@ -404,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 diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 8b2481e55feb..f34bf325f2bc 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -545,6 +545,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 if sys.version_info >= (3, 6): def __getitem__(self, g: Union[int, str]) -> AnyStr: ... From b873894e169b0b15742eb8931f5320347b787dcc Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Wed, 14 Aug 2019 18:14:30 -0700 Subject: [PATCH 107/201] Fix a typo (self -> cls) in stdlib/2/subprocess.pyi. (#3185) --- stdlib/2/subprocess.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/2/subprocess.pyi b/stdlib/2/subprocess.pyi index 0c693a985ffd..e4ffc3db3320 100644 --- a/stdlib/2/subprocess.pyi +++ b/stdlib/2/subprocess.pyi @@ -82,7 +82,7 @@ class Popen(Generic[_T]): pid = 0 returncode = 0 - def __new__(self, + def __new__(cls, args: _CMD, bufsize: int = ..., executable: Optional[_TXT] = ..., From 0ee7c3c38b05a4d1712353bda5e6cffdaab2438b Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Fri, 16 Aug 2019 02:03:00 -0700 Subject: [PATCH 108/201] Update __import__ function annotations (#3188) Per the docs, globals/locals is an optional argument. Additionally, globals/locals can be any mapping type, not only a dict. Likewise, fromlist can be any sequence (the docs mention a tuple, not a list). The function returns a ModuleType, not Any. --- stdlib/2/__builtin__.pyi | 8 +++++--- stdlib/2and3/builtins.pyi | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index bf12fc093233..37d72736e67f 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,): @@ -1437,8 +1437,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. diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index bf12fc093233..37d72736e67f 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,): @@ -1437,8 +1437,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. From 5638d29203c0cc3ada62093bf1e9f18aced65ba6 Mon Sep 17 00:00:00 2001 From: Niels Buwen Date: Fri, 16 Aug 2019 17:08:23 +0200 Subject: [PATCH 109/201] Fix #3187 : Wrong Signatures in socketserver (#3189) Fixes #3187 --- stdlib/2/SocketServer.pyi | 8 ++++---- stdlib/3/socketserver.pyi | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/stdlib/2/SocketServer.pyi b/stdlib/2/SocketServer.pyi index d485b8bf1034..22dda28b4f1d 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: ... @@ -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/socketserver.pyi b/stdlib/3/socketserver.pyi index d485b8bf1034..22dda28b4f1d 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: ... @@ -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: ... From 3cfc3150f034ba7a30d39143dee791c2b42b0d2f Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Fri, 16 Aug 2019 19:53:52 +0100 Subject: [PATCH 110/201] Partially restore old (imprecise) signature of Match.group() (#3190) This partially reverts #3172 --- stdlib/3/typing.pyi | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index f34bf325f2bc..893dbffef624 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -5,9 +5,6 @@ from abc import abstractmethod, ABCMeta from types import CodeType, FrameType, TracebackType import collections # Needed by aliases like DefaultDict, see mypy issue 2986 -if sys.version_info < (3, 8): - from typing_extensions import Literal - # Definitions of special type checking related constructs. Their definition # are not used, so their value does not matter. @@ -528,17 +525,16 @@ 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, __group: Literal[0] = ...) -> AnyStr: ... - @overload - def group(self, __group: Union[str, int]) -> Optional[AnyStr]: ... + def group(self, __group: Union[str, int] = ...) -> AnyStr: ... @overload def group( self, __group1: Union[str, int], __group2: Union[str, int], *groups: Union[str, int], - ) -> Tuple[Optional[AnyStr], ...]: ... + ) -> Tuple[AnyStr, ...]: ... def groups(self, default: AnyStr = ...) -> Sequence[AnyStr]: ... def groupdict(self, default: AnyStr = ...) -> dict[str, AnyStr]: ... From b2947821832bb4d098985383c75c2d712b12f133 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Fri, 16 Aug 2019 16:13:33 -0700 Subject: [PATCH 111/201] Make most contextmanager `__exit__` signatures return Optional[bool] (#3179) This pull request is a follow-up to https://github.com/python/mypy/issues/7214. In short, within that mypy issue, we found it would be helpful to determine between contextmanagers that can "swallow" exceptions vs ones that can't. This helps prevent some false positive when using flags that analyze control flow such as `--warn-unreachable`. To do this, Jelle proposed assuming that only contextmanagers where the `__exit__` returns `bool` are assumed to swallow exceptions. This unfortunately required the following typeshed changes: 1. The typing.IO, threading.Lock, and concurrent.futures.Executor were all modified so `__exit__` returns `Optional[None]` instead of None -- along with all of their subclasses. I believe these three types are meant to be subclassed, so I felt picking the more general type was correct. 2. There were also a few concrete types (e.g. see socketserver, subprocess, ftplib...) that I modified to return `None` -- I checked the source code, and these all seem to return None (and don't appear to be meant to be subclassable). 3. contextlib.suppress was changed to return bool. I also double-checked the unittest modules and modified a subset of those contextmanagers, leaving ones like `_AssertRaisesContext` alone. --- CONTRIBUTING.md | 9 +++++++++ stdlib/2/SocketServer.pyi | 2 +- stdlib/2/__builtin__.pyi | 4 ++-- stdlib/2/_io.pyi | 4 ++-- stdlib/2/subprocess.pyi | 2 +- stdlib/2/tempfile.pyi | 4 ++-- stdlib/2/typing.pyi | 2 +- stdlib/2and3/builtins.pyi | 4 ++-- stdlib/2and3/codecs.pyi | 4 ++-- stdlib/2and3/contextlib.pyi | 9 +++++++++ stdlib/2and3/ftplib.pyi | 2 +- stdlib/2and3/tarfile.pyi | 2 +- stdlib/2and3/threading.pyi | 10 +++++----- stdlib/2and3/warnings.pyi | 2 +- stdlib/2and3/zipfile.pyi | 2 +- stdlib/3/concurrent/futures/_base.pyi | 2 +- stdlib/3/http/client.pyi | 5 ++--- stdlib/3/io.pyi | 6 +++--- stdlib/3/socketserver.pyi | 2 +- stdlib/3/subprocess.pyi | 2 +- stdlib/3/tempfile.pyi | 4 ++-- stdlib/3/typing.pyi | 2 +- stdlib/3/unittest/case.pyi | 4 ++-- stdlib/3/urllib/response.pyi | 2 +- third_party/2/concurrent/futures/_base.pyi | 2 +- 25 files changed, 55 insertions(+), 38 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4c871672360b..bdab962fe86d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/stdlib/2/SocketServer.pyi b/stdlib/2/SocketServer.pyi index 22dda28b4f1d..2403614b4709 100644 --- a/stdlib/2/SocketServer.pyi +++ b/stdlib/2/SocketServer.pyi @@ -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: ... diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 37d72736e67f..daadf8fb040c 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -787,7 +787,7 @@ class memoryview(Sized, Container[_mv_container_type]): 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: ... @@ -1615,7 +1615,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/_io.pyi b/stdlib/2/_io.pyi index e4e15cbfd90f..dd4d1440dd13 100644 --- a/stdlib/2/_io.pyi +++ b/stdlib/2/_io.pyi @@ -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: ... @@ -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): diff --git a/stdlib/2/subprocess.pyi b/stdlib/2/subprocess.pyi index e4ffc3db3320..672efbf8c71e 100644 --- a/stdlib/2/subprocess.pyi +++ b/stdlib/2/subprocess.pyi @@ -106,7 +106,7 @@ class Popen(Generic[_T]): def terminate(self) -> None: ... def kill(self) -> None: ... def __enter__(self) -> Popen: ... - def __exit__(self, type, value, traceback) -> bool: ... + def __exit__(self, type, value, traceback) -> None: ... def list2cmdline(seq: Sequence[str]) -> str: ... # undocumented diff --git a/stdlib/2/tempfile.pyi b/stdlib/2/tempfile.pyi index 2dcc1a924beb..4233cf72f179 100644 --- a/stdlib/2/tempfile.pyi +++ b/stdlib/2/tempfile.pyi @@ -24,7 +24,7 @@ class _TemporaryFileWrapper(IO[str]): def __init__(self, file: IO, 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/typing.pyi b/stdlib/2/typing.pyi index 52042ff2be6c..0d10952b5ae6 100644 --- a/stdlib/2/typing.pyi +++ b/stdlib/2/typing.pyi @@ -343,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 diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 37d72736e67f..daadf8fb040c 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -787,7 +787,7 @@ class memoryview(Sized, Container[_mv_container_type]): 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: ... @@ -1615,7 +1615,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/codecs.pyi b/stdlib/2and3/codecs.pyi index 47ea963c6920..fe734511be21 100644 --- a/stdlib/2and3/codecs.pyi +++ b/stdlib/2and3/codecs.pyi @@ -188,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__. @@ -229,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 4aa07471f842..a2b161ce85dc 100644 --- a/stdlib/2and3/contextlib.pyi +++ b/stdlib/2and3/contextlib.pyi @@ -46,6 +46,9 @@ 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: ... @@ -69,6 +72,9 @@ 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 @@ -94,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/ftplib.pyi b/stdlib/2and3/ftplib.pyi index dff8c4788bc2..9222ff6556d3 100644 --- a/stdlib/2and3/ftplib.pyi +++ b/stdlib/2and3/ftplib.pyi @@ -44,7 +44,7 @@ class FTP: encoding: str 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]) -> None: ... else: file: Optional[BinaryIO] diff --git a/stdlib/2and3/tarfile.pyi b/stdlib/2and3/tarfile.pyi index 07f78aeeb7d9..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 = ..., diff --git a/stdlib/2and3/threading.pyi b/stdlib/2and3/threading.pyi index 190f93407001..63f838f3df4d 100644 --- a/stdlib/2and3/threading.pyi +++ b/stdlib/2and3/threading.pyi @@ -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/warnings.pyi b/stdlib/2and3/warnings.pyi index 4d7419edbf90..d9ecec74f71e 100644 --- a/stdlib/2and3/warnings.pyi +++ b/stdlib/2and3/warnings.pyi @@ -43,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/zipfile.pyi b/stdlib/2and3/zipfile.pyi index a1ae7f3d2f14..f5b8fab0edff 100644 --- a/stdlib/2and3/zipfile.pyi +++ b/stdlib/2and3/zipfile.pyi @@ -55,7 +55,7 @@ class ZipFile: 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/concurrent/futures/_base.pyi b/stdlib/3/concurrent/futures/_base.pyi index fd04210936dc..6d454fbe8388 100644 --- a/stdlib/3/concurrent/futures/_base.pyi +++ b/stdlib/3/concurrent/futures/_base.pyi @@ -53,7 +53,7 @@ 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]]: ... diff --git a/stdlib/3/http/client.pyi b/stdlib/3/http/client.pyi index f4b5189d94d8..ee57f16a8f29 100644 --- a/stdlib/3/http/client.pyi +++ b/stdlib/3/http/client.pyi @@ -80,8 +80,7 @@ responses: Dict[int, str] class HTTPMessage(email.message.Message): ... -# Ignore errors to work around python/mypy#5027 -class HTTPResponse(io.BufferedIOBase, BinaryIO): # type: ignore +class HTTPResponse(io.BufferedIOBase, BinaryIO): msg: HTTPMessage headers: HTTPMessage version: int @@ -103,7 +102,7 @@ class HTTPResponse(io.BufferedIOBase, BinaryIO): # type: ignore def __enter__(self) -> HTTPResponse: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[types.TracebackType]) -> bool: ... + exc_tb: Optional[types.TracebackType]) -> Optional[bool]: ... def info(self) -> email.message.Message: ... def geturl(self) -> str: ... def getcode(self) -> int: ... diff --git a/stdlib/3/io.pyi b/stdlib/3/io.pyi index 5afbbcbf386e..900b77cc9831 100644 --- a/stdlib/3/io.pyi +++ b/stdlib/3/io.pyi @@ -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: ... @@ -86,7 +86,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: ... @@ -165,7 +165,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: ... diff --git a/stdlib/3/socketserver.pyi b/stdlib/3/socketserver.pyi index 22dda28b4f1d..2403614b4709 100644 --- a/stdlib/3/socketserver.pyi +++ b/stdlib/3/socketserver.pyi @@ -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: ... diff --git a/stdlib/3/subprocess.pyi b/stdlib/3/subprocess.pyi index 0e5df2c5094c..ef2aae4cbff5 100644 --- a/stdlib/3/subprocess.pyi +++ b/stdlib/3/subprocess.pyi @@ -1170,7 +1170,7 @@ class Popen(Generic[AnyStr]): 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 __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/tempfile.pyi b/stdlib/3/tempfile.pyi index e4aad54b4a03..c81187631b87 100644 --- a/stdlib/3/tempfile.pyi +++ b/stdlib/3/tempfile.pyi @@ -38,7 +38,7 @@ class SpooledTemporaryFile(IO[AnyStr]): def __enter__(self) -> SpooledTemporaryFile: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... + exc_tb: Optional[TracebackType]) -> Optional[bool]: ... # These methods are copied from the abstract methods of IO, because # SpooledTemporaryFile implements IO. @@ -69,7 +69,7 @@ class TemporaryDirectory(Generic[AnyStr]): def __enter__(self) -> AnyStr: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> bool: ... + exc_tb: Optional[TracebackType]) -> None: ... def mkstemp(suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., dir: Optional[AnyStr] = ..., text: bool = ...) -> Tuple[int, AnyStr]: ... diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 893dbffef624..42ebbf964284 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -479,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 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/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/third_party/2/concurrent/futures/_base.pyi b/third_party/2/concurrent/futures/_base.pyi index fd04210936dc..6d454fbe8388 100644 --- a/third_party/2/concurrent/futures/_base.pyi +++ b/third_party/2/concurrent/futures/_base.pyi @@ -53,7 +53,7 @@ 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]]: ... From fab2ee0d7c38dba0a5142924e53460548fdce0b0 Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Fri, 16 Aug 2019 20:29:32 -0700 Subject: [PATCH 112/201] Remove unnecessary quotes around forward references. (#3191) --- stdlib/2and3/argparse.pyi | 2 +- stdlib/2and3/cProfile.pyi | 2 +- stdlib/2and3/contextlib.pyi | 4 ++-- stdlib/2and3/distutils/version.pyi | 2 +- stdlib/2and3/profile.pyi | 2 +- stdlib/2and3/pstats.pyi | 2 +- stdlib/3/io.pyi | 2 +- stdlib/3/multiprocessing/pool.pyi | 2 +- stdlib/3/pathlib.pyi | 2 +- third_party/2/pathlib2.pyi | 2 +- third_party/2and3/pynamodb/attributes.pyi | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/stdlib/2and3/argparse.pyi b/stdlib/2and3/argparse.pyi index 03b9620d3225..b0f375dbedc0 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,): 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/contextlib.pyi b/stdlib/2and3/contextlib.pyi index a2b161ce85dc..948fcff7ae51 100644 --- a/stdlib/2and3/contextlib.pyi +++ b/stdlib/2and3/contextlib.pyi @@ -61,7 +61,7 @@ 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: ... @@ -79,7 +79,7 @@ if sys.version_info >= (3,): 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], 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/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/3/io.pyi b/stdlib/3/io.pyi index 900b77cc9831..acab18ca179c 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 diff --git a/stdlib/3/multiprocessing/pool.pyi b/stdlib/3/multiprocessing/pool.pyi index 469d83ad301a..2b0fbd078345 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') diff --git a/stdlib/3/pathlib.pyi b/stdlib/3/pathlib.pyi index fb06c65e0544..9ca20cd36fff 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] diff --git a/third_party/2/pathlib2.pyi b/third_party/2/pathlib2.pyi index fb06c65e0544..9ca20cd36fff 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] diff --git a/third_party/2and3/pynamodb/attributes.pyi b/third_party/2and3/pynamodb/attributes.pyi index 3c8247435cd7..6dca7cf8f8e4 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) class Attribute(Generic[_T]): attr_name: Optional[Text] From c0625d3280af888f2476279e484a873dd6d57a9a Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 17 Aug 2019 17:22:03 +0300 Subject: [PATCH 113/201] builtins: add __trunc__ to int and float (#3194) See: https://docs.python.org/3/reference/datamodel.html#object.__trunc__ It also works on Python 2.7. --- stdlib/2/__builtin__.pyi | 2 ++ stdlib/2and3/builtins.pyi | 2 ++ 2 files changed, 4 insertions(+) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index daadf8fb040c..4c94058b987d 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -183,6 +183,7 @@ class int: def __neg__(self) -> int: ... def __pos__(self) -> int: ... def __invert__(self) -> int: ... + def __trunc__(self) -> int: ... if sys.version_info >= (3,): def __round__(self, ndigits: Optional[int] = ...) -> int: ... def __getnewargs__(self) -> Tuple[int]: ... @@ -240,6 +241,7 @@ 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: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index daadf8fb040c..4c94058b987d 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -183,6 +183,7 @@ class int: def __neg__(self) -> int: ... def __pos__(self) -> int: ... def __invert__(self) -> int: ... + def __trunc__(self) -> int: ... if sys.version_info >= (3,): def __round__(self, ndigits: Optional[int] = ...) -> int: ... def __getnewargs__(self) -> Tuple[int]: ... @@ -240,6 +241,7 @@ 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: ... From c7417e8b3f2686571aa274df9151552564ed93cc Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 17 Aug 2019 17:23:04 +0300 Subject: [PATCH 114/201] builtins,numbers: harmonize float.__round__ and Real.__round__ (#3193) See: https://docs.python.org/3/reference/datamodel.html#object.__round__ https://docs.python.org/3/library/functions.html#round --- stdlib/2/__builtin__.pyi | 4 +--- stdlib/2and3/builtins.pyi | 4 +--- stdlib/2and3/numbers.pyi | 8 ++++++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 4c94058b987d..bab33c260a5d 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -244,9 +244,7 @@ class 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: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 4c94058b987d..bab33c260a5d 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -244,9 +244,7 @@ class 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: ... 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 From b2cd972b1760d850694772fe763e3027f131f223 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 17 Aug 2019 17:23:53 +0300 Subject: [PATCH 115/201] builtins: int.__pow__ can take a modulo argument (#3192) See: https://docs.python.org/3/reference/datamodel.html#object.__pow__ https://docs.python.org/3/library/functions.html#pow --- stdlib/2/__builtin__.pyi | 2 +- stdlib/2and3/builtins.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index bab33c260a5d..d73d97a6494e 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -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: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index bab33c260a5d..d73d97a6494e 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -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: ... From d5a918de7ba5d88d31d6377b372f112c29308de4 Mon Sep 17 00:00:00 2001 From: Bouteillebleu Date: Mon, 19 Aug 2019 14:34:29 +0100 Subject: [PATCH 116/201] Add stubs for CGIHTTPServer (#3196) This commit adds: * Stubs for CGIHTTPServer in the Python 2 standard library, as requested in #1147. * Stubs for six.moves.CGIHTTPServer in Python 2, as requested in #22. --- stdlib/2/CGIHTTPServer.pyi | 8 ++++++++ third_party/2/six/moves/CGIHTTPServer.pyi | 1 + third_party/2/six/moves/__init__.pyi | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 stdlib/2/CGIHTTPServer.pyi create mode 100644 third_party/2/six/moves/CGIHTTPServer.pyi 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/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 From e2520943548a4b6cbe09314509b5e33d575659af Mon Sep 17 00:00:00 2001 From: Alan Du Date: Mon, 19 Aug 2019 11:52:00 -0400 Subject: [PATCH 117/201] multiprocessing.Value can also take a Type (#3200) --- stdlib/3/multiprocessing/__init__.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/3/multiprocessing/__init__.pyi b/stdlib/3/multiprocessing/__init__.pyi index e5fad0a5afc9..f3bfdd566c34 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 ) +from ctypes import _CData from logging import Logger from multiprocessing import connection, pool, spawn, synchronize from multiprocessing.context import ( @@ -68,7 +69,7 @@ class Process(): 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: ... # ----- multiprocessing function stubs ----- From 1ab5145124ecc3af323f4ccbf210d25121d7c5a2 Mon Sep 17 00:00:00 2001 From: Michael Nix Date: Mon, 19 Aug 2019 18:33:19 +0200 Subject: [PATCH 118/201] adds threading related members to queue.pyi (#3198) --- stdlib/3/queue.pyi | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stdlib/3/queue.pyi b/stdlib/3/queue.pyi index 88605a358325..f6bafc04f0b7 100644 --- a/stdlib/3/queue.pyi +++ b/stdlib/3/queue.pyi @@ -3,6 +3,7 @@ # NOTE: These are incomplete! from collections import deque +from threading import Condition, Lock from typing import Any, TypeVar, Generic, Optional import sys @@ -13,6 +14,13 @@ class Full(Exception): ... class Queue(Generic[_T]): maxsize: int + + mutex: Lock # undocumented + not_empty: Condition # undocumented + not_full: Condition # undocumented + all_tasks_done: Condition # undocumented + unfinished_tasks: int # undocumented + queue: deque # undocumented def __init__(self, maxsize: int = ...) -> None: ... def _init(self, maxsize: int) -> None: ... From 72010bc5dcb402a8128a809daabd8a5b9f7b5628 Mon Sep 17 00:00:00 2001 From: Shannon Zhu Date: Mon, 19 Aug 2019 17:10:27 -0700 Subject: [PATCH 119/201] Update how mock classes alias to Any (#3182) * Update how mock classes alias to Any > First, the z: Any situation looks like a bug or accidental feature to me. This is definitely meant (and works) as a variable declaration; that it also allows using z as a type seems wrong. I can't find any evidence in PEP 484 that this was intended; in mypy it's likely the accidental result of other design choices meant to shut up errors about Any. Ideally these classes could be declared as empty class stubs, but since the comments suggest this isn't possible yet, let's update these to be type aliases to Any rather than global variables of type Any. This would avoid invalid type errors when the implementation of type checkers respect the intention that `z: Any` does not make `z` a valid type. * Update mock.pyi --- stdlib/3/unittest/mock.pyi | 10 +++++----- third_party/2and3/mock.pyi | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/stdlib/3/unittest/mock.pyi b/stdlib/3/unittest/mock.pyi index cb3db6198b41..8b20ea60217d 100644 --- a/stdlib/3/unittest/mock.pyi +++ b/stdlib/3/unittest/mock.pyi @@ -33,14 +33,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 +94,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 @@ -140,7 +140,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/mock.pyi b/third_party/2and3/mock.pyi index cb3db6198b41..8b20ea60217d 100644 --- a/third_party/2and3/mock.pyi +++ b/third_party/2and3/mock.pyi @@ -33,14 +33,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 +94,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 @@ -140,7 +140,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: ... From 75ccbdcab5637b1389b934b4385a87bbc97c9b92 Mon Sep 17 00:00:00 2001 From: Samuel Freilich Date: Fri, 23 Aug 2019 02:25:41 -0400 Subject: [PATCH 120/201] cadata param can (and PEM-encoded cadata must) be unicode under PY2 (#3150) --- stdlib/2and3/ssl.pyi | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/stdlib/2and3/ssl.pyi b/stdlib/2and3/ssl.pyi index 717c0edac005..2cfd1019e48d 100644 --- a/stdlib/2and3/ssl.pyi +++ b/stdlib/2and3/ssl.pyi @@ -1,7 +1,8 @@ # Stubs for ssl from typing import ( - Any, Callable, ClassVar, Dict, List, NamedTuple, Optional, Set, Tuple, Union, + Any, Callable, ClassVar, Dict, List, NamedTuple, Optional, Set, Text, Tuple, + Union, ) import enum import socket @@ -53,20 +54,19 @@ def create_default_context( *, cafile: Optional[str] = ..., capath: Optional[str] = ..., - cadata: Union[str, bytes, None] = ..., + cadata: Union[Text, bytes, None] = ..., ) -> 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: Union[str, bytes, None] = ...) -> SSLContext: ... - _create_default_https_context: Callable[..., 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: Union[Text, bytes, None] = ...) -> SSLContext: ... +_create_default_https_context: Callable[..., SSLContext] if sys.version_info >= (3, 3): def RAND_bytes(num: int) -> bytes: ... @@ -234,7 +234,7 @@ class SSLContext: self, cafile: Optional[str] = ..., capath: Optional[str] = ..., - cadata: Union[str, bytes, None] = ..., + 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: ... From 04bcb89aea991e45cffab05cb9520577dba9ad20 Mon Sep 17 00:00:00 2001 From: Scott Belden Date: Fri, 23 Aug 2019 02:31:40 -0400 Subject: [PATCH 121/201] create_server returns a Server, not AbstractServer (#3131) * remove create_unix_connection and use ABCMeta --- stdlib/3/asyncio/__init__.pyi | 5 ++++- stdlib/3/asyncio/base_events.pyi | 26 ++++++++------------------ 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/stdlib/3/asyncio/__init__.pyi b/stdlib/3/asyncio/__init__.pyi index c89d5f77b73b..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, diff --git a/stdlib/3/asyncio/base_events.pyi b/stdlib/3/asyncio/base_events.pyi index 373d8d87030b..6a80cbdec387 100644 --- a/stdlib/3/asyncio/base_events.pyi +++ b/stdlib/3/asyncio/base_events.pyi @@ -3,6 +3,7 @@ from socket import socket, _Address, _RetAddress import ssl import sys 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. @@ -76,18 +79,12 @@ class BaseEventLoop(AbstractEventLoop): 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: ... + 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 = ...) -> AbstractServer: ... - 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: ... - 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: ... + 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] = ..., *, @@ -112,21 +109,14 @@ class BaseEventLoop(AbstractEventLoop): family: int = ..., flags: int = ..., sock: None = ..., backlog: int = ..., ssl: _SSLContext = ..., reuse_address: Optional[bool] = ..., - reuse_port: Optional[bool] = ...) -> Generator[Any, None, AbstractServer]: ... + 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, 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]: ... + 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 From ce0f5b226fc00c732e5b6eb2a9fcb845cd18531c Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 22 Aug 2019 23:46:16 -0700 Subject: [PATCH 122/201] zipfile.ZipFile: Add start_dir attribute. (#3203) --- stdlib/2and3/zipfile.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/2and3/zipfile.pyi b/stdlib/2and3/zipfile.pyi index f5b8fab0edff..8003cce68da0 100644 --- a/stdlib/2and3/zipfile.pyi +++ b/stdlib/2and3/zipfile.pyi @@ -50,6 +50,7 @@ class ZipFile: 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: ... From 03b38d4d2eac6d2a7c8fae8e4542ba29dc9a1449 Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Fri, 23 Aug 2019 12:06:21 -0700 Subject: [PATCH 123/201] Add sys.flags.utf8_mode. (#3205) This is new in Python 3.7: https://docs.python.org/3/library/sys.html#sys.flags --- stdlib/3/sys.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/3/sys.pyi b/stdlib/3/sys.pyi index fa99bbb13be1..48644328d056 100644 --- a/stdlib/3/sys.pyi +++ b/stdlib/3/sys.pyi @@ -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: From 282405696e70cbfd2e21b38bacb08838ffd8f767 Mon Sep 17 00:00:00 2001 From: plokmijnuhby <39633434+plokmijnuhby@users.noreply.github.com> Date: Sat, 24 Aug 2019 17:06:38 +0100 Subject: [PATCH 124/201] Make inplace sorting require mutable sequences in bisect module (#3199) --- stdlib/2and3/_bisect.pyi | 8 ++++---- stdlib/2and3/bisect.pyi | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) 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/bisect.pyi b/stdlib/2and3/bisect.pyi index 5c541124ab58..04229284f71a 100644 --- a/stdlib/2and3/bisect.pyi +++ b/stdlib/2and3/bisect.pyi @@ -1,6 +1,6 @@ # Stubs for bisect -from typing import Any, Sequence, TypeVar +from typing import Any, Sequence, MutableSequence, TypeVar _T = TypeVar('_T') @@ -9,14 +9,14 @@ _T = TypeVar('_T') # 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 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: ... 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, x: Any, lo: int = ..., hi: int = ...) -> int: ... +def insort_right(a: MutableSequence, x: Any, lo: int = ..., hi: int = ...) -> int: ... +def insort(a: MutableSequence, x: Any, lo: int = ..., hi: int = ...) -> int: ... From 3e4a251b2b6da6bb43137acf5abf81ecfa7ba8ee Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 24 Aug 2019 23:30:14 +0300 Subject: [PATCH 125/201] doctest: fix type of DocTestParser.get_doctest(lineno) (#3206) Reference: https://docs.python.org/3/library/doctest.html#doctest.DocTest.lineno Also noticed a typo in get_examples() argument name. --- stdlib/2and3/doctest.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 = ..., From cd1a0c592a0faff50667214a601afe20b6fb5200 Mon Sep 17 00:00:00 2001 From: Jaromir Latal Date: Tue, 27 Aug 2019 15:34:22 +0200 Subject: [PATCH 126/201] Add typestubs for unittest.util (#3186) --- stdlib/3/unittest/util.pyi | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 stdlib/3/unittest/util.pyi 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]]: ... From a48abb4546bc2abb4c73d38839e98d43f5b8754d Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Wed, 28 Aug 2019 18:01:38 -0700 Subject: [PATCH 127/201] Add unquote_to_bytes to Python 3 six.moves.urllib.parse. (#3208) --- third_party/3/six/moves/urllib/parse.pyi | 1 + 1 file changed, 1 insertion(+) 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 From f53f52de572f01cc5f27c95defab4fe21ea526b0 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Wed, 28 Aug 2019 21:53:19 -0700 Subject: [PATCH 128/201] requests: Allow bytes for url parameters. (#3209) typeshed already partially reflected https://github.com/psf/requests/pull/2238 but not completely. --- third_party/2and3/requests/api.pyi | 12 ++++++------ third_party/2and3/requests/sessions.pyi | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/third_party/2and3/requests/api.pyi b/third_party/2and3/requests/api.pyi index df3003cfafc4..09c3d4f54ba1 100644 --- a/third_party/2and3/requests/api.pyi +++ b/third_party/2and3/requests/api.pyi @@ -32,9 +32,9 @@ def get(url: Union[_Text, bytes], 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 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/sessions.pyi b/third_party/2and3/requests/sessions.pyi index db275ae4e6b3..0676367c5847 100644 --- a/third_party/2and3/requests/sessions.pyi +++ b/third_party/2and3/requests/sessions.pyi @@ -79,7 +79,7 @@ class Session(SessionRedirectMixin): 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]] = ..., From d78747c0f01b7656d9a34be7afc13ac68fd7560c Mon Sep 17 00:00:00 2001 From: Andriy Teraz Date: Thu, 29 Aug 2019 18:38:53 +0300 Subject: [PATCH 129/201] Make target optional in contextlib redirecting managers (#3212) Fixes #3210 --- stdlib/2and3/contextlib.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/2and3/contextlib.pyi b/stdlib/2and3/contextlib.pyi index 948fcff7ae51..ab11501403b9 100644 --- a/stdlib/2and3/contextlib.pyi +++ b/stdlib/2and3/contextlib.pyi @@ -51,11 +51,11 @@ if sys.version_info >= (3, 4): 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: From ae881faaf1ecc8190fd2f88c197c75e2ca5725de Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Thu, 29 Aug 2019 17:51:59 +0200 Subject: [PATCH 130/201] Remove custom _Text type (#3211) * Remove custom _Text type Since the custom type was only used in argument types, it was effectively only an alias for typing.Text. * Run requests/api.pyi through black --- third_party/2and3/requests/api.pyi | 54 +++++++++++++----------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/third_party/2and3/requests/api.pyi b/third_party/2and3/requests/api.pyi index 09c3d4f54ba1..e6f3417c2b13 100644 --- a/third_party/2and3/requests/api.pyi +++ b/third_party/2and3/requests/api.pyi @@ -5,36 +5,28 @@ from typing import Optional, Union, Any, Iterable, Mapping, MutableMapping, Tupl from .models import Response -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]]] +_Data = Union[None, Text, bytes, MutableMapping[str, Any], MutableMapping[Text, Any], Iterable[Tuple[Text, Optional[Text]]], IO] 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: 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: ... +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: ... From 99e8ed42a4734adfe1a964f5734eed2d3af1a7fc Mon Sep 17 00:00:00 2001 From: Colin Gilgenbach Date: Thu, 29 Aug 2019 11:57:43 -0400 Subject: [PATCH 131/201] Mark ParamType.fail() as NoReturn (#3213) This function just raises a click.BadParameter exception with the supplied arguments. --- third_party/2and3/click/core.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/2and3/click/core.pyi b/third_party/2and3/click/core.pyi index fa2413d69e3e..68308ffc3e8a 100644 --- a/third_party/2and3/click/core.pyi +++ b/third_party/2and3/click/core.pyi @@ -351,7 +351,7 @@ 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: ... From f9300ed1ed89ee75d82e22b33f0d22be0fd65d37 Mon Sep 17 00:00:00 2001 From: Shannon Zhu Date: Fri, 30 Aug 2019 16:15:24 -0700 Subject: [PATCH 132/201] Update pyre_extensions stub (#3214) --- third_party/2and3/pyre_extensions.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/third_party/2and3/pyre_extensions.pyi b/third_party/2and3/pyre_extensions.pyi index 04adc5093f13..c6c4fd8690b9 100644 --- a/third_party/2and3/pyre_extensions.pyi +++ b/third_party/2and3/pyre_extensions.pyi @@ -1,6 +1,7 @@ -from typing import List, Optional, Type, TypeVar +from typing import Any, List, Optional, Type, TypeVar _T = TypeVar("_T") -def none_throws(optional: Optional[_T]) -> _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]: ... From abc241bd35f7c98277c204255f2489538b1304c1 Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Sat, 31 Aug 2019 02:25:44 -0700 Subject: [PATCH 133/201] Use Literal to improve tempfile.[Named]TemporaryFile. (#3215) --- stdlib/3/tempfile.pyi | 78 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 11 deletions(-) diff --git a/stdlib/3/tempfile.pyi b/stdlib/3/tempfile.pyi index c81187631b87..9aaa72ce1450 100644 --- a/stdlib/3/tempfile.pyi +++ b/stdlib/3/tempfile.pyi @@ -7,24 +7,80 @@ import sys from types import TracebackType from typing import Any, AnyStr, Generic, IO, Iterable, Iterator, List, Optional, overload, Tuple, Type +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 - +@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[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[AnyStr] = ..., +) -> IO[bytes]: ... +@overload def TemporaryFile( - mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., - newline: Optional[str] = ..., suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., - dir: Optional[AnyStr] = ... -) -> IO[Any]: - ... + mode: str = ..., + buffering: int = ..., + encoding: Optional[str] = ..., + newline: Optional[str] = ..., + suffix: Optional[AnyStr] = ..., + prefix: Optional[AnyStr] = ..., + dir: Optional[AnyStr] = ..., +) -> IO[Any]: ... + +@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[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[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[AnyStr] = ..., delete: bool = ... -) -> IO[Any]: - ... + 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. From b94fa842eba642c73c25ec8cd33cd6bce1a8dc76 Mon Sep 17 00:00:00 2001 From: Pascal Corpet Date: Tue, 3 Sep 2019 11:12:11 +0200 Subject: [PATCH 134/201] Type response of Flask test client methods: get, post, etc. (#2904) --- third_party/2and3/flask/app.pyi | 2 +- third_party/2and3/flask/testing.pyi | 10 +++- third_party/2and3/werkzeug/test.pyi | 86 ++++++++++++++++++++++++----- 3 files changed, 81 insertions(+), 17 deletions(-) diff --git a/third_party/2and3/flask/app.pyi b/third_party/2and3/flask/app.pyi index 308367d5ff70..654d41c1f07f 100644 --- a/third_party/2and3/flask/app.pyi +++ b/third_party/2and3/flask/app.pyi @@ -127,7 +127,7 @@ 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): ... diff --git a/third_party/2and3/flask/testing.pyi b/third_party/2and3/flask/testing.pyi index 813eeca4d27e..4c562e5801f3 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, Union, TypeVar 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: ... 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 = ...): ... From 1d213157733fe0033aee655780e5df1d93308021 Mon Sep 17 00:00:00 2001 From: Daniel Holth Date: Tue, 3 Sep 2019 06:10:48 -0400 Subject: [PATCH 135/201] ssl.pyi: Add functions, support Path (#3044) --- stdlib/2and3/ssl.pyi | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/stdlib/2and3/ssl.pyi b/stdlib/2and3/ssl.pyi index 2cfd1019e48d..83717d00c66d 100644 --- a/stdlib/2and3/ssl.pyi +++ b/stdlib/2and3/ssl.pyi @@ -1,12 +1,12 @@ # Stubs for ssl from typing import ( - Any, Callable, ClassVar, Dict, List, NamedTuple, Optional, Set, Text, 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, ...] @@ -15,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: @@ -227,7 +232,7 @@ class SSLContext: else: def __init__(self, protocol: int) -> None: ... def cert_store_stats(self) -> Dict[str, int]: ... - def load_cert_chain(self, certfile: str, keyfile: Optional[str] = ..., + def load_cert_chain(self, certfile: _Path, keyfile: Optional[_Path] = ..., password: _PasswordType = ...) -> None: ... def load_default_certs(self, purpose: Purpose = ...) -> None: ... def load_verify_locations( @@ -240,6 +245,9 @@ class SSLContext: def set_default_verify_paths(self) -> None: ... def set_ciphers(self, ciphers: 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: ... From efb4af0108fcdb556af52897f33de8afaa0d0e36 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 4 Sep 2019 17:38:09 +0200 Subject: [PATCH 136/201] Mark some types as non-hashable (#3219) Based on @JelleZijlstra's PR #2221. Fixes #2148 --- stdlib/2/__builtin__.pyi | 7 ++++-- stdlib/2and3/builtins.pyi | 7 ++++-- third_party/2and3/werkzeug/datastructures.pyi | 24 +++++++++---------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index d73d97a6494e..e19b65c2e4f9 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -734,7 +734,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 @@ -849,6 +849,7 @@ class slice(object): def __init__(self, stop: Any) -> None: ... @overload 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]): @@ -906,7 +907,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 @@ -980,6 +981,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: ... @@ -1016,6 +1018,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: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index d73d97a6494e..e19b65c2e4f9 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -734,7 +734,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 @@ -849,6 +849,7 @@ class slice(object): def __init__(self, stop: Any) -> None: ... @overload 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]): @@ -906,7 +907,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 @@ -980,6 +981,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: ... @@ -1016,6 +1018,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: ... diff --git a/third_party/2and3/werkzeug/datastructures.pyi b/third_party/2and3/werkzeug/datastructures.pyi index 7ee49dda7021..63a04227db7c 100644 --- a/third_party/2and3/werkzeug/datastructures.pyi +++ b/third_party/2and3/werkzeug/datastructures.pyi @@ -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] = ...): ... @@ -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]: ... @@ -207,7 +207,7 @@ class EnvironHeaders(ImmutableHeadersMixin, Headers): def __iter__(self): ... def copy(self): ... -class CombinedMultiDict(ImmutableMultiDictMixin, MultiDict): +class CombinedMultiDict(ImmutableMultiDictMixin, MultiDict): # type: ignore def __reduce_ex__(self, protocol): ... dicts: Any def __init__(self, dicts: Optional[Any] = ...): ... @@ -231,15 +231,15 @@ class CombinedMultiDict(ImmutableMultiDictMixin, MultiDict): class FileMultiDict(MultiDict): def add_file(self, name, file, filename: Optional[Any] = ..., content_type: Optional[Any] = ...): ... -class ImmutableDict(ImmutableDictMixin, dict): +class ImmutableDict(ImmutableDictMixin, dict): # type: ignore def copy(self): ... def __copy__(self): ... -class ImmutableMultiDict(ImmutableMultiDictMixin, MultiDict): +class ImmutableMultiDict(ImmutableMultiDictMixin, MultiDict): # type: ignore def copy(self): ... def __copy__(self): ... -class ImmutableOrderedMultiDict(ImmutableMultiDictMixin, OrderedMultiDict): +class ImmutableOrderedMultiDict(ImmutableMultiDictMixin, OrderedMultiDict): # type: ignore def copy(self): ... def __copy__(self): ... @@ -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 @@ -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 From 3fc8aec4255514436545b80245c13faf10c432a1 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Wed, 4 Sep 2019 14:24:58 -0700 Subject: [PATCH 137/201] Allow passing str to Python 2's bytearray.extend. (#3223) --- stdlib/2/__builtin__.pyi | 2 ++ stdlib/2and3/builtins.pyi | 2 ++ 2 files changed, 4 insertions(+) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index e19b65c2e4f9..680f1fd7b06a 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -667,6 +667,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): diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index e19b65c2e4f9..680f1fd7b06a 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -667,6 +667,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): From 668988fa8cfd106a73218b23f953f226db89b3d4 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Thu, 5 Sep 2019 16:59:59 +0200 Subject: [PATCH 138/201] Return concrete sets from ItemsView and KeysView (#3181) --- stdlib/3/typing.pyi | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 42ebbf964284..3d36ce2736a7 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -335,28 +335,28 @@ 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[object]) -> 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[object]) -> 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[object]) -> 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[object]) -> 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: ... From c9f19b1d725a154388918f0c2af4a9b624c633bd Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Tue, 10 Sep 2019 23:40:10 +0200 Subject: [PATCH 139/201] Use protocol for FTP.stor* (#3227) * Use protocol for FTP.stor* * Reformat ftplib.pyi with black --- stdlib/2and3/ftplib.pyi | 94 +++++++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 27 deletions(-) diff --git a/stdlib/2and3/ftplib.pyi b/stdlib/2and3/ftplib.pyi index 9222ff6556d3..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]) -> None: ... + 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: ... From 686e21d330ce9a2ca16fb925554fd5eba082fb8f Mon Sep 17 00:00:00 2001 From: jjmortensen Date: Wed, 11 Sep 2019 17:00:25 +0200 Subject: [PATCH 140/201] Fix type in argparse.HelpFormatter._fill_text() (#3229) --- stdlib/2and3/argparse.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/2and3/argparse.pyi b/stdlib/2and3/argparse.pyi index b0f375dbedc0..2c33cac7122d 100644 --- a/stdlib/2and3/argparse.pyi +++ b/stdlib/2and3/argparse.pyi @@ -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: ... From 5ccf017ca06a83511df49143226757d3bb7a33d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E8=91=89?= Date: Thu, 12 Sep 2019 00:20:40 +0800 Subject: [PATCH 141/201] fix: Add MapResult type (#3228) --- stdlib/3/multiprocessing/pool.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/3/multiprocessing/pool.pyi b/stdlib/3/multiprocessing/pool.pyi index 2b0fbd078345..fe1045d0a4d8 100644 --- a/stdlib/3/multiprocessing/pool.pyi +++ b/stdlib/3/multiprocessing/pool.pyi @@ -17,6 +17,8 @@ class ApplyResult(Generic[_T]): # alias created during issue #17805 AsyncResult = ApplyResult +class MapResult(ApplyResult[List[_T]]): ... + _IMIT = TypeVar('_IMIT', bound=IMapIterator) class IMapIterator(Iterator[_T]): @@ -50,7 +52,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] = ..., From 8d053f139ffbc648a38fed1252be30bc86383f4f Mon Sep 17 00:00:00 2001 From: plokmijnuhby <39633434+plokmijnuhby@users.noreply.github.com> Date: Wed, 11 Sep 2019 17:24:36 +0100 Subject: [PATCH 142/201] Change SyncManager behaviour when used as a context decorator (#3230) Resolves #3018. --- stdlib/3/multiprocessing/managers.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/multiprocessing/managers.pyi b/stdlib/3/multiprocessing/managers.pyi index ceabefbd8223..7c19b1d2035f 100644 --- a/stdlib/3/multiprocessing/managers.pyi +++ b/stdlib/3/multiprocessing/managers.pyi @@ -37,7 +37,7 @@ 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: ... From 2b97bb904af4d7120243beb6ebf5ce0e4bc85041 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Wed, 11 Sep 2019 17:39:41 -0500 Subject: [PATCH 143/201] Add AIFC module stubs (#3075) --- stdlib/2and3/aifc.pyi | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 stdlib/2and3/aifc.pyi 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: ... From 2edb36e9935ee725d5424b0fc5984e7421d7fe40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E8=91=89?= Date: Sun, 15 Sep 2019 22:06:19 +0800 Subject: [PATCH 144/201] Add ThreadingHTTPServer stub (#3232) Fixes #3217 --- stdlib/3/http/server.pyi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stdlib/3/http/server.pyi b/stdlib/3/http/server.pyi index 7a7729f87275..dd3118e9fb77 100644 --- a/stdlib/3/http/server.pyi +++ b/stdlib/3/http/server.pyi @@ -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 From d0f3eb2d6bababd8c9591b7260b050573f429c3b Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 16 Sep 2019 14:36:28 +0100 Subject: [PATCH 145/201] Use Text for text arguments to click.[un]style (#3233) --- third_party/2and3/click/termui.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/third_party/2and3/click/termui.pyi b/third_party/2and3/click/termui.pyi index 1f838eb5787f..d34963bcb1bb 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, @@ -112,7 +113,7 @@ def clear() -> None: def style( - text: str, + text: Text, fg: Optional[str] = ..., bg: Optional[str] = ..., bold: Optional[bool] = ..., @@ -125,7 +126,7 @@ def style( ... -def unstyle(text: str) -> str: +def unstyle(text: Text) -> str: ... From 895ae0fd9b1778ffc5ce8b370a47603b2f426e79 Mon Sep 17 00:00:00 2001 From: Alex Garbutt Date: Mon, 16 Sep 2019 13:16:52 -0700 Subject: [PATCH 146/201] requests.Session.request data arg accepts an iterable of tuples (#3237) --- third_party/2and3/requests/api.pyi | 2 +- third_party/2and3/requests/sessions.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/2and3/requests/api.pyi b/third_party/2and3/requests/api.pyi index e6f3417c2b13..1f994aa9192c 100644 --- a/third_party/2and3/requests/api.pyi +++ b/third_party/2and3/requests/api.pyi @@ -4,9 +4,9 @@ import sys from typing import Optional, Union, Any, Iterable, Mapping, MutableMapping, Tuple, IO, Text from .models import Response +from .sessions import _Data _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] def request(method: str, url: str, **kwargs) -> Response: ... def get( diff --git a/third_party/2and3/requests/sessions.pyi b/third_party/2and3/requests/sessions.pyi index 0676367c5847..a0f476009fff 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]] From babc0c19124bbbd51a59c84e674b778bd9101490 Mon Sep 17 00:00:00 2001 From: Brad Date: Tue, 17 Sep 2019 05:30:00 -0400 Subject: [PATCH 147/201] Accept bytes to several Redis client commands (#3238) --- third_party/2and3/redis/client.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/third_party/2and3/redis/client.pyi b/third_party/2and3/redis/client.pyi index c180df4254fe..ea692bb1a818 100644 --- a/third_party/2and3/redis/client.pyi +++ b/third_party/2and3/redis/client.pyi @@ -119,9 +119,9 @@ class Redis(object): def dump(self, name): ... def exists(self, name): ... __contains__: Any - def expire(self, name: Text, time: Union[int, timedelta]) -> bool: ... + def expire(self, name: Union[Text, bytes], time: Union[int, timedelta]) -> bool: ... def expireat(self, name, when): ... - def get(self, name: Text) -> Optional[bytes]: ... + def get(self, name: Union[Text, bytes]) -> Optional[bytes]: ... def __getitem__(self, name): ... def getbit(self, name, offset): ... def getrange(self, key, start, end): ... @@ -145,7 +145,7 @@ class Redis(object): def restore(self, name, ttl, value): ... def set( self, - name: Text, + name: Union[Text, bytes], value: _Str, ex: Union[None, int, timedelta] = ..., px: Union[None, int, timedelta] = ..., From 4c63939585f128ccbc3acd31665c7b1c79ea6165 Mon Sep 17 00:00:00 2001 From: Augusto Hack Date: Tue, 17 Sep 2019 13:15:27 +0200 Subject: [PATCH 148/201] setprofile accepts None (#3239) The function `threading.setprofile` can be called with a `None` value to clear the profile function. This does unset the function from the existing threads, it only clears the callback function so that new threads are created without the profiling hook installed. --- stdlib/2and3/threading.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/2and3/threading.pyi b/stdlib/2and3/threading.pyi index 63f838f3df4d..b5d8f0d3569d 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,): From ce0dc8a23de46e7c729904158d73c0132ce812cd Mon Sep 17 00:00:00 2001 From: Philippe F Date: Tue, 17 Sep 2019 23:24:42 +0200 Subject: [PATCH 149/201] Add proper support for __rtruediv__ on libpath.Path (#3236) --- stdlib/3/pathlib.pyi | 2 ++ third_party/2/pathlib2.pyi | 2 ++ 2 files changed, 4 insertions(+) diff --git a/stdlib/3/pathlib.pyi b/stdlib/3/pathlib.pyi index 9ca20cd36fff..ff6bedd1c043 100644 --- a/stdlib/3/pathlib.pyi +++ b/stdlib/3/pathlib.pyi @@ -32,8 +32,10 @@ class PurePath(_PurePathBase): def __ge__(self, other: PurePath) -> bool: ... 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: ... diff --git a/third_party/2/pathlib2.pyi b/third_party/2/pathlib2.pyi index 9ca20cd36fff..ff6bedd1c043 100644 --- a/third_party/2/pathlib2.pyi +++ b/third_party/2/pathlib2.pyi @@ -32,8 +32,10 @@ class PurePath(_PurePathBase): def __ge__(self, other: PurePath) -> bool: ... 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: ... From 8b28753b64ee6e757be068333b41db2f84d1928e Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Tue, 17 Sep 2019 20:48:27 -0600 Subject: [PATCH 150/201] Update and improve py_compile module stubs. (#3240) --- stdlib/2and3/py_compile.pyi | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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: ... From 9488b58fb39700b5852da823011d38ed4d272f53 Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Wed, 18 Sep 2019 02:04:53 -0700 Subject: [PATCH 151/201] Copy a better definition of abstractmethod from 3/abc to 2/abc. (#3242) --- stdlib/2/abc.pyi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stdlib/2/abc.pyi b/stdlib/2/abc.pyi index 746f5306fcd6..e5fe035f2cba 100644 --- a/stdlib/2/abc.pyi +++ b/stdlib/2/abc.pyi @@ -1,9 +1,11 @@ -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 From 0602840cc2df1f67805f8ab62f4aa777e566cfc6 Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Wed, 18 Sep 2019 02:05:49 -0700 Subject: [PATCH 152/201] Make the type of `timeout` Optional[float] everywhere in subprocess. (#3241) --- stdlib/3/subprocess.pyi | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/stdlib/3/subprocess.pyi b/stdlib/3/subprocess.pyi index ef2aae4cbff5..c3126dd62fe6 100644 --- a/stdlib/3/subprocess.pyi +++ b/stdlib/3/subprocess.pyi @@ -451,7 +451,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, @@ -471,7 +471,7 @@ 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 @@ -493,7 +493,7 @@ 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] = ..., @@ -517,7 +517,7 @@ if sys.version_info >= (3, 7): start_new_session: bool = ..., pass_fds: Any = ..., *, - timeout: float = ..., + timeout: Optional[float] = ..., input: _TXT = ..., encoding: str, errors: Optional[str] = ..., @@ -541,7 +541,7 @@ if sys.version_info >= (3, 7): start_new_session: bool = ..., pass_fds: Any = ..., *, - timeout: float = ..., + timeout: Optional[float] = ..., input: _TXT = ..., encoding: Optional[str] = ..., errors: str, @@ -566,7 +566,7 @@ if sys.version_info >= (3, 7): start_new_session: bool = ..., pass_fds: Any = ..., # where the real keyword only ones start - timeout: float = ..., + timeout: Optional[float] = ..., input: _TXT = ..., encoding: Optional[str] = ..., errors: Optional[str] = ..., @@ -590,7 +590,7 @@ if sys.version_info >= (3, 7): start_new_session: bool = ..., pass_fds: Any = ..., *, - timeout: float = ..., + timeout: Optional[float] = ..., input: _TXT = ..., encoding: None = ..., errors: None = ..., @@ -614,7 +614,7 @@ 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] = ..., @@ -640,7 +640,7 @@ 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] = ..., @@ -663,7 +663,7 @@ elif sys.version_info >= (3, 6): start_new_session: bool = ..., pass_fds: Any = ..., *, - timeout: float = ..., + timeout: Optional[float] = ..., input: _TXT = ..., encoding: Optional[str] = ..., errors: str, @@ -686,7 +686,7 @@ elif sys.version_info >= (3, 6): pass_fds: Any = ..., *, universal_newlines: Literal[True], - timeout: float = ..., + timeout: Optional[float] = ..., input: _TXT = ..., encoding: Optional[str] = ..., errors: Optional[str] = ..., @@ -709,7 +709,7 @@ elif sys.version_info >= (3, 6): start_new_session: bool = ..., pass_fds: Any = ..., *, - timeout: float = ..., + timeout: Optional[float] = ..., input: _TXT = ..., encoding: None = ..., errors: None = ..., @@ -732,7 +732,7 @@ elif sys.version_info >= (3, 6): start_new_session: bool = ..., pass_fds: Any = ..., *, - timeout: float = ..., + timeout: Optional[float] = ..., input: _TXT = ..., encoding: Optional[str] = ..., errors: Optional[str] = ..., @@ -754,7 +754,7 @@ else: restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., - timeout: float = ..., + timeout: Optional[float] = ..., input: _TXT = ..., *, universal_newlines: Literal[True], @@ -776,7 +776,7 @@ else: restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., - timeout: float = ..., + timeout: Optional[float] = ..., input: _TXT = ..., ) -> bytes: ... @overload @@ -796,7 +796,7 @@ else: restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., - timeout: float = ..., + timeout: Optional[float] = ..., input: _TXT = ..., ) -> Any: ... # morally: -> _TXT From 4d662f0f49f8429ea1367344c90a16e9514d9704 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Thu, 19 Sep 2019 18:49:38 +0300 Subject: [PATCH 153/201] Stubs for maxminddb added (#3245) --- third_party/3/maxminddb/__init__.pyi | 9 +++++++ third_party/3/maxminddb/compat.pyi | 10 ++++++++ third_party/3/maxminddb/const.pyi | 8 ++++++ third_party/3/maxminddb/decoder.pyi | 7 ++++++ third_party/3/maxminddb/errors.pyi | 3 +++ third_party/3/maxminddb/extension.pyi | 35 +++++++++++++++++++++++++++ third_party/3/maxminddb/reader.pyi | 31 ++++++++++++++++++++++++ 7 files changed, 103 insertions(+) create mode 100644 third_party/3/maxminddb/__init__.pyi create mode 100644 third_party/3/maxminddb/compat.pyi create mode 100644 third_party/3/maxminddb/const.pyi create mode 100644 third_party/3/maxminddb/decoder.pyi create mode 100644 third_party/3/maxminddb/errors.pyi create mode 100644 third_party/3/maxminddb/extension.pyi create mode 100644 third_party/3/maxminddb/reader.pyi 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..4a963a65c8ec --- /dev/null +++ b/third_party/3/maxminddb/reader.pyi @@ -0,0 +1,31 @@ +# Stubs for maxminddb.reader (Python 3) + +from ipaddress import IPv4Address, IPv6Address + +from types import TracebackType +from typing import Any, Mapping, Optional, Sequence, Type, Union + +class Reader: + closed: bool = ... + def __init__(self, database: bytes, mode: int = ...) -> None: ... + def metadata(self) -> Metadata: ... + def get(self, ip_address: str) -> Optional[Any]: ... + 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: ... From c65b5cc61c00ef082236855534b7cdf762585fda Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Mon, 23 Sep 2019 09:23:46 -0700 Subject: [PATCH 154/201] Changed combine method in datetime to use aliased _date and _time types (like all other methods in this class) to avoid namespace collision with date and time methods. (#3251) --- stdlib/2and3/datetime.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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: ... From a011d1945e22a79f9efede8ba0af73b25044941a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E8=91=89?= Date: Tue, 24 Sep 2019 00:24:05 +0800 Subject: [PATCH 155/201] add missing errnos (#3254) --- stdlib/2and3/errno.pyi | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 From c879ff05aac14e15a5e3982c0975ae7ab341fd60 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Mon, 23 Sep 2019 09:24:45 -0700 Subject: [PATCH 156/201] Changed type of fieldname parameter in DictWriter __init__ method from Sequence[str] to Iterable[str]. This allows it to work with the following code: (#3253) --- stdlib/2and3/csv.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: ... From 01b7002a89c2d484c1cac05e3d89808050fa7459 Mon Sep 17 00:00:00 2001 From: sinancepel Date: Mon, 23 Sep 2019 09:25:49 -0700 Subject: [PATCH 157/201] Introduce explicit `__str__` and `__repr__` for Exceptions (#3247) --- stdlib/2/__builtin__.pyi | 2 ++ stdlib/2and3/builtins.pyi | 2 ++ 2 files changed, 4 insertions(+) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 680f1fd7b06a..ecaaf42076f3 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -1475,6 +1475,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, ...]: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 680f1fd7b06a..ecaaf42076f3 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -1475,6 +1475,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, ...]: ... From c1ec292344dc35f345d885ddb1823538f1311e49 Mon Sep 17 00:00:00 2001 From: Augusto Hack Date: Mon, 23 Sep 2019 18:48:13 +0200 Subject: [PATCH 158/201] Added missing top-level export to click (#3256) --- third_party/2and3/click/__init__.pyi | 2 ++ 1 file changed, 2 insertions(+) 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, From 829c646d69df26b9adf420ea7494417ffc596fdb Mon Sep 17 00:00:00 2001 From: Augusto Hack Date: Mon, 23 Sep 2019 20:40:54 +0200 Subject: [PATCH 159/201] Added constructor types for click.FloatRange (#3257) --- third_party/2and3/click/types.pyi | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/third_party/2and3/click/types.pyi b/third_party/2and3/click/types.pyi index 7f1e0ba8f324..dc1e787568bf 100644 --- a/third_party/2and3/click/types.pyi +++ b/third_party/2and3/click/types.pyi @@ -71,7 +71,13 @@ class FloatParamType(ParamType): class FloatRange(FloatParamType): - ... + def __init__( + self, + min: Optional[float] = ..., + max: Optional[float] = ..., + clamp: bool = ..., + ) -> None: + ... class File(ParamType): From 3f8c2169d1a53ba5ff2bcfaf1212ccb3a8258299 Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Mon, 23 Sep 2019 14:41:05 -0700 Subject: [PATCH 160/201] Define listdir in posix and import it in os. (#3258) --- stdlib/2/os/__init__.pyi | 3 +-- stdlib/2/posix.pyi | 7 ++++--- stdlib/3/os/__init__.pyi | 19 +------------------ stdlib/3/posix.pyi | 22 +++++++++++++++++++++- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/stdlib/2/os/__init__.pyi b/stdlib/2/os/__init__.pyi index da2a35dd1f95..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, @@ -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/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/3/os/__init__.pyi b/stdlib/3/os/__init__.pyi index 2a9656a3de10..458fc75c1952 100644 --- a/stdlib/3/os/__init__.pyi +++ b/stdlib/3/os/__init__.pyi @@ -2,7 +2,7 @@ # Ron Murawski from io import TextIOWrapper as _TextIOWrapper -from posix import times_result +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, @@ -434,23 +434,6 @@ def link( follow_symlinks: bool = ..., ) -> 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]: ... -else: - @overload - def listdir(path: Optional[str] = ...) -> List[str]: ... - @overload - def listdir(path: bytes) -> List[bytes]: ... - @overload - def listdir(path: int) -> List[str]: ... - 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': diff --git a/stdlib/3/posix.pyi b/stdlib/3/posix.pyi index a24001d7fe7d..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), @@ -109,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]: ... From c33239b011f777ac78f0e4df3acb9655be4d8e09 Mon Sep 17 00:00:00 2001 From: Colin Gilgenbach Date: Tue, 24 Sep 2019 08:11:25 -0400 Subject: [PATCH 161/201] click: Support tuples of _ParamTypes, CliRunner fixes (#3259) --- third_party/2and3/click/core.pyi | 3 ++- third_party/2and3/click/testing.pyi | 4 ++-- third_party/2and3/flask/testing.pyi | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/third_party/2and3/click/core.pyi b/third_party/2and3/click/core.pyi index 68308ffc3e8a..ea3ef550a55b 100644 --- a/third_party/2and3/click/core.pyi +++ b/third_party/2and3/click/core.pyi @@ -356,7 +356,8 @@ class _ParamType: # 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/testing.pyi b/third_party/2and3/click/testing.pyi index 6b16df9b2d39..bffe29eb83e0 100644 --- a/third_party/2and3/click/testing.pyi +++ b/third_party/2and3/click/testing.pyi @@ -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]] = ..., 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]] = ..., env: Optional[Mapping[str, str]] = ..., catch_exceptions: bool = ..., color: bool = ..., diff --git a/third_party/2and3/flask/testing.pyi b/third_party/2and3/flask/testing.pyi index 4c562e5801f3..79459287c224 100644 --- a/third_party/2and3/flask/testing.pyi +++ b/third_party/2and3/flask/testing.pyi @@ -4,7 +4,7 @@ from click import BaseCommand from click.testing import CliRunner, Result -from typing import Any, IO, Iterable, Mapping, Optional, Union, TypeVar +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): ... @@ -29,7 +29,7 @@ class FlaskCliRunner(CliRunner): self, cli: Optional[BaseCommand] = ..., args: Optional[Union[str, Iterable[str]]] = ..., - input: Optional[IO] = ..., + input: Optional[Union[bytes, IO, Text]] = ..., env: Optional[Mapping[str, str]] = ..., catch_exceptions: bool = ..., color: bool = ..., From e0cc8bdafb7fd7fca3b08ca20a7c25ac389dec0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81rni=20M=C3=A1r=20J=C3=B3nsson?= Date: Thu, 26 Sep 2019 15:13:00 +0000 Subject: [PATCH 162/201] inspect.Traceback/FrameInfo index/code_context attributes now Optional[] (#3265) Resolves #3264 --- stdlib/2/inspect.pyi | 6 +++--- stdlib/3/inspect.pyi | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/stdlib/2/inspect.pyi b/stdlib/2/inspect.pyi index a7ad5029c4db..4e157dca7cd8 100644 --- a/stdlib/2/inspect.pyi +++ b/stdlib/2/inspect.pyi @@ -109,12 +109,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/3/inspect.pyi b/stdlib/3/inspect.pyi index 737b22896e53..cd3ae936440e 100644 --- a/stdlib/3/inspect.pyi +++ b/stdlib/3/inspect.pyi @@ -258,8 +258,8 @@ Traceback = NamedTuple( ('filename', str), ('lineno', int), ('function', str), - ('code_context', List[str]), - ('index', int), + ('code_context', Optional[List[str]]), + ('index', Optional[int]), ] ) @@ -268,8 +268,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: ... From efdbefee86ff1e4c7597f939ca044fbd5b4b0733 Mon Sep 17 00:00:00 2001 From: Alex Jurkiewicz Date: Fri, 27 Sep 2019 15:04:23 +1000 Subject: [PATCH 163/201] Add return types for pymysql.connection.close/cursor (#3268) --- third_party/2and3/pymysql/connections.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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): ... From d1ed2b275fe2a4361dd501c6fa05b66e125805d2 Mon Sep 17 00:00:00 2001 From: brianjyoung <40139733+brianjyoung@users.noreply.github.com> Date: Fri, 27 Sep 2019 04:28:08 -0700 Subject: [PATCH 164/201] Updated logging type stub (#3269) --- stdlib/2and3/logging/__init__.pyi | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/stdlib/2and3/logging/__init__.pyi b/stdlib/2and3/logging/__init__.pyi index 290f62000ec2..32b2f117db8b 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, @@ -18,7 +18,10 @@ else: _ExcInfoType = Union[None, bool, _SysExcInfoType] _ArgsType = Union[Tuple[Any, ...], Mapping[str, Any]] _FilterType = Union[Filter, Callable[[LogRecord], int]] -_Level = Union[int, Text] +if sys.version_info >= (3, 2): + _Level = Union[int, Text] +else: + _Level = int if sys.version_info >= (3, 6): from os import PathLike _Path = Union[str, PathLike[str]] @@ -53,7 +56,7 @@ 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 setLevel(self, level: _Level) -> None: ... def isEnabledFor(self, level: int) -> bool: ... def getEffectiveLevel(self) -> int: ... def getChild(self, suffix: str) -> Logger: ... @@ -154,7 +157,7 @@ class Handler(Filterer): def createLock(self) -> None: ... def acquire(self) -> None: ... def release(self) -> None: ... - def setLevel(self, level: Union[int, str]) -> 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: ... @@ -383,22 +386,25 @@ 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: ... -class NullHandler(Handler): ... +if sys.version_info >= (3, 1): + class NullHandler(Handler): ... class PlaceHolder: From 4e1a45a0bb781ca8ed377d2ca95863da90018fea Mon Sep 17 00:00:00 2001 From: Parth Sharma Date: Fri, 27 Sep 2019 22:36:08 +0530 Subject: [PATCH 165/201] update `codecs.register` type definition (#3271) Closes #3262 --- stdlib/2and3/codecs.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/2and3/codecs.pyi b/stdlib/2and3/codecs.pyi index fe734511be21..7c06ee937a85 100644 --- a/stdlib/2and3/codecs.pyi +++ b/stdlib/2and3/codecs.pyi @@ -65,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]: ... From ac35a18ad6001a1e95e2f498660557fb9bbce8d6 Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Fri, 27 Sep 2019 15:39:04 -0700 Subject: [PATCH 166/201] Make the `value` argument to ctypes.cbool.__init__ optional. (#3273) --- stdlib/2and3/ctypes/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 60bdf60eda4205a6bd724be2f844429e1e508f61 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sun, 29 Sep 2019 16:13:09 +0300 Subject: [PATCH 167/201] Add missing default for ssl_handshake_timeout agrument (#3277) --- stdlib/3/asyncio/events.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/asyncio/events.pyi b/stdlib/3/asyncio/events.pyi index a559809ea13a..e779d2a8d172 100644 --- a/stdlib/3/asyncio/events.pyi +++ b/stdlib/3/asyncio/events.pyi @@ -139,7 +139,7 @@ class AbstractEventLoop(metaclass=ABCMeta): @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: ... + 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] = ..., From c0371df172e9ea2178f77cb0f3125bba92359271 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 29 Sep 2019 07:09:22 -0700 Subject: [PATCH 168/201] dir argument to tempfile functions may take PathLike (#3226) --- stdlib/3/tempfile.pyi | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/stdlib/3/tempfile.pyi b/stdlib/3/tempfile.pyi index 9aaa72ce1450..5baf9abf385b 100644 --- a/stdlib/3/tempfile.pyi +++ b/stdlib/3/tempfile.pyi @@ -3,9 +3,10 @@ # 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 @@ -17,6 +18,12 @@ TMP_MAX: int tempdir: Optional[str] template: str +_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] + @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"], @@ -25,7 +32,7 @@ def TemporaryFile( newline: Optional[str] = ..., suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., - dir: Optional[AnyStr] = ..., + dir: Optional[_DirT[AnyStr]] = ..., ) -> IO[str]: ... @overload def TemporaryFile( @@ -35,7 +42,7 @@ def TemporaryFile( newline: Optional[str] = ..., suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., - dir: Optional[AnyStr] = ..., + dir: Optional[_DirT[AnyStr]] = ..., ) -> IO[bytes]: ... @overload def TemporaryFile( @@ -45,7 +52,7 @@ def TemporaryFile( newline: Optional[str] = ..., suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., - dir: Optional[AnyStr] = ..., + dir: Optional[_DirT[AnyStr]] = ..., ) -> IO[Any]: ... @overload @@ -56,7 +63,7 @@ def NamedTemporaryFile( newline: Optional[str] = ..., suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., - dir: Optional[AnyStr] = ..., + dir: Optional[_DirT[AnyStr]] = ..., delete: bool = ..., ) -> IO[str]: ... @overload @@ -67,7 +74,7 @@ def NamedTemporaryFile( newline: Optional[str] = ..., suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., - dir: Optional[AnyStr] = ..., + dir: Optional[_DirT[AnyStr]] = ..., delete: bool = ..., ) -> IO[bytes]: ... @overload @@ -78,7 +85,7 @@ def NamedTemporaryFile( newline: Optional[str] = ..., suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., - dir: Optional[AnyStr] = ..., + dir: Optional[_DirT[AnyStr]] = ..., delete: bool = ..., ) -> IO[Any]: ... @@ -120,21 +127,21 @@ class SpooledTemporaryFile(IO[AnyStr]): class TemporaryDirectory(Generic[AnyStr]): name: str def __init__(self, suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., - dir: Optional[AnyStr] = ...) -> None: ... + 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: ... -def mkstemp(suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., dir: Optional[AnyStr] = ..., +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[AnyStr] = ...) -> AnyStr: ... -def mktemp(suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., dir: Optional[AnyStr] = ...) -> AnyStr: ... + dir: Optional[_DirT[AnyStr]] = ...) -> AnyStr: ... +def mktemp(suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., dir: Optional[_DirT[AnyStr]] = ...) -> AnyStr: ... def gettempdirb() -> bytes: ... def gettempprefixb() -> bytes: ... From d4727c39f12a2812309545c1ce6fe8d931fa1afa Mon Sep 17 00:00:00 2001 From: Alan Du Date: Sun, 29 Sep 2019 10:30:09 -0400 Subject: [PATCH 169/201] Add multiprocessing.Array (#3272) --- stdlib/3/multiprocessing/__init__.pyi | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/stdlib/3/multiprocessing/__init__.pyi b/stdlib/3/multiprocessing/__init__.pyi index f3bfdd566c34..fb514266bd6b 100644 --- a/stdlib/3/multiprocessing/__init__.pyi +++ b/stdlib/3/multiprocessing/__init__.pyi @@ -2,7 +2,7 @@ from typing import ( Any, Callable, ContextManager, Iterable, Mapping, Optional, Dict, List, - Union, Sequence, Tuple, Type + Union, Sequence, Tuple, Type, overload ) from ctypes import _CData @@ -67,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: 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]: ... From 1e881ad156dc403dbf722551d5a9d733b424c3dd Mon Sep 17 00:00:00 2001 From: hh-h Date: Sun, 29 Sep 2019 17:46:37 +0300 Subject: [PATCH 170/201] switched return_exceptions from bool to Literal for asyncio.gather (#3275) --- stdlib/3/asyncio/tasks.pyi | 40 +++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/stdlib/3/asyncio/tasks.pyi b/stdlib/3/asyncio/tasks.pyi index d100605d91be..f3a3e5f21c46 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') @@ -29,26 +34,51 @@ def ensure_future(coro_or_future: _FutureT[_T], # It became a keyword in 3.7. @overload def gather(coro_or_future1: _FutureT[_T1], - *, loop: Optional[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: Optional[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: Optional[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: Optional[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: Optional[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: Optional[AbstractEventLoop] = ..., return_exceptions: bool = ...) -> Future[Tuple[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: Optional[AbstractEventLoop] = ...) -> Future[_T]: ... From b336182b695b58ec6a0faa31794defcdc70ffb96 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sun, 29 Sep 2019 09:15:27 -0700 Subject: [PATCH 171/201] Fix some errors with --disallow-any-generics (#3276) See #3267. Covers all of stdlib/2and3. --- stdlib/2/__builtin__.pyi | 24 ++++++++++++------------ stdlib/2and3/_weakrefset.pyi | 2 +- stdlib/2and3/asyncore.pyi | 6 +++--- stdlib/2and3/bisect.pyi | 21 ++++++--------------- stdlib/2and3/builtins.pyi | 24 ++++++++++++------------ stdlib/2and3/cgi.pyi | 2 +- stdlib/2and3/contextlib.pyi | 4 ++-- stdlib/2and3/formatter.pyi | 4 ++-- stdlib/2and3/imaplib.pyi | 8 ++++---- stdlib/2and3/lib2to3/pgen2/literals.pyi | 2 +- stdlib/2and3/logging/__init__.pyi | 2 +- stdlib/2and3/logging/handlers.pyi | 8 ++++---- stdlib/2and3/math.pyi | 2 +- stdlib/2and3/mmap.pyi | 4 ++-- stdlib/2and3/operator.pyi | 4 ++-- stdlib/2and3/optparse.pyi | 12 ++++++------ stdlib/2and3/pickle.pyi | 8 ++++---- stdlib/2and3/plistlib.pyi | 2 +- stdlib/2and3/pydoc.pyi | 6 +++--- stdlib/2and3/shutil.pyi | 10 ++++++---- stdlib/2and3/socket.pyi | 2 +- stdlib/2and3/sqlite3/dbapi2.pyi | 8 ++++---- stdlib/2and3/sre_compile.pyi | 2 +- stdlib/2and3/threading.pyi | 4 ++-- stdlib/2and3/traceback.pyi | 2 +- stdlib/2and3/xml/etree/ElementPath.pyi | 2 +- stdlib/2and3/zipfile.pyi | 2 +- 27 files changed, 85 insertions(+), 92 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index ecaaf42076f3..433bfdfa0833 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -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 @@ -1130,7 +1130,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: @@ -1187,8 +1187,8 @@ else: 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 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: ... @@ -1324,7 +1324,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,): 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/asyncore.pyi b/stdlib/2and3/asyncore.pyi index 8dc8f477543f..a7fb59c84644 100644 --- a/stdlib/2and3/asyncore.pyi +++ b/stdlib/2and3/asyncore.pyi @@ -50,8 +50,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 +103,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/bisect.pyi b/stdlib/2and3/bisect.pyi index 04229284f71a..c3075297c394 100644 --- a/stdlib/2and3/bisect.pyi +++ b/stdlib/2and3/bisect.pyi @@ -4,19 +4,10 @@ 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: 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: ... +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: MutableSequence, x: Any, lo: int = ..., hi: int = ...) -> int: ... -def insort_right(a: MutableSequence, x: Any, lo: int = ..., hi: int = ...) -> int: ... -def insort(a: MutableSequence, 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 ecaaf42076f3..433bfdfa0833 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -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 @@ -1130,7 +1130,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: @@ -1187,8 +1187,8 @@ else: 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 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: ... @@ -1324,7 +1324,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,): 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/contextlib.pyi b/stdlib/2and3/contextlib.pyi index ab11501403b9..2832d94b8518 100644 --- a/stdlib/2and3/contextlib.pyi +++ b/stdlib/2and3/contextlib.pyi @@ -23,7 +23,7 @@ _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]): @@ -85,7 +85,7 @@ if sys.version_info >= (3, 7): 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: ... 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/imaplib.pyi b/stdlib/2and3/imaplib.pyi index ab32e7bac31f..1653ae344a26 100644 --- a/stdlib/2and3/imaplib.pyi +++ b/stdlib/2and3/imaplib.pyi @@ -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: ... @@ -111,7 +111,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 +121,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 32b2f117db8b..d95cf50e1ef4 100644 --- a/stdlib/2and3/logging/__init__.pyi +++ b/stdlib/2and3/logging/__init__.pyi @@ -39,7 +39,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] diff --git a/stdlib/2and3/logging/handlers.pyi b/stdlib/2and3/logging/handlers.pyi index 00a27c923b54..5b923ea8d5b5 100644 --- a/stdlib/2and3/logging/handlers.pyi +++ b/stdlib/2and3/logging/handlers.pyi @@ -198,19 +198,19 @@ class HTTPHandler(Handler): if sys.version_info >= (3,): class QueueHandler(Handler): if sys.version_info >= (3, 7): - def __init__(self, queue: Union[SimpleQueue, Queue]) -> None: ... + def __init__(self, queue: Union[SimpleQueue[Any], Queue[Any]]) -> None: ... else: - def __init__(self, queue: Queue) -> None: ... + 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, 7): - def __init__(self, queue: Union[SimpleQueue, Queue], + 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, *handlers: Handler, + def __init__(self, queue: Queue[Any], *handlers: Handler, respect_handler_level: bool = ...) -> None: ... else: def __init__(self, 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/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 ad5d51dff150..532be815ebd9 100644 --- a/stdlib/2and3/plistlib.pyi +++ b/stdlib/2and3/plistlib.pyi @@ -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/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/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/socket.pyi b/stdlib/2and3/socket.pyi index 4d1916a58a4d..1a42632187a1 100644 --- a/stdlib/2and3/socket.pyi +++ b/stdlib/2and3/socket.pyi @@ -600,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/threading.pyi b/stdlib/2and3/threading.pyi index b5d8f0d3569d..c8ed09611ec6 100644 --- a/stdlib/2and3/threading.pyi +++ b/stdlib/2and3/threading.pyi @@ -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: ... diff --git a/stdlib/2and3/traceback.pyi b/stdlib/2and3/traceback.pyi index cbefb62f020c..e6744007ace6 100644 --- a/stdlib/2and3/traceback.pyi +++ b/stdlib/2and3/traceback.pyi @@ -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/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/zipfile.pyi b/stdlib/2and3/zipfile.pyi index 8003cce68da0..a7737215d0dd 100644 --- a/stdlib/2and3/zipfile.pyi +++ b/stdlib/2and3/zipfile.pyi @@ -29,7 +29,7 @@ class ZipExtFile(io.BufferedIOBase): MIN_READ_SIZE: int = ... if sys.version_info < (3, 6): - PATTERN: Pattern = ... + PATTERN: Pattern[str] = ... if sys.version_info >= (3, 7): MAX_SEEK_READ: int = ... From 95185fa9cf9acb261f75ea9cf5fedc1fe538e0ce Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sun, 29 Sep 2019 09:23:11 -0700 Subject: [PATCH 172/201] Improve the explanatory comment at the top of check_consistent.py --- tests/check_consistent.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/check_consistent.py b/tests/check_consistent.py index 47e455830067..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 From 23232c056c9958f60423784b838974a7e201cdbb Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 30 Sep 2019 11:46:12 +0200 Subject: [PATCH 173/201] Simplify Travis-CI configuration (#3220) This removes the indirection of setting environment variables to install and run tests. Also, use an explicit version for running mypy with typed-ast. --- .travis.yml | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2d96621b8e9e..0a315e7668d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,34 +2,24 @@ dist: bionic language: python python: 3.7 -matrix: +jobs: include: - name: "pytype" python: 3.6 - env: - - TEST_CMD="./tests/pytype_test.py" - - INSTALL="test" + install: pip install -r requirements-tests-py3.txt + script: ./tests/pytype_test.py - name: "mypy (typed-ast)" - env: - - TEST_CMD="./tests/mypy_test.py" - - INSTALL="mypy" + 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 - env: - - TEST_CMD="./tests/mypy_test.py" - - INSTALL="mypy" + 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" + 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 From 468d13a2059fa1c74cbc9fc467472da5f0f6391b Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Mon, 30 Sep 2019 03:42:40 -0700 Subject: [PATCH 174/201] Modified __add__ method in tuple class (#3252) Modified __add__ method in tuple class to allow it to accept tuples with different generic parameter types. This allows, for example: a = (1, ) b = a + (2.4, ) --- stdlib/2/__builtin__.pyi | 3 +++ stdlib/2and3/builtins.pyi | 3 +++ 2 files changed, 6 insertions(+) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 433bfdfa0833..9b4c83dc8949 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -867,7 +867,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) -> tuple: ... def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... def count(self, x: Any) -> int: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 433bfdfa0833..9b4c83dc8949 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -867,7 +867,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) -> tuple: ... def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... def count(self, x: Any) -> int: ... From 412b9e74d557196dfcbe49dc443c17fbf503fd94 Mon Sep 17 00:00:00 2001 From: Brad Date: Mon, 30 Sep 2019 06:42:58 -0400 Subject: [PATCH 175/201] Change last asyncio.gather() overload ret. to List (#3248) Stems from PR #1550/ Issue #3243. --- stdlib/3/asyncio/tasks.pyi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stdlib/3/asyncio/tasks.pyi b/stdlib/3/asyncio/tasks.pyi index f3a3e5f21c46..830af19d49bb 100644 --- a/stdlib/3/asyncio/tasks.pyi +++ b/stdlib/3/asyncio/tasks.pyi @@ -32,6 +32,11 @@ 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: Optional[AbstractEventLoop] = ..., return_exceptions: Literal[False] = ...) -> Future[Tuple[_T1]]: ... @@ -56,7 +61,7 @@ def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], coro_ 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: Optional[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] = ..., From ed4b1de0ad107f7967e95c9333100ab9e31eb63b Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 30 Sep 2019 13:14:01 +0200 Subject: [PATCH 176/201] Fix third_party errors with --disallow-any-generics (#3278) Part of #3267. Together with #3276 this should fix all such problems. --- third_party/2/gflags.pyi | 4 +- third_party/2/tornado/httputil.pyi | 6 +- third_party/2/tornado/testing.pyi | 7 +- third_party/2/tornado/util.pyi | 4 +- third_party/2and3/atomicwrites/__init__.pyi | 20 +++--- third_party/2and3/boto/s3/cors.pyi | 4 +- third_party/2and3/boto/s3/lifecycle.pyi | 6 +- third_party/2and3/boto/s3/tagging.pyi | 6 +- third_party/2and3/boto/s3/website.pyi | 6 +- third_party/2and3/boto/utils.pyi | 6 +- third_party/2and3/characteristic/__init__.pyi | 4 +- third_party/2and3/click/core.pyi | 43 +++++-------- third_party/2and3/click/decorators.pyi | 12 ++-- third_party/2and3/click/exceptions.pyi | 7 +- third_party/2and3/click/termui.pyi | 6 +- third_party/2and3/click/testing.pyi | 6 +- third_party/2and3/click/types.pyi | 36 +++-------- third_party/2and3/click/utils.pyi | 64 ++++++------------- third_party/2and3/emoji.pyi | 4 +- third_party/2and3/flask/sessions.pyi | 4 +- third_party/2and3/flask/testing.pyi | 2 +- third_party/2and3/itsdangerous.pyi | 12 ++-- third_party/2and3/jinja2/environment.pyi | 56 ++++++++++++++-- third_party/2and3/jinja2/filters.pyi | 7 +- third_party/2and3/jinja2/lexer.pyi | 4 +- third_party/2and3/jinja2/loaders.pyi | 14 ++-- third_party/2and3/mypy_extensions.pyi | 2 +- third_party/2and3/pycurl.pyi | 9 ++- third_party/2and3/pymysql/err.pyi | 6 +- third_party/2and3/pynamodb/attributes.pyi | 8 +-- .../2and3/pynamodb/connection/base.pyi | 4 +- third_party/2and3/pynamodb/models.pyi | 8 +-- third_party/2and3/pyre_extensions.pyi | 2 +- third_party/2and3/requests/cookies.pyi | 2 +- third_party/2and3/requests/models.pyi | 2 +- .../packages/urllib3/_collections.pyi | 11 +++- third_party/2and3/requests/sessions.pyi | 6 +- third_party/2and3/requests/structures.pyi | 2 +- third_party/2and3/typing_extensions.pyi | 2 +- .../2and3/werkzeug/contrib/securecookie.pyi | 2 +- .../2and3/werkzeug/contrib/sessions.pyi | 9 ++- third_party/2and3/werkzeug/datastructures.pyi | 28 ++++---- third_party/2and3/werkzeug/formparser.pyi | 2 +- third_party/2and3/werkzeug/http.pyi | 4 +- .../2and3/werkzeug/middleware/lint.pyi | 2 +- third_party/2and3/werkzeug/wrappers.pyi | 16 ++--- third_party/3/docutils/parsers/rst/roles.pyi | 13 ++-- third_party/3/jwt/__init__.pyi | 4 +- third_party/3/jwt/algorithms.pyi | 11 ++-- .../3/jwt/contrib/algorithms/py_ecdsa.pyi | 2 +- .../3/jwt/contrib/algorithms/pycrypto.pyi | 2 +- 51 files changed, 245 insertions(+), 264 deletions(-) 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/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 adc7fcda6fc1..c10025810c1c 100644 --- a/third_party/2/tornado/testing.pyi +++ b/third_party/2/tornado/testing.pyi @@ -43,12 +43,9 @@ class AsyncHTTPSTestCase(AsyncHTTPTestCase): def get_protocol(self): ... @overload -def gen_test(*, timeout: Optional[float] = ...) -> Callable[[Callable[..., Generator]], Callable[..., None]]: - ... - +def gen_test(*, timeout: Optional[float] = ...) -> Callable[[Callable[..., Generator[Any, Any, Any]]], Callable[..., None]]: ... @overload -def gen_test(func: Callable[..., Generator]) -> Callable[..., None]: - ... +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 2132eb374a1d..efe556193c05 100644 --- a/third_party/2and3/boto/utils.pyi +++ b/third_party/2and3/boto/utils.pyi @@ -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/core.pyi b/third_party/2and3/click/core.pyi index ea3ef550a55b..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): 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 d34963bcb1bb..87e9bdcc9cfc 100644 --- a/third_party/2and3/click/termui.pyi +++ b/third_party/2and3/click/termui.pyi @@ -84,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]: ... @@ -103,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]: ... @@ -133,7 +133,7 @@ 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 bffe29eb83e0..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[Union[bytes, Text, 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[Union[bytes, Text, 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 dc1e787568bf..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 @@ -79,7 +79,6 @@ class FloatRange(FloatParamType): ) -> None: ... - class File(ParamType): def __init__( self, @@ -88,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/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/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/testing.pyi b/third_party/2and3/flask/testing.pyi index 79459287c224..45a0065b1977 100644 --- a/third_party/2and3/flask/testing.pyi +++ b/third_party/2and3/flask/testing.pyi @@ -29,7 +29,7 @@ class FlaskCliRunner(CliRunner): self, cli: Optional[BaseCommand] = ..., args: Optional[Union[str, Iterable[str]]] = ..., - input: Optional[Union[bytes, IO, Text]] = ..., + input: Optional[Union[bytes, IO[Any], Text]] = ..., env: Optional[Mapping[str, str]] = ..., catch_exceptions: bool = ..., color: bool = ..., diff --git a/third_party/2and3/itsdangerous.pyi b/third_party/2and3/itsdangerous.pyi index 37a7070518d7..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: ... 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/mypy_extensions.pyi b/third_party/2and3/mypy_extensions.pyi index f9c9ff6da6c0..f42162c0eb1e 100644 --- a/third_party/2and3/mypy_extensions.pyi +++ b/third_party/2and3/mypy_extensions.pyi @@ -23,7 +23,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: ... 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/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 6dca7cf8f8e4..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 index c6c4fd8690b9..742b88013256 100644 --- a/third_party/2and3/pyre_extensions.pyi +++ b/third_party/2and3/pyre_extensions.pyi @@ -4,4 +4,4 @@ _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]: ... +def ParameterSpecification(__name: str) -> List[Type[Any]]: ... 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 a0f476009fff..f09dbec2e462 100644 --- a/third_party/2and3/requests/sessions.pyi +++ b/third_party/2and3/requests/sessions.pyi @@ -73,8 +73,8 @@ 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: ... @@ -84,7 +84,7 @@ class Session(SessionRedirectMixin): 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 807f39a1c6b0..0ef1993643a5 100644 --- a/third_party/2and3/requests/structures.pyi +++ b/third_party/2and3/requests/structures.pyi @@ -10,7 +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: ... + 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 5531601469a1..ef36d125cf7e 100644 --- a/third_party/2and3/typing_extensions.pyi +++ b/third_party/2and3/typing_extensions.pyi @@ -26,7 +26,7 @@ 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/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 63a04227db7c..4d5f0ec146a3 100644 --- a/third_party/2and3/werkzeug/datastructures.pyi +++ b/third_party/2and3/werkzeug/datastructures.pyi @@ -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=...): ... @@ -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): # type: ignore +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): # type: ignore 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): # type: ignore +class ImmutableDict(ImmutableDictMixin, Dict[_K, _V]): # type: ignore def copy(self): ... def __copy__(self): ... -class ImmutableMultiDict(ImmutableMultiDictMixin, MultiDict): # type: ignore +class ImmutableMultiDict(ImmutableMultiDictMixin, MultiDict[_K, _V]): # type: ignore def copy(self): ... def __copy__(self): ... -class ImmutableOrderedMultiDict(ImmutableMultiDictMixin, OrderedMultiDict): # type: ignore +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 @@ -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 = ...): ... @@ -384,7 +384,7 @@ class Authorization(ImmutableDictMixin, Dict[str, Any]): # type: ignore @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 = ...): ... diff --git a/third_party/2and3/werkzeug/formparser.pyi b/third_party/2and3/werkzeug/formparser.pyi index 16c91c350ecf..8f0b55254bb8 100644 --- a/third_party/2and3/werkzeug/formparser.pyi +++ b/third_party/2and3/werkzeug/formparser.pyi @@ -47,7 +47,7 @@ class FormDataParser(object): 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_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]: ... 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/lint.pyi b/third_party/2and3/werkzeug/middleware/lint.pyi index 7ad4901f8a06..95922cc4afc4 100644 --- a/third_party/2and3/werkzeug/middleware/lint.pyi +++ b/third_party/2and3/werkzeug/middleware/lint.pyi @@ -60,7 +60,7 @@ class LintMiddleware(object): self, status: str, headers: List[Tuple[str, str]], - exc_info: Optional[tuple], + 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: ... diff --git a/third_party/2and3/werkzeug/wrappers.pyi b/third_party/2and3/werkzeug/wrappers.pyi index 4ea56495a8b2..c1635b9fcdcb 100644 --- a/third_party/2and3/werkzeug/wrappers.pyi +++ b/third_party/2and3/werkzeug/wrappers.pyi @@ -22,10 +22,10 @@ class BaseRequest: 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 = ... @@ -46,7 +46,7 @@ class BaseRequest: @property def stream(self) -> InputStream: ... input_stream: InputStream - args: ImmutableMultiDict + args: ImmutableMultiDict[Any, Any] @property def data(self) -> bytes: ... @overload @@ -59,9 +59,9 @@ class BaseRequest: 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 - values: CombinedMultiDict - files: MultiDict + form: ImmutableMultiDict[Any, Any] + values: CombinedMultiDict[Any, Any] + files: MultiDict[Any, Any] @property def cookies(self) -> ImmutableTypeConversionDict[str, str]: ... headers: EnvironHeaders 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 From c441a1f5b87a5ae74b674aebbafaa44e0eb358cf Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Mon, 30 Sep 2019 18:10:48 +0300 Subject: [PATCH 177/201] Added ConfigParser.BOOLEAN_STATES # Undocumented (#3281) --- stdlib/3/configparser.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/3/configparser.pyi b/stdlib/3/configparser.pyi index 17501c1e9e6c..3f59b611b865 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]] = ..., From aaff561ef6ab4a6baa427ab94d66874e97a003fa Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Mon, 30 Sep 2019 19:57:14 +0300 Subject: [PATCH 178/201] Added stub for urllib.request.proxy_bypass() (#3283) --- stdlib/3/urllib/request.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index b043a115e4ec..63152d445448 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -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 From a2834cf24d6cc5f9858bf06668651a1930984e23 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Mon, 30 Sep 2019 20:27:54 +0300 Subject: [PATCH 179/201] Added stub for http.server.BaseHTTPRequestHandler useful undocumented fields (#3285) --- stdlib/3/http/server.pyi | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stdlib/3/http/server.pyi b/stdlib/3/http/server.pyi index dd3118e9fb77..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 @@ -36,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: ... @@ -58,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] From 785d7838e1813767a1779a8a14105666a3d7add3 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Mon, 30 Sep 2019 21:51:11 +0300 Subject: [PATCH 180/201] Added stub for asyncore.socket_map, undocumented but useful (#3284) --- stdlib/2and3/asyncore.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/2and3/asyncore.pyi b/stdlib/2and3/asyncore.pyi index a7fb59c84644..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): ... From 23b353303bcc5aa713e377b54cced74b6ea8db0d Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 30 Sep 2019 13:30:28 -0700 Subject: [PATCH 181/201] Allow passing bytes and byte string to yaml load APIs. (#3287) --- third_party/2and3/yaml/__init__.pyi | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 From c32e1e228038af9fe95e5899431cd442a5772ad6 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Tue, 1 Oct 2019 14:31:34 +0200 Subject: [PATCH 182/201] Enable --disallow-any-generics for stubs (#3288) --- stdlib/2/ConfigParser.pyi | 12 ++-- stdlib/2/Cookie.pyi | 6 +- stdlib/2/Queue.pyi | 4 +- stdlib/2/SimpleHTTPServer.pyi | 2 +- stdlib/2/UserList.pyi | 4 +- stdlib/2/__builtin__.pyi | 2 +- stdlib/2/_collections.pyi | 19 ++--- stdlib/2/_hotshot.pyi | 2 +- stdlib/2/_io.pyi | 25 ++++--- stdlib/2/_json.pyi | 16 +---- stdlib/2/_socket.pyi | 18 ++--- stdlib/2/_sre.pyi | 8 +-- stdlib/2/_warnings.pyi | 19 +++-- stdlib/2/abc.pyi | 6 +- stdlib/2/collections.pyi | 16 ++--- stdlib/2/compileall.pyi | 15 +++- stdlib/2/email/iterators.pyi | 8 +-- stdlib/2/email/message.pyi | 4 +- stdlib/2/inspect.pyi | 8 +-- stdlib/2/json.pyi | 4 +- stdlib/2/multiprocessing/dummy/__init__.pyi | 6 +- stdlib/2/multiprocessing/dummy/connection.pyi | 2 +- stdlib/2/mutex.pyi | 5 +- stdlib/2/popen2.pyi | 14 ++-- stdlib/2/repr.pyi | 4 +- stdlib/2/sets.pyi | 32 ++++----- stdlib/2/shelve.pyi | 2 +- stdlib/2/sre_parse.pyi | 12 ++-- stdlib/2/subprocess.pyi | 2 - stdlib/2/tempfile.pyi | 4 +- stdlib/2/types.pyi | 4 +- stdlib/2/typing.pyi | 11 +-- stdlib/2/xmlrpclib.pyi | 72 +++++++++++++------ stdlib/2and3/builtins.pyi | 2 +- stdlib/3/_threading_local.pyi | 2 +- stdlib/3/_tracemalloc.pyi | 4 +- stdlib/3/_warnings.pyi | 10 +-- stdlib/3/asyncio/base_events.pyi | 2 +- stdlib/3/asyncio/events.pyi | 2 +- stdlib/3/asyncio/futures.pyi | 2 +- stdlib/3/asyncio/tasks.pyi | 10 +-- stdlib/3/collections/__init__.pyi | 55 +++++++------- stdlib/3/compileall.pyi | 24 ++++++- stdlib/3/concurrent/futures/_base.pyi | 30 ++++---- stdlib/3/concurrent/futures/thread.pyi | 13 ++-- stdlib/3/configparser.pyi | 2 +- stdlib/3/http/cookies.pyi | 8 +-- stdlib/3/inspect.pyi | 7 +- stdlib/3/ipaddress.pyi | 2 +- stdlib/3/json/__init__.pyi | 4 +- stdlib/3/json/encoder.pyi | 2 +- stdlib/3/multiprocessing/__init__.pyi | 4 +- stdlib/3/multiprocessing/context.pyi | 10 +-- stdlib/3/multiprocessing/dummy/__init__.pyi | 6 +- stdlib/3/multiprocessing/dummy/connection.pyi | 4 +- stdlib/3/multiprocessing/managers.pyi | 4 +- stdlib/3/multiprocessing/pool.pyi | 6 +- stdlib/3/multiprocessing/synchronize.pyi | 4 +- stdlib/3/os/__init__.pyi | 20 +++--- stdlib/3/queue.pyi | 5 +- stdlib/3/random.pyi | 8 +-- stdlib/3/reprlib.pyi | 2 +- stdlib/3/shelve.pyi | 2 +- stdlib/3/sre_parse.pyi | 4 +- stdlib/3/subprocess.pyi | 3 +- stdlib/3/tempfile.pyi | 3 +- stdlib/3/tokenize.pyi | 2 +- stdlib/3/types.pyi | 2 +- stdlib/3/typing.pyi | 11 +-- stdlib/3/unittest/mock.pyi | 8 ++- stdlib/3/urllib/parse.pyi | 2 +- stdlib/3/urllib/request.pyi | 2 +- tests/mypy_test.py | 1 + third_party/2/concurrent/futures/_base.pyi | 30 ++++---- third_party/2/concurrent/futures/thread.pyi | 13 ++-- third_party/2and3/boto/utils.pyi | 2 +- third_party/2and3/mock.pyi | 8 ++- 77 files changed, 386 insertions(+), 329 deletions(-) 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 1593eb1c6a67..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: ... 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/UserList.pyi b/stdlib/2/UserList.pyi index b8466eed1405..97ba17a9b513 100644 --- a/stdlib/2/UserList.pyi +++ b/stdlib/2/UserList.pyi @@ -1,7 +1,7 @@ from typing import Iterable, MutableSequence, TypeVar, Union, overload _T = TypeVar("_T") -_ULT = TypeVar("_ULT", bound=UserList) +_S = TypeVar("_S") class UserList(MutableSequence[_T]): def insert(self, index: int, object: _T) -> None: ... @@ -14,5 +14,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 9b4c83dc8949..62052cfb7186 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -870,7 +870,7 @@ class tuple(Sequence[_T_co], Generic[_T_co]): @overload def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... @overload - def __add__(self, x: tuple) -> tuple: ... + 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: ... 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/_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 dd4d1440dd13..d0185ae7da0c 100644 --- a/stdlib/2/_io.pyi +++ b/stdlib/2/_io.pyi @@ -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: ... @@ -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 9b327d1c91d7..5ab7ed124da4 100644 --- a/stdlib/2/_sre.pyi +++ b/stdlib/2/_sre.pyi @@ -35,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 e5fe035f2cba..64fbb50bc706 100644 --- a/stdlib/2/abc.pyi +++ b/stdlib/2/abc.pyi @@ -10,11 +10,11 @@ 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/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/inspect.pyi b/stdlib/2/inspect.pyi index 4e157dca7cd8..67be3a41a7c9 100644 --- a/stdlib/2/inspect.pyi +++ b/stdlib/2/inspect.pyi @@ -52,8 +52,7 @@ def isgetsetdescriptor(object: object) -> bool: ... def ismemberdescriptor(object: object) -> bool: ... # Retrieving source code -_SourceObjectType = Union[ModuleType, Type, MethodType, FunctionType, - TracebackType, FrameType, CodeType] +_SourceObjectType = Union[ModuleType, Type[Any], MethodType, FunctionType, TracebackType, FrameType, CodeType] def findsource(object: _SourceObjectType) -> Tuple[List[str], int]: ... def getabsfile(object: _SourceObjectType) -> str: ... @@ -69,13 +68,12 @@ 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]), diff --git a/stdlib/2/json.pyi b/stdlib/2/json.pyi index 84ed8b9c3fae..578e0cd0c507 100644 --- a/stdlib/2/json.pyi +++ b/stdlib/2/json.pyi @@ -36,7 +36,7 @@ def dump(obj: Any, def loads(s: Union[Text, bytes], encoding: Any = ..., cls: Optional[Type[JSONDecoder]] = ..., - object_hook: Optional[Callable[[Dict], Any]] = ..., + 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,7 +49,7 @@ class _Reader(Protocol): def load(fp: _Reader, encoding: Optional[str] = ..., cls: Optional[Type[JSONDecoder]] = ..., - object_hook: Optional[Callable[[Dict], Any]] = ..., + 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/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/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 672efbf8c71e..54dd0dbd3bc8 100644 --- a/stdlib/2/subprocess.pyi +++ b/stdlib/2/subprocess.pyi @@ -105,8 +105,6 @@ class Popen(Generic[_T]): 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) -> None: ... def list2cmdline(seq: Sequence[str]) -> str: ... # undocumented diff --git a/stdlib/2/tempfile.pyi b/stdlib/2/tempfile.pyi index 4233cf72f179..536b391ad4d0 100644 --- a/stdlib/2/tempfile.pyi +++ b/stdlib/2/tempfile.pyi @@ -19,9 +19,9 @@ 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) -> Optional[bool]: ... diff --git a/stdlib/2/types.pyi b/stdlib/2/types.pyi index 93360e7dec35..47c52e88a29d 100644 --- a/stdlib/2/types.pyi +++ b/stdlib/2/types.pyi @@ -103,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): ... @@ -154,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 0d10952b5ae6..d45aba1da6b7 100644 --- a/stdlib/2/typing.pyi +++ b/stdlib/2/typing.pyi @@ -69,7 +69,7 @@ _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_checkable(cls: _TC) -> _TC: ... @@ -447,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: ... @@ -458,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]] = ..., *, @@ -467,7 +468,7 @@ 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) 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/builtins.pyi b/stdlib/2and3/builtins.pyi index 9b4c83dc8949..62052cfb7186 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -870,7 +870,7 @@ class tuple(Sequence[_T_co], Generic[_T_co]): @overload def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... @overload - def __add__(self, x: tuple) -> tuple: ... + 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: ... 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/asyncio/base_events.pyi b/stdlib/3/asyncio/base_events.pyi index 6a80cbdec387..8a959a9ee0dc 100644 --- a/stdlib/3/asyncio/base_events.pyi +++ b/stdlib/3/asyncio/base_events.pyi @@ -61,7 +61,7 @@ class BaseEventLoop(AbstractEventLoop, metaclass=ABCMeta): 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]]: ... + 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: ... diff --git a/stdlib/3/asyncio/events.pyi b/stdlib/3/asyncio/events.pyi index e779d2a8d172..66f7c9f9e134 100644 --- a/stdlib/3/asyncio/events.pyi +++ b/stdlib/3/asyncio/events.pyi @@ -107,7 +107,7 @@ 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]]: ... + 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] = ..., *, diff --git a/stdlib/3/asyncio/futures.pyi b/stdlib/3/asyncio/futures.pyi index b4323c0189d4..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): ... diff --git a/stdlib/3/asyncio/tasks.pyi b/stdlib/3/asyncio/tasks.pyi index 830af19d49bb..05b590eb0430 100644 --- a/stdlib/3/asyncio/tasks.pyi +++ b/stdlib/3/asyncio/tasks.pyi @@ -95,9 +95,9 @@ def wait_for(fut: _FutureT[_T], timeout: Optional[float], 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]: ... @@ -107,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/collections/__init__.pyi b/stdlib/3/collections/__init__.pyi index a6cecdfc794d..46d3644dc60a 100644 --- a/stdlib/3/collections/__init__.pyi +++ b/stdlib/3/collections/__init__.pyi @@ -47,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] @@ -67,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] @@ -91,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: ... @@ -233,8 +242,6 @@ class deque(MutableSequence[_T], Generic[_T]): def __mul__(self, other: int) -> deque[_T]: ... def __imul__(self, other: int) -> None: ... -_CounterT = TypeVar('_CounterT', bound=Counter) - class Counter(Dict[_T, int], Generic[_T]): @overload def __init__(self, **kwargs: int) -> None: ... @@ -242,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]]: ... @@ -275,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]]): @@ -287,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]] @@ -318,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/compileall.pyi b/stdlib/3/compileall.pyi index 0e0b11748d73..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,6 +12,24 @@ else: _SuccessType = int # 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 = ..., 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 6d454fbe8388..00ff41d76959 100644 --- a/stdlib/3/concurrent/futures/_base.pyi +++ b/stdlib/3/concurrent/futures/_base.pyi @@ -62,25 +62,25 @@ def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: class _Waiter: event: threading.Event - finished_futures: List[Future] + finished_futures: List[Future[Any]] def __init__(self) -> None: ... - def add_result(self, future: Future) -> None: ... - def add_exception(self, future: Future) -> None: ... - def add_cancelled(self, future: Future) -> 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) -> None: ... - def add_exception(self, future: Future) -> None: ... - def add_cancelled(self, future: Future) -> 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) -> None: ... - def add_exception(self, future: Future) -> None: ... - def add_cancelled(self, future: Future) -> 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 _AllCompletedWaiter(_Waiter): @@ -88,13 +88,13 @@ class _AllCompletedWaiter(_Waiter): 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) -> None: ... - def add_exception(self, future: Future) -> None: ... - def add_cancelled(self, future: Future) -> 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] - def __init__(self, futures: Iterable[Future]) -> None: ... + 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/thread.pyi b/stdlib/3/concurrent/futures/thread.pyi index c4f895d7a543..82c8ddd03d94 100644 --- a/stdlib/3/concurrent/futures/thread.pyi +++ b/stdlib/3/concurrent/futures/thread.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Optional, Tuple, TypeVar, Generic +from typing import Any, Callable, Iterable, Mapping, Optional, Tuple, TypeVar, Generic from ._base import Executor, Future import sys @@ -22,10 +22,9 @@ class ThreadPoolExecutor(Executor): class _WorkItem(Generic[_S]): - future: Future - fn: Callable[[Future[_S]], Any] - args: Any - kwargs: Any - def __init__(self, future: Future, fn: Callable[[Future[_S]], Any], args: Any, - kwargs: Any) -> None: ... + 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 3f59b611b865..8b87e06453b9 100644 --- a/stdlib/3/configparser.pyi +++ b/stdlib/3/configparser.pyi @@ -177,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/http/cookies.pyi b/stdlib/3/http/cookies.pyi index 1e1091ba1c4a..dfd6df88cba1 100644 --- a/stdlib/3/http/cookies.pyi +++ b/stdlib/3/http/cookies.pyi @@ -2,7 +2,7 @@ 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): ... @@ -18,7 +18,7 @@ class Morsel(Dict[str, Any], 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/inspect.pyi b/stdlib/3/inspect.pyi index cd3ae936440e..5c518b81baab 100644 --- a/stdlib/3/inspect.pyi +++ b/stdlib/3/inspect.pyi @@ -77,8 +77,7 @@ def ismemberdescriptor(object: object) -> bool: ... # # Retrieving source code # -_SourceObjectType = Union[ModuleType, Type, MethodType, FunctionType, - TracebackType, FrameType, CodeType] +_SourceObjectType = Union[ModuleType, Type[Any], MethodType, FunctionType, TracebackType, FrameType, CodeType] def findsource(object: _SourceObjectType) -> Tuple[List[str], int]: ... def getabsfile(object: _SourceObjectType) -> str: ... @@ -174,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]), @@ -188,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]), diff --git a/stdlib/3/ipaddress.pyi b/stdlib/3/ipaddress.pyi index c6855fe264b7..3d507f41b911 100644 --- a/stdlib/3/ipaddress.pyi +++ b/stdlib/3/ipaddress.pyi @@ -54,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 e60c4727dc51..2f6374e3ba6a 100644 --- a/stdlib/3/json/__init__.pyi +++ b/stdlib/3/json/__init__.pyi @@ -37,7 +37,7 @@ else: def loads(s: _LoadsString, encoding: Any = ..., # ignored and deprecated cls: Optional[Type[JSONDecoder]] = ..., - object_hook: Optional[Callable[[Dict], Any]] = ..., + 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,7 +49,7 @@ class _Reader(Protocol): def load(fp: _Reader, cls: Optional[Type[JSONDecoder]] = ..., - object_hook: Optional[Callable[[Dict], Any]] = ..., + 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/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/multiprocessing/__init__.pyi b/stdlib/3/multiprocessing/__init__.pyi index fb514266bd6b..e2513f3bd75e 100644 --- a/stdlib/3/multiprocessing/__init__.pyi +++ b/stdlib/3/multiprocessing/__init__.pyi @@ -26,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: ... @@ -52,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] = ..., 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 7c19b1d2035f..7522d0ae437f 100644 --- a/stdlib/3/multiprocessing/managers.pyi +++ b/stdlib/3/multiprocessing/managers.pyi @@ -28,7 +28,7 @@ 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]] = ..., @@ -43,7 +43,7 @@ class SyncManager(BaseManager, ContextManager[SyncManager]): 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]: ... diff --git a/stdlib/3/multiprocessing/pool.pyi b/stdlib/3/multiprocessing/pool.pyi index fe1045d0a4d8..3782a3f1dc4b 100644 --- a/stdlib/3/multiprocessing/pool.pyi +++ b/stdlib/3/multiprocessing/pool.pyi @@ -19,14 +19,12 @@ AsyncResult = ApplyResult class MapResult(ApplyResult[List[_T]]): ... -_IMIT = TypeVar('_IMIT', bound=IMapIterator) - 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] = ..., 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 458fc75c1952..085000a0922f 100644 --- a/stdlib/3/os/__init__.pyi +++ b/stdlib/3/os/__init__.pyi @@ -282,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: ... @@ -297,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 @@ -506,32 +506,34 @@ def utime( 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': 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 diff --git a/stdlib/3/queue.pyi b/stdlib/3/queue.pyi index f6bafc04f0b7..9647faf4c0d3 100644 --- a/stdlib/3/queue.pyi +++ b/stdlib/3/queue.pyi @@ -2,9 +2,8 @@ # NOTE: These are incomplete! -from collections import deque from threading import Condition, Lock -from typing import Any, TypeVar, Generic, Optional +from typing import Any, Deque, TypeVar, Generic, Optional import sys _T = TypeVar('_T') @@ -21,7 +20,7 @@ class Queue(Generic[_T]): all_tasks_done: Condition # undocumented unfinished_tasks: int # undocumented - queue: deque # 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/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/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/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 c3126dd62fe6..8bc2e807e571 100644 --- a/stdlib/3/subprocess.pyi +++ b/stdlib/3/subprocess.pyi @@ -40,6 +40,7 @@ else: _CMD = Union[_TXT, Sequence[_PATH]] _ENV = Union[Mapping[bytes, _TXT], Mapping[Text, _TXT]] +_S = TypeVar('_S') _T = TypeVar('_T') class CompletedProcess(Generic[_T]): @@ -1169,7 +1170,7 @@ class Popen(Generic[AnyStr]): def send_signal(self, signal: int) -> None: ... def terminate(self) -> None: ... def kill(self) -> None: ... - def __enter__(self) -> Popen: ... + 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. diff --git a/stdlib/3/tempfile.pyi b/stdlib/3/tempfile.pyi index 5baf9abf385b..5d66a47a1b43 100644 --- a/stdlib/3/tempfile.pyi +++ b/stdlib/3/tempfile.pyi @@ -18,6 +18,7 @@ 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]] @@ -98,7 +99,7 @@ class SpooledTemporaryFile(IO[AnyStr]): prefix: Optional[str] = ..., dir: Optional[str] = ... ) -> None: ... def rollover(self) -> None: ... - def __enter__(self) -> SpooledTemporaryFile: ... + def __enter__(self: _S) -> _S: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]) -> Optional[bool]: ... diff --git a/stdlib/3/tokenize.pyi b/stdlib/3/tokenize.pyi index 9b6b50d2ee3c..b3c5fd9641b6 100644 --- a/stdlib/3/tokenize.pyi +++ b/stdlib/3/tokenize.pyi @@ -45,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 5d0acc7dd24c..61f87832ad9e 100644 --- a/stdlib/3/types.pyi +++ b/stdlib/3/types.pyi @@ -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] diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 3d36ce2736a7..4aa4988bd25f 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -75,7 +75,7 @@ _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_checkable(cls: _TC) -> _TC: ... @@ -166,7 +166,7 @@ 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]: ... + def gi_yieldfrom(self) -> Optional[Generator[Any, Any, Any]]: ... @runtime_checkable class Awaitable(Protocol[_T_co]): @@ -581,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: ... @@ -592,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, ...] diff --git a/stdlib/3/unittest/mock.pyi b/stdlib/3/unittest/mock.pyi index 8b20ea60217d..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: @@ -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 diff --git a/stdlib/3/urllib/parse.pyi b/stdlib/3/urllib/parse.pyi index b835119ec890..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 diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index 63152d445448..a18210a5971d 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -202,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/tests/mypy_test.py b/tests/mypy_test.py index 568f072b169a..cba411abb8ce 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -132,6 +132,7 @@ def main(): flags.append('--no-site-packages') flags.append('--show-traceback') flags.append('--no-implicit-optional') + flags.append('--disallow-any-generics') if args.warn_unused_ignores: flags.append('--warn-unused-ignores') sys.argv = ['mypy'] + flags + files diff --git a/third_party/2/concurrent/futures/_base.pyi b/third_party/2/concurrent/futures/_base.pyi index 6d454fbe8388..00ff41d76959 100644 --- a/third_party/2/concurrent/futures/_base.pyi +++ b/third_party/2/concurrent/futures/_base.pyi @@ -62,25 +62,25 @@ def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: class _Waiter: event: threading.Event - finished_futures: List[Future] + finished_futures: List[Future[Any]] def __init__(self) -> None: ... - def add_result(self, future: Future) -> None: ... - def add_exception(self, future: Future) -> None: ... - def add_cancelled(self, future: Future) -> 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) -> None: ... - def add_exception(self, future: Future) -> None: ... - def add_cancelled(self, future: Future) -> 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) -> None: ... - def add_exception(self, future: Future) -> None: ... - def add_cancelled(self, future: Future) -> 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 _AllCompletedWaiter(_Waiter): @@ -88,13 +88,13 @@ class _AllCompletedWaiter(_Waiter): 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) -> None: ... - def add_exception(self, future: Future) -> None: ... - def add_cancelled(self, future: Future) -> 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] - def __init__(self, futures: Iterable[Future]) -> None: ... + 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/thread.pyi b/third_party/2/concurrent/futures/thread.pyi index c4f895d7a543..82c8ddd03d94 100644 --- a/third_party/2/concurrent/futures/thread.pyi +++ b/third_party/2/concurrent/futures/thread.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Optional, Tuple, TypeVar, Generic +from typing import Any, Callable, Iterable, Mapping, Optional, Tuple, TypeVar, Generic from ._base import Executor, Future import sys @@ -22,10 +22,9 @@ class ThreadPoolExecutor(Executor): class _WorkItem(Generic[_S]): - future: Future - fn: Callable[[Future[_S]], Any] - args: Any - kwargs: Any - def __init__(self, future: Future, fn: Callable[[Future[_S]], Any], args: Any, - kwargs: Any) -> None: ... + 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/2and3/boto/utils.pyi b/third_party/2and3/boto/utils.pyi index efe556193c05..7c927d8356ce 100644 --- a/third_party/2and3/boto/utils.pyi +++ b/third_party/2and3/boto/utils.pyi @@ -37,7 +37,7 @@ if sys.version_info >= (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 diff --git a/third_party/2and3/mock.pyi b/third_party/2and3/mock.pyi index 8b20ea60217d..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: @@ -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 From 0abb50e20a7938b850f707d3372bf851b9daab20 Mon Sep 17 00:00:00 2001 From: Stefan T <66305+stj@users.noreply.github.com> Date: Tue, 1 Oct 2019 15:42:44 -0700 Subject: [PATCH 183/201] Add http.MISDIRECTED_REQUEST introduced in 3.7 (#3293) --- stdlib/3/http/__init__.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/3/http/__init__.pyi b/stdlib/3/http/__init__.pyi index 54aae66660dc..8e12f7997d76 100644 --- a/stdlib/3/http/__init__.pyi +++ b/stdlib/3/http/__init__.pyi @@ -1,3 +1,4 @@ +import sys from enum import IntEnum class HTTPStatus(IntEnum): @@ -5,7 +6,6 @@ class HTTPStatus(IntEnum): def phrase(self) -> str: ... @property def description(self) -> str: ... - CONTINUE: int SWITCHING_PROTOCOLS: int PROCESSING: int @@ -63,3 +63,5 @@ class HTTPStatus(IntEnum): LOOP_DETECTED: int NOT_EXTENDED: int NETWORK_AUTHENTICATION_REQUIRED: int + if sys.version_info >= (3, 7): + MISDIRECTED_REQUEST: int From ad881f94d733c948cc83f667929f87fd1135a5dc Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Tue, 1 Oct 2019 17:45:47 -0700 Subject: [PATCH 184/201] Add the mypyc_attr function to mypy_extensions (#3290) --- third_party/2and3/mypy_extensions.pyi | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/third_party/2and3/mypy_extensions.pyi b/third_party/2and3/mypy_extensions.pyi index f42162c0eb1e..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') @@ -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]): ... From 455f25a5c72fdca91185599f878f7648f9cbd016 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Tue, 1 Oct 2019 23:03:57 -0700 Subject: [PATCH 185/201] Use Any instead of object in the view types for __and__ and __sub__ (#3294) This was discussed in #3181 and the correct explanation was given that object ought to be preferred here. In practice this caused an obscure issue with mypy when using this operations on the results of six.viewkeys(), since it decided that it wanted a mapping *from* object as a result of inference contexts. Grumble. --- stdlib/3/typing.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 4aa4988bd25f..fb279c01f46b 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -335,25 +335,25 @@ 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[object]) -> Set[Tuple[_KT_co, _VT_co]]: ... + 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]) -> 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[object]) -> Set[Tuple[_KT_co, _VT_co]]: ... + 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[object]) -> Set[_KT_co]: ... + 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]) -> Set[Union[_KT_co, _T]]: ... def __ror__(self, o: Iterable[_T]) -> Set[Union[_KT_co, _T]]: ... - def __sub__(self, o: Iterable[object]) -> Set[_KT_co]: ... + 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]]: ... From eeb8daa4675cb47a0e4432699be5f262bbca4658 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Tue, 1 Oct 2019 23:09:21 -0700 Subject: [PATCH 186/201] Remove some spurious version checks in logging (#3292) PR #3269 added some version checks for the argument type to setLevel and the existence of NullHandler. While these features weren't present in early versions of Python 3, they *are* present in Python 2.7, which leads to false positives. --- stdlib/2and3/logging/__init__.pyi | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/stdlib/2and3/logging/__init__.pyi b/stdlib/2and3/logging/__init__.pyi index d95cf50e1ef4..79ee6261b22b 100644 --- a/stdlib/2and3/logging/__init__.pyi +++ b/stdlib/2and3/logging/__init__.pyi @@ -18,10 +18,7 @@ else: _ExcInfoType = Union[None, bool, _SysExcInfoType] _ArgsType = Union[Tuple[Any, ...], Mapping[str, Any]] _FilterType = Union[Filter, Callable[[LogRecord], int]] -if sys.version_info >= (3, 2): - _Level = Union[int, Text] -else: - _Level = int +_Level = Union[int, Text] if sys.version_info >= (3, 6): from os import PathLike _Path = Union[str, PathLike[str]] @@ -403,8 +400,7 @@ class FileHandler(StreamHandler): encoding: Optional[str] = ..., delay: bool = ...) -> None: ... -if sys.version_info >= (3, 1): - class NullHandler(Handler): ... +class NullHandler(Handler): ... class PlaceHolder: From c38cf6736e3eee4d0fb507861b051008d73d23cd Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 2 Oct 2019 15:52:21 -0700 Subject: [PATCH 187/201] Allow callables in _SourceObjectType (#3295) This is important because mypy doesn't generally think functions are compatible with `FunctionType`, so `inspect.getsource` on arbitrary functions is rejected by the current annotations. --- stdlib/3/inspect.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/inspect.pyi b/stdlib/3/inspect.pyi index 5c518b81baab..099041551d94 100644 --- a/stdlib/3/inspect.pyi +++ b/stdlib/3/inspect.pyi @@ -77,7 +77,7 @@ def ismemberdescriptor(object: object) -> bool: ... # # Retrieving source code # -_SourceObjectType = Union[ModuleType, Type[Any], MethodType, FunctionType, TracebackType, FrameType, CodeType] +_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: ... From 9a1d205f344547edee1d5b09cc7c2e0de024d657 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Wed, 2 Oct 2019 16:09:25 -0700 Subject: [PATCH 188/201] cryptography: Return RSAPrivateKeyWithSerialization from generate_private_key. (#3296) The only extant implementation of generate_private_key returns this more specialized interface. --- third_party/2/cryptography/hazmat/primitives/asymmetric/rsa.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/2/cryptography/hazmat/primitives/asymmetric/rsa.pyi b/third_party/2/cryptography/hazmat/primitives/asymmetric/rsa.pyi index 006e8221e6c5..310ced7ca0c8 100644 --- a/third_party/2/cryptography/hazmat/primitives/asymmetric/rsa.pyi +++ b/third_party/2/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: ... From fa571fb224ab4872e74c194d8dc4c89e1e9b76d0 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Fri, 4 Oct 2019 03:45:41 +0530 Subject: [PATCH 189/201] builtins.pyi: Use two type vars (#3291) Fixes: #3201 --- stdlib/2/__builtin__.pyi | 4 +++- stdlib/2and3/builtins.pyi | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 62052cfb7186..85b681a522c4 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -1189,7 +1189,9 @@ else: @overload def iter(__iterable: Iterable[_T]) -> Iterator[_T]: ... @overload -def iter(__function: Callable[[], _T], __sentinel: _T) -> Iterator[_T]: ... +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: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 62052cfb7186..85b681a522c4 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -1189,7 +1189,9 @@ else: @overload def iter(__iterable: Iterable[_T]) -> Iterator[_T]: ... @overload -def iter(__function: Callable[[], _T], __sentinel: _T) -> Iterator[_T]: ... +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: ... From e62857f851b24625948d6f7dd2203a67680a69dd Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Fri, 4 Oct 2019 13:55:46 +0300 Subject: [PATCH 190/201] Updated maxminddb stubs to v1.5.0 (#3300) --- third_party/3/maxminddb/reader.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/third_party/3/maxminddb/reader.pyi b/third_party/3/maxminddb/reader.pyi index 4a963a65c8ec..47e7f6493a8f 100644 --- a/third_party/3/maxminddb/reader.pyi +++ b/third_party/3/maxminddb/reader.pyi @@ -3,13 +3,14 @@ from ipaddress import IPv4Address, IPv6Address from types import TracebackType -from typing import Any, Mapping, Optional, Sequence, Type, Union +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: str) -> Optional[Any]: ... + 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: ... From 41d23a67f656aebd87b44eb7e71b8db027b12229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jeremy=20Lain=C3=A9?= Date: Fri, 4 Oct 2019 16:27:30 +0200 Subject: [PATCH 191/201] ssl: add VerifyFlags flags and VerifyMode enum (#3302) Closes #3301 --- stdlib/2and3/ssl.pyi | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/stdlib/2and3/ssl.pyi b/stdlib/2and3/ssl.pyi index 83717d00c66d..3e358f356004 100644 --- a/stdlib/2and3/ssl.pyi +++ b/stdlib/2and3/ssl.pyi @@ -303,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 From 0a426d8a8e269d33b5aa0c4bc53c38ba10c5a52e Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 4 Oct 2019 23:11:42 +0200 Subject: [PATCH 192/201] Move cryptography from 2 to 2and3 (#3304) The cryptography stubs are very rudimentary at the moment, but there is nothing that limits them to just Python 2. Closes: #3303 --- third_party/{2 => 2and3}/cryptography/__init__.pyi | 0 third_party/{2 => 2and3}/cryptography/hazmat/__init__.pyi | 0 .../{2 => 2and3}/cryptography/hazmat/primitives/__init__.pyi | 0 .../cryptography/hazmat/primitives/asymmetric/__init__.pyi | 0 .../cryptography/hazmat/primitives/asymmetric/dsa.pyi | 0 .../cryptography/hazmat/primitives/asymmetric/rsa.pyi | 0 .../{2 => 2and3}/cryptography/hazmat/primitives/serialization.pyi | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename third_party/{2 => 2and3}/cryptography/__init__.pyi (100%) rename third_party/{2 => 2and3}/cryptography/hazmat/__init__.pyi (100%) rename third_party/{2 => 2and3}/cryptography/hazmat/primitives/__init__.pyi (100%) rename third_party/{2 => 2and3}/cryptography/hazmat/primitives/asymmetric/__init__.pyi (100%) rename third_party/{2 => 2and3}/cryptography/hazmat/primitives/asymmetric/dsa.pyi (100%) rename third_party/{2 => 2and3}/cryptography/hazmat/primitives/asymmetric/rsa.pyi (100%) rename third_party/{2 => 2and3}/cryptography/hazmat/primitives/serialization.pyi (100%) 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 100% rename from third_party/2/cryptography/hazmat/primitives/asymmetric/rsa.pyi rename to third_party/2and3/cryptography/hazmat/primitives/asymmetric/rsa.pyi 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 From 90aa27b54a03d52e9dfccbff0a5c44514b335f0c Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Fri, 4 Oct 2019 14:53:48 -0700 Subject: [PATCH 193/201] Fix the signature of IOBase._checkClosed(). (#3305) * In Python 2, the optional `msg` argument was missing. * In Python 3, the method was missing altogether. Reference: https://github.com/python/cpython/blob/2.7/Lib/_pyio.py#L423 https://github.com/python/cpython/blob/3.6/Lib/_pyio.py#L443 --- stdlib/2/_io.pyi | 2 +- stdlib/3/io.pyi | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/2/_io.pyi b/stdlib/2/_io.pyi index d0185ae7da0c..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: ... diff --git a/stdlib/3/io.pyi b/stdlib/3/io.pyi index acab18ca179c..22a8784a755e 100644 --- a/stdlib/3/io.pyi +++ b/stdlib/3/io.pyi @@ -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: ... From 83589844c9f1a9629dc470a564766d10934c755a Mon Sep 17 00:00:00 2001 From: Glyph Date: Fri, 4 Oct 2019 16:49:49 -0700 Subject: [PATCH 194/201] rrule.weekday(...) returns rrule.weekdays, not _common.weekdays. (#3274) --- third_party/2and3/dateutil/_common.pyi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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: ... From cd418e95462553293375bde22ef7e09b98bb2d99 Mon Sep 17 00:00:00 2001 From: sinancepel Date: Fri, 4 Oct 2019 19:16:32 -0700 Subject: [PATCH 195/201] introduce __floor__ and __ceil__ for int in Python 3 (#3306) --- stdlib/2/__builtin__.pyi | 2 ++ stdlib/2and3/builtins.pyi | 2 ++ 2 files changed, 4 insertions(+) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 85b681a522c4..966e150897eb 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -185,6 +185,8 @@ class 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]: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 85b681a522c4..966e150897eb 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -185,6 +185,8 @@ class 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]: ... From 79a8f0b8c6ee27fd516c6ab839a39652b21e5c28 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Sat, 5 Oct 2019 08:40:21 +0530 Subject: [PATCH 196/201] imaplib.pyi: Take strings as args instead of a list of strings (#3308) Fixes: #3289 --- stdlib/2and3/imaplib.pyi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stdlib/2and3/imaplib.pyi b/stdlib/2and3/imaplib.pyi index 1653ae344a26..c22a47533355 100644 --- a/stdlib/2and3/imaplib.pyi +++ b/stdlib/2and3/imaplib.pyi @@ -72,18 +72,18 @@ 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): From 3743b64b072330279c98a9280c1e3c3651585074 Mon Sep 17 00:00:00 2001 From: Ryan Morshead Date: Sun, 6 Oct 2019 02:33:26 -0700 Subject: [PATCH 197/201] IncrementalNewlineDecoder.decode accepts str (#3312) The decode method of IncrementalNewlineDecoder accepts a string when its decoder is None. --- stdlib/3/io.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/io.pyi b/stdlib/3/io.pyi index 22a8784a755e..ab32adc5f6dc 100644 --- a/stdlib/3/io.pyi +++ b/stdlib/3/io.pyi @@ -206,4 +206,4 @@ class StringIO(TextIOWrapper): def __enter__(self) -> StringIO: ... class IncrementalNewlineDecoder(codecs.IncrementalDecoder): - def decode(self, input: bytes, final: bool = ...) -> str: ... + def decode(self, input: Union[bytes, str], final: bool = ...) -> str: ... From b9342eca0a654933d9db2bf8fbe1b2a3be06f7ba Mon Sep 17 00:00:00 2001 From: Ryan Morshead Date: Sun, 6 Oct 2019 08:22:03 -0700 Subject: [PATCH 198/201] add IncrementalNewlineDecoder constructor (#3311) --- stdlib/3/io.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stdlib/3/io.pyi b/stdlib/3/io.pyi index ab32adc5f6dc..351d5be86d2c 100644 --- a/stdlib/3/io.pyi +++ b/stdlib/3/io.pyi @@ -206,4 +206,6 @@ class StringIO(TextIOWrapper): def __enter__(self) -> StringIO: ... class IncrementalNewlineDecoder(codecs.IncrementalDecoder): + def __init__(self, decoder: Optional[codecs.IncrementalDecoder], + translate: bool, errors: str = ...) -> None: ... def decode(self, input: Union[bytes, str], final: bool = ...) -> str: ... From 717cd1f96f1df3f00b9e5e569d40ae5172ffd800 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Sun, 6 Oct 2019 22:27:22 +0530 Subject: [PATCH 199/201] imaplib.pyi: Add ssl_context parameter for Python >= 3.3 (#3310) Fixes: #3289 --- stdlib/2and3/imaplib.pyi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stdlib/2and3/imaplib.pyi b/stdlib/2and3/imaplib.pyi index c22a47533355..d24070312724 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]] @@ -89,7 +89,10 @@ class IMAP4: 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 = ... From 447691cf46d7b84df0db75370eb79596911645c6 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Mon, 7 Oct 2019 08:18:48 +0530 Subject: [PATCH 200/201] imaplib.pyi: Add missing imaplib.IMAP4.enable() (#3314) Closes: #3313 --- stdlib/2and3/imaplib.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stdlib/2and3/imaplib.pyi b/stdlib/2and3/imaplib.pyi index d24070312724..07272ce02548 100644 --- a/stdlib/2and3/imaplib.pyi +++ b/stdlib/2and3/imaplib.pyi @@ -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: ... From 7710e925ca8bd2b3b425bec7550895296758736f Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Mon, 7 Oct 2019 11:05:19 -0400 Subject: [PATCH 201/201] Add `data` to UserList class, fix UserDict.data type (#3316) --- stdlib/2/UserDict.pyi | 2 +- stdlib/2/UserList.pyi | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) 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 97ba17a9b513..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") _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: ...