From 3ead05f277844320b60f93232618e51a223f46e3 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 20 Feb 2022 23:06:54 +0000 Subject: [PATCH] Add `__all__` to modules beginning with 'j', 'k' and 'l' (#7328) --- stdlib/json/__init__.pyi | 2 + stdlib/json/decoder.pyi | 2 + stdlib/keyword.pyi | 5 + stdlib/lib2to3/pgen2/driver.pyi | 2 + stdlib/lib2to3/pgen2/tokenize.pyi | 147 +++++++++++++++++++++++++++++- stdlib/linecache.pyi | 6 ++ stdlib/locale.pyi | 26 ++++++ stdlib/logging/__init__.pyi | 45 +++++++++ stdlib/lzma.pyi | 39 ++++++++ 9 files changed, 273 insertions(+), 1 deletion(-) diff --git a/stdlib/json/__init__.pyi b/stdlib/json/__init__.pyi index b9867b55f..8e1a36756 100644 --- a/stdlib/json/__init__.pyi +++ b/stdlib/json/__init__.pyi @@ -4,6 +4,8 @@ from typing import IO, Any, Callable from .decoder import JSONDecodeError as JSONDecodeError, JSONDecoder as JSONDecoder from .encoder import JSONEncoder as JSONEncoder +__all__ = ["dump", "dumps", "load", "loads", "JSONDecoder", "JSONDecodeError", "JSONEncoder"] + def dumps( obj: Any, *, diff --git a/stdlib/json/decoder.pyi b/stdlib/json/decoder.pyi index adf09bb4b..866836758 100644 --- a/stdlib/json/decoder.pyi +++ b/stdlib/json/decoder.pyi @@ -1,5 +1,7 @@ from typing import Any, Callable +__all__ = ["JSONDecoder", "JSONDecodeError"] + class JSONDecodeError(ValueError): msg: str doc: str diff --git a/stdlib/keyword.pyi b/stdlib/keyword.pyi index ac052feeb..e9a9877d5 100644 --- a/stdlib/keyword.pyi +++ b/stdlib/keyword.pyi @@ -1,6 +1,11 @@ import sys from typing import Sequence +if sys.version_info >= (3, 9): + __all__ = ["iskeyword", "issoftkeyword", "kwlist", "softkwlist"] +else: + __all__ = ["iskeyword", "kwlist"] + def iskeyword(s: str) -> bool: ... kwlist: Sequence[str] diff --git a/stdlib/lib2to3/pgen2/driver.pyi b/stdlib/lib2to3/pgen2/driver.pyi index a8159dccf..4ecba0319 100644 --- a/stdlib/lib2to3/pgen2/driver.pyi +++ b/stdlib/lib2to3/pgen2/driver.pyi @@ -4,6 +4,8 @@ from lib2to3.pytree import _NL, _Convert from logging import Logger from typing import IO, Any, Iterable +__all__ = ["Driver", "load_grammar"] + class Driver: grammar: Grammar logger: Logger diff --git a/stdlib/lib2to3/pgen2/tokenize.pyi b/stdlib/lib2to3/pgen2/tokenize.pyi index 3679caee9..c1b5a91df 100644 --- a/stdlib/lib2to3/pgen2/tokenize.pyi +++ b/stdlib/lib2to3/pgen2/tokenize.pyi @@ -1,6 +1,151 @@ -from lib2to3.pgen2.token import * # noqa +import sys +from lib2to3.pgen2.token import * from typing import Callable, Iterable, Iterator +if sys.version_info >= (3, 8): + __all__ = [ + "AMPER", + "AMPEREQUAL", + "ASYNC", + "AT", + "ATEQUAL", + "AWAIT", + "BACKQUOTE", + "CIRCUMFLEX", + "CIRCUMFLEXEQUAL", + "COLON", + "COLONEQUAL", + "COMMA", + "COMMENT", + "DEDENT", + "DOT", + "DOUBLESLASH", + "DOUBLESLASHEQUAL", + "DOUBLESTAR", + "DOUBLESTAREQUAL", + "ENDMARKER", + "EQEQUAL", + "EQUAL", + "ERRORTOKEN", + "GREATER", + "GREATEREQUAL", + "INDENT", + "ISEOF", + "ISNONTERMINAL", + "ISTERMINAL", + "LBRACE", + "LEFTSHIFT", + "LEFTSHIFTEQUAL", + "LESS", + "LESSEQUAL", + "LPAR", + "LSQB", + "MINEQUAL", + "MINUS", + "NAME", + "NEWLINE", + "NL", + "NOTEQUAL", + "NT_OFFSET", + "NUMBER", + "N_TOKENS", + "OP", + "PERCENT", + "PERCENTEQUAL", + "PLUS", + "PLUSEQUAL", + "RARROW", + "RBRACE", + "RIGHTSHIFT", + "RIGHTSHIFTEQUAL", + "RPAR", + "RSQB", + "SEMI", + "SLASH", + "SLASHEQUAL", + "STAR", + "STAREQUAL", + "STRING", + "TILDE", + "VBAR", + "VBAREQUAL", + "tok_name", + "tokenize", + "generate_tokens", + "untokenize", + ] +else: + __all__ = [ + "AMPER", + "AMPEREQUAL", + "ASYNC", + "AT", + "ATEQUAL", + "AWAIT", + "BACKQUOTE", + "CIRCUMFLEX", + "CIRCUMFLEXEQUAL", + "COLON", + "COMMA", + "COMMENT", + "DEDENT", + "DOT", + "DOUBLESLASH", + "DOUBLESLASHEQUAL", + "DOUBLESTAR", + "DOUBLESTAREQUAL", + "ENDMARKER", + "EQEQUAL", + "EQUAL", + "ERRORTOKEN", + "GREATER", + "GREATEREQUAL", + "INDENT", + "ISEOF", + "ISNONTERMINAL", + "ISTERMINAL", + "LBRACE", + "LEFTSHIFT", + "LEFTSHIFTEQUAL", + "LESS", + "LESSEQUAL", + "LPAR", + "LSQB", + "MINEQUAL", + "MINUS", + "NAME", + "NEWLINE", + "NL", + "NOTEQUAL", + "NT_OFFSET", + "NUMBER", + "N_TOKENS", + "OP", + "PERCENT", + "PERCENTEQUAL", + "PLUS", + "PLUSEQUAL", + "RARROW", + "RBRACE", + "RIGHTSHIFT", + "RIGHTSHIFTEQUAL", + "RPAR", + "RSQB", + "SEMI", + "SLASH", + "SLASHEQUAL", + "STAR", + "STAREQUAL", + "STRING", + "TILDE", + "VBAR", + "VBAREQUAL", + "tok_name", + "tokenize", + "generate_tokens", + "untokenize", + ] + _Coord = tuple[int, int] _TokenEater = Callable[[int, str, _Coord, _Coord, str], None] _TokenInfo = tuple[int, str, _Coord, _Coord, str] diff --git a/stdlib/linecache.pyi b/stdlib/linecache.pyi index e53d3efea..6b3761f4a 100644 --- a/stdlib/linecache.pyi +++ b/stdlib/linecache.pyi @@ -1,5 +1,11 @@ +import sys from typing import Any, Protocol +if sys.version_info >= (3, 9): + __all__ = ["getline", "clearcache", "checkcache", "lazycache"] +else: + __all__ = ["getline", "clearcache", "checkcache"] + _ModuleGlobals = dict[str, Any] _ModuleMetadata = tuple[int, float, list[str], str] diff --git a/stdlib/locale.pyi b/stdlib/locale.pyi index 38912c5c6..60945b886 100644 --- a/stdlib/locale.pyi +++ b/stdlib/locale.pyi @@ -1,6 +1,32 @@ import sys from _typeshed import StrPath +__all__ = [ + "getlocale", + "getdefaultlocale", + "getpreferredencoding", + "Error", + "setlocale", + "resetlocale", + "localeconv", + "strcoll", + "strxfrm", + "str", + "atof", + "atoi", + "format", + "format_string", + "currency", + "normalize", + "LC_CTYPE", + "LC_COLLATE", + "LC_MESSAGES" "LC_TIME", + "LC_MONETARY", + "LC_NUMERIC", + "LC_ALL", + "CHAR_MAX", +] + # This module defines a function "str()", which is why "str" can't be used # as a type annotation or type alias. from builtins import str as _str diff --git a/stdlib/logging/__init__.pyi b/stdlib/logging/__init__.pyi index dd746427d..b3f17b943 100644 --- a/stdlib/logging/__init__.pyi +++ b/stdlib/logging/__init__.pyi @@ -9,6 +9,51 @@ from types import FrameType, TracebackType from typing import Any, ClassVar, Generic, Optional, Pattern, TextIO, TypeVar, Union, overload from typing_extensions import Literal +__all__ = [ + "BASIC_FORMAT", + "BufferingFormatter", + "CRITICAL", + "DEBUG", + "ERROR", + "FATAL", + "FileHandler", + "Filter", + "Formatter", + "Handler", + "INFO", + "LogRecord", + "Logger", + "LoggerAdapter", + "NOTSET", + "NullHandler", + "StreamHandler", + "WARN", + "WARNING", + "addLevelName", + "basicConfig", + "captureWarnings", + "critical", + "debug", + "disable", + "error", + "exception", + "fatal", + "getLevelName", + "getLogger", + "getLoggerClass", + "info", + "log", + "makeLogRecord", + "setLoggerClass", + "shutdown", + "warn", + "warning", + "getLogRecordFactory", + "setLogRecordFactory", + "lastResort", + "raiseExceptions", +] + _SysExcInfoType = Union[tuple[type[BaseException], BaseException, Optional[TracebackType]], tuple[None, None, None]] _ExcInfoType = Union[None, bool, _SysExcInfoType, BaseException] _ArgsType = Union[tuple[object, ...], Mapping[str, object]] diff --git a/stdlib/lzma.pyi b/stdlib/lzma.pyi index 89083973b..c469c218a 100644 --- a/stdlib/lzma.pyi +++ b/stdlib/lzma.pyi @@ -3,6 +3,45 @@ from _typeshed import ReadableBuffer, Self, StrOrBytesPath from typing import IO, Any, Mapping, Sequence, TextIO, Union, overload from typing_extensions import Literal, final +__all__ = [ + "CHECK_NONE", + "CHECK_CRC32", + "CHECK_CRC64", + "CHECK_SHA256", + "CHECK_ID_MAX", + "CHECK_UNKNOWN", + "FILTER_LZMA1", + "FILTER_LZMA2", + "FILTER_DELTA", + "FILTER_X86", + "FILTER_IA64", + "FILTER_ARM", + "FILTER_ARMTHUMB", + "FILTER_POWERPC", + "FILTER_SPARC", + "FORMAT_AUTO", + "FORMAT_XZ", + "FORMAT_ALONE", + "FORMAT_RAW", + "MF_HC3", + "MF_HC4", + "MF_BT2", + "MF_BT3", + "MF_BT4", + "MODE_FAST", + "MODE_NORMAL", + "PRESET_DEFAULT", + "PRESET_EXTREME", + "LZMACompressor", + "LZMADecompressor", + "LZMAFile", + "LZMAError", + "open", + "compress", + "decompress", + "is_check_supported", +] + _OpenBinaryWritingMode = Literal["w", "wb", "x", "xb", "a", "ab"] _OpenTextWritingMode = Literal["wt", "xt", "at"]