Skip to content

lowercase list and dict in the rest of stdlib #5892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions stdlib/multiprocessing/managers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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: ...
Expand All @@ -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: ...
Expand All @@ -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: ...
Expand All @@ -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): ...

Expand Down
31 changes: 14 additions & 17 deletions stdlib/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ from typing import (
BinaryIO,
Callable,
ContextManager,
Dict,
Generic,
Iterable,
Iterator,
Expand Down Expand Up @@ -213,7 +212,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: ...
Expand All @@ -225,9 +224,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
Expand Down Expand Up @@ -336,7 +335,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
Expand Down Expand Up @@ -378,9 +377,7 @@ 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]: ...

# NOTE: get_exec_path(): returns List[bytes] when env not None
def get_exec_path(env: Mapping[str, str] | None = ...) -> list[str]: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the comment wrong? Sounds like something we should handle with overloads.

Copy link
Collaborator Author

@Akuli Akuli Aug 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried get_exec_path(), get_exec_path(None), get_exec_path(os.environ) and get_exec_path(os.environb). They all returned a list of strings. I also don't think this is different on windows, because windows generally uses byte strings less than unixy operating systems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking! Maybe it was a Python 2 thing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I thought too, but the function doesn't exist in Python 2. I also tried git blame, but that leads to 337abed which copies stubs from a different repo and gives no more history.

def getlogin() -> str: ...
def getpid() -> int: ...
def getppid() -> int: ...
Expand All @@ -393,8 +390,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: ...
Expand Down Expand Up @@ -689,7 +686,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):
Expand All @@ -701,7 +698,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,
Expand All @@ -710,7 +707,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 = ...,
Expand All @@ -719,10 +716,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 = ...
Expand All @@ -742,7 +739,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],
Expand Down
22 changes: 12 additions & 10 deletions stdlib/pydoc.pyi
Original file line number Diff line number Diff line change
@@ -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]]
Expand All @@ -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: ...
Expand All @@ -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: ...
Expand Down Expand Up @@ -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: ...
Expand All @@ -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(
Expand Down Expand Up @@ -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: ...
Expand Down Expand Up @@ -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]
Expand All @@ -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: ...
Expand Down
12 changes: 7 additions & 5 deletions stdlib/tarfile.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 = ...
Expand Down
19 changes: 9 additions & 10 deletions stdlib/xmlrpc/server.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -34,11 +33,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
Expand All @@ -57,18 +56,18 @@ 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):

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: ...
Expand All @@ -92,7 +91,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__(
Expand Down Expand Up @@ -122,7 +121,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

Expand Down