From 56bba4793d20187b22feb3df4e219a4750194c19 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Thu, 17 Sep 2020 18:43:27 +0200 Subject: [PATCH 1/3] Add various missing undocumented functions Mostly addresses #2149 --- stdlib/2and3/pickle.pyi | 7 ++++++- stdlib/2and3/pkgutil.pyi | 4 ++-- stdlib/2and3/sre_compile.pyi | 14 ++++++++++++++ stdlib/3/_thread.pyi | 2 -- stdlib/3/urllib/request.pyi | 3 +-- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/stdlib/2and3/pickle.pyi b/stdlib/2and3/pickle.pyi index 5ca023db831e..ddf8a4401399 100644 --- a/stdlib/2and3/pickle.pyi +++ b/stdlib/2and3/pickle.pyi @@ -1,10 +1,12 @@ import sys -from typing import IO, Any, Callable, Iterable, Iterator, Mapping, Optional, Tuple, Union +from typing import IO, Any, Callable, Iterable, Iterator, Mapping, Optional, Tuple, Type, Union HIGHEST_PROTOCOL: int if sys.version_info >= (3, 0): DEFAULT_PROTOCOL: int +bytes_types: Tuple[Type[Any], ...] # undocumented + if sys.version_info >= (3, 8): # TODO: holistic design for buffer interface (typing.Buffer?) class PickleBuffer: @@ -179,3 +181,6 @@ if sys.version_info >= (3, 4): STACK_GLOBAL: bytes MEMOIZE: bytes FRAME: bytes + +def encode_long(x: int) -> bytes: ... # undocumented +def decode_long(data: bytes) -> int: ... # undocumented diff --git a/stdlib/2and3/pkgutil.pyi b/stdlib/2and3/pkgutil.pyi index 0bc7167d0e3f..5fd025411325 100644 --- a/stdlib/2and3/pkgutil.pyi +++ b/stdlib/2and3/pkgutil.pyi @@ -1,6 +1,5 @@ -# Stubs for pkgutil - import sys +from _typeshed import SupportsRead from typing import IO, Any, Callable, Iterable, Iterator, NamedTuple, Optional, Tuple, Union if sys.version_info >= (3,): @@ -32,6 +31,7 @@ def get_importer(path_item: str) -> Optional[PathEntryFinder]: ... def get_loader(module_or_name: str) -> Loader: ... def iter_importers(fullname: str = ...) -> Iterator[Union[MetaPathFinder, PathEntryFinder]]: ... def iter_modules(path: Optional[Iterable[str]] = ..., prefix: str = ...) -> Iterator[_ModuleInfoLike]: ... +def read_code(stream: SupportsRead[bytes]) -> Any: ... # undocumented def walk_packages( path: Optional[Iterable[str]] = ..., prefix: str = ..., onerror: Optional[Callable[[str], None]] = ... ) -> Iterator[_ModuleInfoLike]: ... diff --git a/stdlib/2and3/sre_compile.pyi b/stdlib/2and3/sre_compile.pyi index 86621c3dae09..4972744c72bf 100644 --- a/stdlib/2and3/sre_compile.pyi +++ b/stdlib/2and3/sre_compile.pyi @@ -5,6 +5,20 @@ import sys from sre_parse import SubPattern from typing import Any, List, Pattern, Tuple, Type, Union +# SRE_* constants are undocumented +SRE_FLAG_ASCII: int +SRE_FLAG_DEBUG: int +SRE_FLAG_DOTALL: int +SRE_FLAG_IGNORECASE: int +SRE_FLAG_LOCALE: int +SRE_FLAG_MULTILINE: int +SRE_FLAG_TEMPLATE: int +SRE_FLAG_UNICODE: int +SRE_FLAG_VERBOSE: int +SRE_INFO_CHARSET: int +SRE_INFO_LITERAL: int +SRE_INFO_PREFIX: int + MAXCODE: int if sys.version_info < (3, 0): STRING_TYPES: Tuple[Type[str], Type[unicode]] diff --git a/stdlib/3/_thread.pyi b/stdlib/3/_thread.pyi index ded307b03659..3984630244ec 100644 --- a/stdlib/3/_thread.pyi +++ b/stdlib/3/_thread.pyi @@ -1,5 +1,3 @@ -# Stubs for _thread - import sys from threading import Thread from types import TracebackType diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index bd20c1939e41..11529d5f0218 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -1,5 +1,3 @@ -# Stubs for urllib.request (Python 3.4) - import os import ssl import sys @@ -7,6 +5,7 @@ from email.message import Message from http.client import HTTPMessage, HTTPResponse, _HTTPConnectionProtocol from http.cookiejar import CookieJar from typing import IO, Any, Callable, ClassVar, Dict, List, Mapping, NoReturn, Optional, Sequence, Tuple, TypeVar, Union, overload +from urllib.error import HTTPError as HTTPError from urllib.response import addinfourl _T = TypeVar("_T") From c4b50d38329ee4c4a5f12973b717454769e45c78 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 18 Sep 2020 12:19:41 +0200 Subject: [PATCH 2/3] Remove HTTPError re-export from urllib.request --- stdlib/3/urllib/request.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index 11529d5f0218..1e529067b75f 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -5,7 +5,6 @@ from email.message import Message from http.client import HTTPMessage, HTTPResponse, _HTTPConnectionProtocol from http.cookiejar import CookieJar from typing import IO, Any, Callable, ClassVar, Dict, List, Mapping, NoReturn, Optional, Sequence, Tuple, TypeVar, Union, overload -from urllib.error import HTTPError as HTTPError from urllib.response import addinfourl _T = TypeVar("_T") From 28a30cf48e13a9f12ea8c04ddba07e2af0d431cf Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 18 Sep 2020 12:33:13 +0200 Subject: [PATCH 3/3] Reexport SRE_ constants from sre_constants --- stdlib/2and3/sre_compile.pyi | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/stdlib/2and3/sre_compile.pyi b/stdlib/2and3/sre_compile.pyi index 4972744c72bf..708fa603c91f 100644 --- a/stdlib/2and3/sre_compile.pyi +++ b/stdlib/2and3/sre_compile.pyi @@ -2,22 +2,24 @@ # and https://github.com/python/cpython/blob/master/Lib/sre_compile.py import sys +from sre_constants import ( + SRE_FLAG_DEBUG as SRE_FLAG_DEBUG, + SRE_FLAG_DOTALL as SRE_FLAG_DOTALL, + SRE_FLAG_IGNORECASE as SRE_FLAG_IGNORECASE, + SRE_FLAG_LOCALE as SRE_FLAG_LOCALE, + SRE_FLAG_MULTILINE as SRE_FLAG_MULTILINE, + SRE_FLAG_TEMPLATE as SRE_FLAG_TEMPLATE, + SRE_FLAG_UNICODE as SRE_FLAG_UNICODE, + SRE_FLAG_VERBOSE as SRE_FLAG_VERBOSE, + SRE_INFO_CHARSET as SRE_INFO_CHARSET, + SRE_INFO_LITERAL as SRE_INFO_LITERAL, + SRE_INFO_PREFIX as SRE_INFO_PREFIX, +) from sre_parse import SubPattern from typing import Any, List, Pattern, Tuple, Type, Union -# SRE_* constants are undocumented -SRE_FLAG_ASCII: int -SRE_FLAG_DEBUG: int -SRE_FLAG_DOTALL: int -SRE_FLAG_IGNORECASE: int -SRE_FLAG_LOCALE: int -SRE_FLAG_MULTILINE: int -SRE_FLAG_TEMPLATE: int -SRE_FLAG_UNICODE: int -SRE_FLAG_VERBOSE: int -SRE_INFO_CHARSET: int -SRE_INFO_LITERAL: int -SRE_INFO_PREFIX: int +if sys.version_info >= (3,): + from sre_constants import SRE_FLAG_ASCII as SRE_FLAG_ASCII MAXCODE: int if sys.version_info < (3, 0):