From 0d120cd52454d0029f60d99db2e5b923cce2a895 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sun, 8 Aug 2021 21:22:36 +0300 Subject: [PATCH 1/8] multiprocessing.managers --- stdlib/multiprocessing/managers.pyi | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/stdlib/multiprocessing/managers.pyi b/stdlib/multiprocessing/managers.pyi index 422a7fd6266d..568845bfb9e4 100644 --- a/stdlib/multiprocessing/managers.pyi +++ b/stdlib/multiprocessing/managers.pyi @@ -3,7 +3,7 @@ import queue import sys import threading -from typing import Any, AnyStr, Callable, ContextManager, Dict, Generic, Iterable, List, Mapping, Sequence, Tuple, TypeVar +from typing import Any, AnyStr, Callable, ContextManager, Generic, Iterable, Mapping, Sequence, Tuple, TypeVar from .connection import Connection from .context import BaseContext @@ -38,7 +38,7 @@ class Token(object): def __setstate__(self, state: Tuple[str | bytes | None, Tuple[str | bytes, int], str | bytes | int | None]) -> None: ... class BaseProxy(object): - _address_to_local: Dict[Any, Any] + _address_to_local: dict[Any, Any] _mutex: Any def __init__( self, @@ -51,9 +51,9 @@ class BaseProxy(object): manager_owned: bool = ..., ) -> None: ... def __deepcopy__(self, memo: Any | None) -> Any: ... - def _callmethod(self, methodname: str, args: Tuple[Any, ...] = ..., kwds: Dict[Any, Any] = ...) -> None: ... + def _callmethod(self, methodname: str, args: Tuple[Any, ...] = ..., kwds: dict[Any, Any] = ...) -> None: ... def _getvalue(self) -> Any: ... - def __reduce__(self) -> Tuple[Any, Tuple[Any, Any, str, Dict[Any, Any]]]: ... + def __reduce__(self) -> Tuple[Any, Tuple[Any, Any, str, dict[Any, Any]]]: ... class ValueProxy(BaseProxy, Generic[_T]): def get(self) -> _T: ... @@ -66,7 +66,7 @@ class ValueProxy(BaseProxy, Generic[_T]): class Server: address: Any def __init__( - self, registry: Dict[str, Tuple[Callable[..., Any], Any, Any, Any]], address: Any, authkey: bytes, serializer: str + self, registry: dict[str, Tuple[Callable[..., Any], Any, Any, Any]], address: Any, authkey: bytes, serializer: str ) -> None: ... def serve_forever(self) -> None: ... def accept_connection(self, c: Connection, name: str) -> None: ... @@ -93,6 +93,10 @@ class BaseManager(ContextManager[BaseManager]): create_method: bool = ..., ) -> None: ... +# Conflicts with method names +_dict = dict +_list = list + class SyncManager(BaseManager, ContextManager[SyncManager]): def BoundedSemaphore(self, value: Any = ...) -> threading.BoundedSemaphore: ... def Condition(self, lock: Any = ...) -> threading.Condition: ... @@ -104,8 +108,8 @@ class SyncManager(BaseManager, ContextManager[SyncManager]): def Semaphore(self, value: Any = ...) -> threading.Semaphore: ... def Array(self, typecode: Any, sequence: Sequence[_T]) -> Sequence[_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]: ... + def dict(self, sequence: Mapping[_KT, _VT] = ...) -> _dict[_KT, _VT]: ... + def list(self, sequence: Sequence[_T] = ...) -> _list[_T]: ... class RemoteError(Exception): ... From c6a5d428a3ba25d303c50d29703bee37d03f5d1e Mon Sep 17 00:00:00 2001 From: Akuli Date: Sun, 8 Aug 2021 21:24:07 +0300 Subject: [PATCH 2/8] pydoc --- stdlib/pydoc.pyi | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/stdlib/pydoc.pyi b/stdlib/pydoc.pyi index daa8c27e0b1e..778a2e535706 100644 --- a/stdlib/pydoc.pyi +++ b/stdlib/pydoc.pyi @@ -1,7 +1,7 @@ from _typeshed import SupportsWrite from reprlib import Repr from types import MethodType, ModuleType, TracebackType -from typing import IO, Any, AnyStr, Callable, Container, Dict, List, Mapping, MutableMapping, NoReturn, Optional, Tuple, Type +from typing import IO, Any, AnyStr, Callable, Container, Mapping, MutableMapping, NoReturn, Optional, Tuple, Type # the return type of sys.exc_info(), used by ErrorDuringImport.__init__ _Exc_Info = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]] @@ -11,7 +11,7 @@ __date__: str __version__: str __credits__: str -def pathdirs() -> List[str]: ... +def pathdirs() -> list[str]: ... def getdoc(object: object) -> str: ... def splitdoc(doc: AnyStr) -> Tuple[AnyStr, AnyStr]: ... def classname(object: object, modname: str) -> str: ... @@ -21,7 +21,7 @@ def cram(text: str, maxlen: int) -> str: ... def stripid(text: str) -> str: ... def allmethods(cl: type) -> MutableMapping[str, MethodType]: ... def visiblename(name: str, all: Container[str] | None = ..., obj: object | None = ...) -> bool: ... -def classify_class_attrs(object: object) -> List[Tuple[str, str, type, str]]: ... +def classify_class_attrs(object: object) -> list[Tuple[str, str, type, str]]: ... def ispackage(path: str) -> bool: ... def source_synopsis(file: IO[AnyStr]) -> AnyStr | None: ... def synopsis(filename: str, cache: MutableMapping[str, Tuple[int, str]] = ...) -> str | None: ... @@ -81,7 +81,7 @@ class HTMLDoc(Doc): ) -> str: ... def bigsection(self, title: str, *args: Any) -> str: ... def preformat(self, text: str) -> str: ... - def multicolumn(self, list: List[Any], format: Callable[[Any], str], cols: int = ...) -> str: ... + def multicolumn(self, list: list[Any], format: Callable[[Any], str], cols: int = ...) -> str: ... def grey(self, text: str) -> str: ... def namelink(self, name: str, *dicts: MutableMapping[str, str]) -> str: ... def classlink(self, object: object, modname: str) -> str: ... @@ -96,7 +96,7 @@ class HTMLDoc(Doc): methods: Mapping[str, str] = ..., ) -> str: ... def formattree( - self, tree: List[Tuple[type, Tuple[type, ...]] | List[Any]], modname: str, parent: type | None = ... + self, tree: list[Tuple[type, Tuple[type, ...]] | list[Any]], modname: str, parent: type | None = ... ) -> str: ... def docmodule(self, object: object, name: str | None = ..., mod: str | None = ..., *ignored: Any) -> str: ... def docclass( @@ -148,7 +148,7 @@ class TextDoc(Doc): def indent(self, text: str, prefix: str = ...) -> str: ... def section(self, title: str, contents: str) -> str: ... def formattree( - self, tree: List[Tuple[type, Tuple[type, ...]] | List[Any]], modname: str, parent: type | None = ..., prefix: str = ... + self, tree: list[Tuple[type, Tuple[type, ...]] | list[Any]], modname: str, parent: type | None = ..., prefix: str = ... ) -> str: ... def docmodule(self, object: object, name: str | None = ..., mod: Any | None = ..., *ignored: Any) -> str: ... def docclass(self, object: object, name: str | None = ..., mod: str | None = ..., *ignored: Any) -> str: ... @@ -194,10 +194,12 @@ def doc(thing: str | object, title: str = ..., forceload: bool = ..., output: Su def writedoc(thing: str | object, forceload: bool = ...) -> None: ... def writedocs(dir: str, pkgpath: str = ..., done: Any | None = ...) -> None: ... +_list = list # "list" conflicts with method name + class Helper: - keywords: Dict[str, str | Tuple[str, str]] - symbols: Dict[str, str] - topics: Dict[str, str | Tuple[str, ...]] + keywords: dict[str, str | Tuple[str, str]] + symbols: dict[str, str] + topics: dict[str, str | Tuple[str, ...]] def __init__(self, input: IO[str] | None = ..., output: IO[str] | None = ...) -> None: ... input: IO[str] output: IO[str] @@ -206,7 +208,7 @@ class Helper: def getline(self, prompt: str) -> str: ... def help(self, request: Any) -> None: ... def intro(self) -> None: ... - def list(self, items: List[str], columns: int = ..., width: int = ...) -> None: ... + def list(self, items: _list[str], columns: int = ..., width: int = ...) -> None: ... def listkeywords(self) -> None: ... def listsymbols(self) -> None: ... def listtopics(self) -> None: ... From fb5557c5f0d2e1c1f2d0b0684aba59e839c8c9ba Mon Sep 17 00:00:00 2001 From: Akuli Date: Sun, 8 Aug 2021 21:25:49 +0300 Subject: [PATCH 3/8] tarfile --- stdlib/tarfile.pyi | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 0b33cc85ec60..53c986a3f017 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -5,7 +5,7 @@ from _typeshed import Self, StrOrBytesPath, StrPath from collections.abc import Callable, Iterable, Iterator, Mapping from gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj from types import TracebackType -from typing import IO, Dict, List, Protocol, Set, Tuple, Type, TypeVar, overload +from typing import IO, Protocol, Set, Tuple, Type, TypeVar, overload from typing_extensions import Literal _TF = TypeVar("_TF", bound=TarFile) @@ -66,7 +66,7 @@ SUPPORTED_TYPES: Tuple[bytes, ...] REGULAR_TYPES: Tuple[bytes, ...] GNU_TYPES: Tuple[bytes, ...] PAX_FIELDS: Tuple[str, ...] -PAX_NUMBER_FIELDS: Dict[str, type] +PAX_NUMBER_FIELDS: dict[str, type] PAX_NAME_FIELDS: Set[str] ENCODING: str @@ -92,6 +92,8 @@ def open( class ExFileObject(io.BufferedReader): def __init__(self, tarfile: TarFile, tarinfo: TarInfo) -> None: ... +_list = list # conflicts with method name + class TarFile: OPEN_METH: Mapping[str, str] name: StrOrBytesPath | None @@ -254,9 +256,9 @@ class TarFile: errorlevel: int | None = ..., ) -> _TF: ... def getmember(self, name: str) -> TarInfo: ... - def getmembers(self) -> List[TarInfo]: ... - def getnames(self) -> List[str]: ... - def list(self, verbose: bool = ..., *, members: List[TarInfo] | None = ...) -> None: ... + def getmembers(self) -> _list[TarInfo]: ... + def getnames(self) -> _list[str]: ... + def list(self, verbose: bool = ..., *, members: _list[TarInfo] | None = ...) -> None: ... def next(self) -> TarInfo | None: ... def extractall( self, path: StrOrBytesPath = ..., members: Iterable[TarInfo] | None = ..., *, numeric_owner: bool = ... From 1846aa8ad274c612a47992eef31caf59122738c9 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sun, 8 Aug 2021 21:28:07 +0300 Subject: [PATCH 4/8] lowercase list and dict in os/__init__.py --- stdlib/os/__init__.pyi | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index 3d13a43130a6..2cd63220c513 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -21,11 +21,9 @@ from typing import ( BinaryIO, Callable, ContextManager, - Dict, Generic, Iterable, Iterator, - List, Mapping, MutableMapping, NoReturn, @@ -213,7 +211,7 @@ class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]): unsetenv: Callable[[AnyStr, AnyStr], None], ) -> None: ... def setdefault(self, key: AnyStr, value: AnyStr) -> AnyStr: ... # type: ignore - def copy(self) -> Dict[AnyStr, AnyStr]: ... + def copy(self) -> dict[AnyStr, AnyStr]: ... def __delitem__(self, key: AnyStr) -> None: ... def __getitem__(self, key: AnyStr) -> AnyStr: ... def __setitem__(self, key: AnyStr, value: AnyStr) -> None: ... @@ -225,9 +223,9 @@ if sys.platform != "win32": environb: _Environ[bytes] if sys.platform != "win32": - confstr_names: Dict[str, int] - pathconf_names: Dict[str, int] - sysconf_names: Dict[str, int] + confstr_names: dict[str, int] + pathconf_names: dict[str, int] + sysconf_names: dict[str, int] EX_OK: int EX_USAGE: int @@ -336,7 +334,7 @@ if sys.platform != "win32": if sys.version_info >= (3, 7): # f_fsid was added in https://github.com/python/cpython/pull/4571 class statvfs_result(_Tuple10Int): # Unix only - def __new__(cls, seq: _Tuple10Int | _Tuple11Int, dict: Dict[str, int] = ...) -> statvfs_result: ... + def __new__(cls, seq: _Tuple10Int | _Tuple11Int, dict: dict[str, int] = ...) -> statvfs_result: ... n_fields: int n_sequence_fields: int n_unnamed_fields: int @@ -378,9 +376,9 @@ def fspath(path: str) -> str: ... def fspath(path: bytes) -> bytes: ... @overload def fspath(path: PathLike[AnyStr]) -> AnyStr: ... -def get_exec_path(env: Mapping[str, str] | None = ...) -> List[str]: ... +def get_exec_path(env: Mapping[str, str] | None = ...) -> list[str]: ... -# NOTE: get_exec_path(): returns List[bytes] when env not None +# NOTE: get_exec_path(): returns list[bytes] when env not None def getlogin() -> str: ... def getpid() -> int: ... def getppid() -> int: ... @@ -393,8 +391,8 @@ if sys.platform != "win32": def getegid() -> int: ... def geteuid() -> int: ... def getgid() -> int: ... - def getgrouplist(__user: str, __group: int) -> List[int]: ... - def getgroups() -> List[int]: ... # Unix only, behaves differently on Mac + def getgrouplist(__user: str, __group: 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: ... @@ -689,7 +687,7 @@ _OnError = Callable[[OSError], Any] def walk( top: AnyStr | PathLike[AnyStr], topdown: bool = ..., onerror: _OnError | None = ..., followlinks: bool = ... -) -> Iterator[Tuple[AnyStr, List[AnyStr], List[AnyStr]]]: ... +) -> Iterator[Tuple[AnyStr, list[AnyStr], list[AnyStr]]]: ... if sys.platform != "win32": if sys.version_info >= (3, 7): @@ -701,7 +699,7 @@ if sys.platform != "win32": *, follow_symlinks: bool = ..., dir_fd: int | None = ..., - ) -> Iterator[Tuple[str, List[str], List[str], int]]: ... + ) -> Iterator[Tuple[str, list[str], list[str], int]]: ... @overload def fwalk( top: bytes, @@ -710,7 +708,7 @@ if sys.platform != "win32": *, follow_symlinks: bool = ..., dir_fd: int | None = ..., - ) -> Iterator[Tuple[bytes, List[bytes], List[bytes], int]]: ... + ) -> Iterator[Tuple[bytes, list[bytes], list[bytes], int]]: ... else: def fwalk( top: StrPath = ..., @@ -719,10 +717,10 @@ if sys.platform != "win32": *, follow_symlinks: bool = ..., dir_fd: int | None = ..., - ) -> Iterator[Tuple[str, List[str], List[str], int]]: ... + ) -> Iterator[Tuple[str, list[str], list[str], int]]: ... if sys.platform == "linux": def getxattr(path: _FdOrAnyPath, attribute: StrOrBytesPath, *, follow_symlinks: bool = ...) -> bytes: ... - def listxattr(path: _FdOrAnyPath | None = ..., *, follow_symlinks: bool = ...) -> List[str]: ... + def listxattr(path: _FdOrAnyPath | None = ..., *, follow_symlinks: bool = ...) -> list[str]: ... def removexattr(path: _FdOrAnyPath, attribute: StrOrBytesPath, *, follow_symlinks: bool = ...) -> None: ... def setxattr( path: _FdOrAnyPath, attribute: StrOrBytesPath, value: bytes, flags: int = ..., *, follow_symlinks: bool = ... @@ -742,7 +740,7 @@ def execlpe(file: StrOrBytesPath, __arg0: StrOrBytesPath, *args: Any) -> NoRetur # The implementation enforces tuple or list so we can't use Sequence. # Not separating out PathLike[str] and PathLike[bytes] here because it doesn't make much difference # in practice, and doing so would explode the number of combinations in this already long union. -# All these combinations are necessary due to List being invariant. +# All these combinations are necessary due to list being invariant. _ExecVArgs = Union[ Tuple[StrOrBytesPath, ...], List[bytes], From a9f6573581bf72a366fe435b8258ada0177c4a43 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sun, 8 Aug 2021 21:30:21 +0300 Subject: [PATCH 5/8] delete old comment --- stdlib/os/__init__.pyi | 2 -- 1 file changed, 2 deletions(-) diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index 2cd63220c513..c17d3b5135b8 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -377,8 +377,6 @@ def fspath(path: bytes) -> bytes: ... @overload def fspath(path: PathLike[AnyStr]) -> AnyStr: ... def get_exec_path(env: Mapping[str, str] | None = ...) -> list[str]: ... - -# NOTE: get_exec_path(): returns list[bytes] when env not None def getlogin() -> str: ... def getpid() -> int: ... def getppid() -> int: ... From 1ebdc00bc1859607f3863f2ed404ca876270010b Mon Sep 17 00:00:00 2001 From: Akuli Date: Sun, 8 Aug 2021 21:32:46 +0300 Subject: [PATCH 6/8] lower-case list and dict in stdlib/xmlrpc/server.pyi except in type alias --- stdlib/xmlrpc/server.pyi | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/stdlib/xmlrpc/server.pyi b/stdlib/xmlrpc/server.pyi index 9d86fe2b6c75..395dec0a7193 100644 --- a/stdlib/xmlrpc/server.pyi +++ b/stdlib/xmlrpc/server.pyi @@ -34,11 +34,11 @@ class _DispatchArityN(Protocol): _DispatchProtocol = Union[_DispatchArity0, _DispatchArity1, _DispatchArity2, _DispatchArity3, _DispatchArity4, _DispatchArityN] def resolve_dotted_attribute(obj: Any, attr: str, allow_dotted_names: bool = ...) -> Any: ... # undocumented -def list_public_methods(obj: Any) -> List[str]: ... # undocumented +def list_public_methods(obj: Any) -> list[str]: ... # undocumented class SimpleXMLRPCDispatcher: # undocumented - funcs: Dict[str, _DispatchProtocol] + funcs: dict[str, _DispatchProtocol] instance: Any | None allow_none: bool encoding: str @@ -57,10 +57,10 @@ class SimpleXMLRPCDispatcher: # undocumented dispatch_method: Callable[[str | None, Tuple[_Marshallable, ...]], Fault | Tuple[_Marshallable, ...]] | None = ..., path: Any | None = ..., ) -> str: ... # undocumented - def system_listMethods(self) -> List[str]: ... # undocumented + def system_listMethods(self) -> list[str]: ... # undocumented def system_methodSignature(self, method_name: str) -> str: ... # undocumented def system_methodHelp(self, method_name: str) -> str: ... # undocumented - def system_multicall(self, call_list: List[Dict[str, _Marshallable]]) -> List[_Marshallable]: ... # undocumented + def system_multicall(self, call_list: list[dict[str, _Marshallable]]) -> list[_Marshallable]: ... # undocumented def _dispatch(self, method: str, params: Iterable[_Marshallable]) -> _Marshallable: ... # undocumented class SimpleXMLRPCRequestHandler(http.server.BaseHTTPRequestHandler): @@ -68,7 +68,7 @@ class SimpleXMLRPCRequestHandler(http.server.BaseHTTPRequestHandler): rpc_paths: Tuple[str, str] = ... encode_threshold: int = ... # undocumented aepattern: Pattern[str] # undocumented - def accept_encodings(self) -> Dict[str, float]: ... + def accept_encodings(self) -> dict[str, float]: ... def is_rpc_path_valid(self) -> bool: ... def do_POST(self) -> None: ... def decode_request_content(self, data: bytes) -> bytes | None: ... @@ -92,7 +92,7 @@ class SimpleXMLRPCServer(socketserver.TCPServer, SimpleXMLRPCDispatcher): class MultiPathXMLRPCServer(SimpleXMLRPCServer): # undocumented - dispatchers: Dict[str, SimpleXMLRPCDispatcher] + dispatchers: dict[str, SimpleXMLRPCDispatcher] allow_none: bool encoding: str def __init__( @@ -122,7 +122,7 @@ class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher): class ServerHTMLDoc(pydoc.HTMLDoc): # undocumented def docroutine(self, object: object, name: str, mod: str | None = ..., funcs: Mapping[str, str] = ..., classes: Mapping[str, str] = ..., methods: Mapping[str, str] = ..., cl: type | None = ...) -> str: ... # type: ignore - def docserver(self, server_name: str, package_documentation: str, methods: Dict[str, str]) -> str: ... + def docserver(self, server_name: str, package_documentation: str, methods: dict[str, str]) -> str: ... class XMLRPCDocGenerator: # undocumented From 8a864b74cf9f92b2efa12cbfe850456825e36cb1 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sun, 8 Aug 2021 21:33:16 +0300 Subject: [PATCH 7/8] collapse on one line --- stdlib/xmlrpc/server.pyi | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stdlib/xmlrpc/server.pyi b/stdlib/xmlrpc/server.pyi index 395dec0a7193..f67290ccf551 100644 --- a/stdlib/xmlrpc/server.pyi +++ b/stdlib/xmlrpc/server.pyi @@ -6,9 +6,8 @@ from datetime import datetime from typing import Any, Callable, Dict, Iterable, List, Mapping, Pattern, Protocol, Tuple, Type, Union from xmlrpc.client import Fault -_Marshallable = Union[ - None, bool, int, float, str, bytes, Tuple[Any, ...], List[Any], Dict[Any, Any], datetime -] # TODO: Recursive type on tuple, list, dict +# TODO: Recursive type on tuple, list, dict +_Marshallable = Union[None, bool, int, float, str, bytes, Tuple[Any, ...], List[Any], Dict[Any, Any], datetime] # The dispatch accepts anywhere from 0 to N arguments, no easy way to allow this in mypy class _DispatchArity0(Protocol): From 1804809f0d9ebfe795dfe379f8029f6e9a219c64 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sun, 8 Aug 2021 21:45:24 +0300 Subject: [PATCH 8/8] fix --- stdlib/os/__init__.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index c17d3b5135b8..e0841458510e 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -24,6 +24,7 @@ from typing import ( Generic, Iterable, Iterator, + List, Mapping, MutableMapping, NoReturn,