Skip to content

stdlib: Add many missing dunder overrides #7231

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 2 commits into from
Feb 16, 2022
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
1 change: 1 addition & 0 deletions stdlib/argparse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ class Namespace(_AttributeHolder):
def __getattr__(self, name: str) -> Any: ...
def __setattr__(self, __name: str, __value: Any) -> None: ...
def __contains__(self, key: str) -> bool: ...
def __eq__(self, other: object) -> bool: ...

class FileType:
# undocumented
Expand Down
1 change: 1 addition & 0 deletions stdlib/asyncio/events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class TimerHandle(Handle):
def __le__(self, other: TimerHandle) -> bool: ...
def __gt__(self, other: TimerHandle) -> bool: ...
def __ge__(self, other: TimerHandle) -> bool: ...
def __eq__(self, other: object) -> bool: ...

class AbstractServer:
@abstractmethod
Expand Down
6 changes: 6 additions & 0 deletions stdlib/collections/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class UserList(MutableSequence[_T]):
def __le__(self, other: list[_T] | UserList[_T]) -> bool: ...
def __gt__(self, other: list[_T] | UserList[_T]) -> bool: ...
def __ge__(self, other: list[_T] | UserList[_T]) -> bool: ...
def __eq__(self, other: object) -> bool: ...
def __contains__(self, item: object) -> bool: ...
def __len__(self) -> int: ...
@overload
Expand Down Expand Up @@ -125,6 +126,7 @@ class UserString(Sequence[UserString]):
def __le__(self, string: str | UserString) -> bool: ...
def __gt__(self, string: str | UserString) -> bool: ...
def __ge__(self, string: str | UserString) -> bool: ...
def __eq__(self, string: object) -> bool: ...
def __contains__(self, char: object) -> bool: ...
def __len__(self) -> int: ...
def __getitem__(self: Self, i: SupportsIndex | slice) -> Self: ...
Expand Down Expand Up @@ -267,6 +269,9 @@ class Counter(dict[_T, int], Generic[_T]):
def update(self, __m: Iterable[_T] | Iterable[tuple[_T, int]], **kwargs: int) -> None: ...
@overload
def update(self, __m: None = ..., **kwargs: int) -> None: ...
def __delitem__(self, elem: object) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
def __add__(self, other: Counter[_T]) -> Counter[_T]: ...
def __sub__(self, other: Counter[_T]) -> Counter[_T]: ...
def __and__(self, other: Counter[_T]) -> Counter[_T]: ...
Expand Down Expand Up @@ -362,6 +367,7 @@ class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
def __getitem__(self, k: _KT) -> _VT: ...
def __iter__(self) -> Iterator[_KT]: ...
def __len__(self) -> int: ...
def __contains__(self, key: object) -> bool: ...
def __missing__(self, key: _KT) -> _VT: ... # undocumented
def setdefault(self, key: _KT, default: _VT = ...) -> _VT: ...
@overload
Expand Down
1 change: 1 addition & 0 deletions stdlib/configparser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class RawConfigParser(_parser):
def __setitem__(self, section: str, options: _section) -> None: ...
def __delitem__(self, section: str) -> None: ...
def __iter__(self) -> Iterator[str]: ...
def __contains__(self, key: object) -> bool: ...
def defaults(self) -> _section: ...
def sections(self) -> list[str]: ...
def add_section(self, section: str) -> None: ...
Expand Down
6 changes: 6 additions & 0 deletions stdlib/contextlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class _GeneratorContextManager(AbstractContextManager[_T_co], ContextDecorator,
func: Callable[..., Generator[_T_co, Any, Any]]
args: tuple[Any, ...]
kwds: dict[str, Any]
def __exit__(
self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
) -> bool | None: ...

def contextmanager(func: Callable[_P, Iterator[_T_co]]) -> Callable[_P, _GeneratorContextManager[_T_co]]: ...

Expand All @@ -63,6 +66,9 @@ if sys.version_info >= (3, 10):
func: Callable[..., AsyncGenerator[_T_co, Any]]
args: tuple[Any, ...]
kwds: dict[str, Any]
async def __aexit__(
self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
) -> bool | None: ...

elif sys.version_info >= (3, 7):
class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co], Generic[_T_co]):
Expand Down
3 changes: 3 additions & 0 deletions stdlib/doctest.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Example:
options: dict[int, bool] | None = ...,
) -> None: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...

class DocTest:
examples: list[Example]
Expand All @@ -66,6 +67,7 @@ class DocTest:
) -> None: ...
def __hash__(self) -> int: ...
def __lt__(self, other: DocTest) -> bool: ...
def __eq__(self, other: object) -> bool: ...

class DocTestParser:
def parse(self, string: str, name: str = ...) -> list[str | Example]: ...
Expand Down Expand Up @@ -172,6 +174,7 @@ class DocTestCase(unittest.TestCase):
def debug(self) -> None: ...
def id(self) -> str: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
def shortDescription(self) -> str: ...

class SkipDocTestCase(DocTestCase):
Expand Down
2 changes: 2 additions & 0 deletions stdlib/email/headerregistry.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ class Address:
def __init__(
self, display_name: str = ..., username: str | None = ..., domain: str | None = ..., addr_spec: str | None = ...
) -> None: ...
def __eq__(self, other: object) -> bool: ...

class Group:
@property
def display_name(self) -> str | None: ...
@property
def addresses(self) -> tuple[Address, ...]: ...
def __init__(self, display_name: str | None = ..., addresses: Iterable[Address] | None = ...) -> None: ...
def __eq__(self, other: object) -> bool: ...
3 changes: 3 additions & 0 deletions stdlib/enum.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ _EnumNames = Union[str, Iterable[str], Iterable[Iterable[Union[str, Any]]], Mapp

class _EnumDict(dict[str, Any]):
def __init__(self) -> None: ...
def __setitem__(self, key: str, value: Any) -> None: ...

# Note: EnumMeta actually subclasses type directly, not ABCMeta.
# This is a temporary workaround to allow multiple creation of enums with builtins
Expand Down Expand Up @@ -56,6 +57,8 @@ class EnumMeta(ABCMeta):
def __members__(self: type[_T]) -> types.MappingProxyType[str, _T]: ...
def __len__(self) -> int: ...
def __bool__(self) -> Literal[True]: ...
def __setattr__(self, name: str, value: Any) -> None: ...
def __delattr__(self, name: str) -> None: ...
if sys.version_info >= (3, 11):
# Simple value lookup
@overload # type: ignore[override]
Expand Down
2 changes: 2 additions & 0 deletions stdlib/http/cookies.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Morsel(dict[str, Any], Generic[_T]):
def output(self, attrs: list[str] | None = ..., header: str = ...) -> str: ...
def js_output(self, attrs: list[str] | None = ...) -> str: ...
def OutputString(self, attrs: list[str] | None = ...) -> str: ...
def __eq__(self, morsel: object) -> bool: ...
def __setitem__(self, K: str, V: Any) -> None: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...

Expand Down
2 changes: 2 additions & 0 deletions stdlib/importlib/machinery.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ModuleSpec:
cached: str | None
parent: str | None
has_location: bool
def __eq__(self, other: object) -> bool: ...

class BuiltinImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader):
# MetaPathFinder
Expand Down Expand Up @@ -144,3 +145,4 @@ class ExtensionFileLoader(importlib.abc.ExecutionLoader):
def exec_module(self, module: types.ModuleType) -> None: ...
def is_package(self, fullname: str) -> bool: ...
def get_code(self, fullname: str) -> None: ...
def __eq__(self, other: object) -> bool: ...
4 changes: 4 additions & 0 deletions stdlib/inspect.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ class Signature:
@classmethod
def from_callable(cls: type[Self], obj: Callable[..., Any], *, follow_wrapped: bool = ...) -> Self: ...

def __eq__(self, other: object) -> bool: ...

if sys.version_info >= (3, 10):
def get_annotations(
obj: Callable[..., Any] | type[Any] | ModuleType,
Expand Down Expand Up @@ -235,6 +237,7 @@ class Parameter:
default: Any = ...,
annotation: Any = ...,
) -> Self: ...
def __eq__(self, other: object) -> bool: ...

class BoundArguments:
arguments: OrderedDict[str, Any]
Expand All @@ -243,6 +246,7 @@ class BoundArguments:
signature: Signature
def __init__(self, signature: Signature, arguments: OrderedDict[str, Any]) -> None: ...
def apply_defaults(self) -> None: ...
def __eq__(self, other: object) -> bool: ...

#
# Classes and functions
Expand Down
9 changes: 6 additions & 3 deletions stdlib/multiprocessing/managers.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import queue
import sys
import threading
from contextlib import AbstractContextManager
from _typeshed import Self
from types import TracebackType
from typing import Any, AnyStr, Callable, Generic, Iterable, Mapping, Sequence, TypeVar

from .connection import Connection
Expand Down Expand Up @@ -69,7 +70,7 @@ class Server:
def serve_forever(self) -> None: ...
def accept_connection(self, c: Connection, name: str) -> None: ...

class BaseManager(AbstractContextManager[BaseManager]):
class BaseManager:
def __init__(
self, address: Any | None = ..., authkey: bytes | None = ..., serializer: str = ..., ctx: BaseContext | None = ...
) -> None: ...
Expand All @@ -90,12 +91,14 @@ class BaseManager(AbstractContextManager[BaseManager]):
method_to_typeid: Mapping[str, str] | None = ...,
create_method: bool = ...,
) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, exc_type: type[BaseException], exc_val: BaseException, exc_tb: TracebackType) -> None: ...

# Conflicts with method names
_dict = dict
_list = list

class SyncManager(BaseManager, AbstractContextManager[SyncManager]):
class SyncManager(BaseManager):
def BoundedSemaphore(self, value: Any = ...) -> threading.BoundedSemaphore: ...
def Condition(self, lock: Any = ...) -> threading.Condition: ...
def Event(self) -> threading.Event: ...
Expand Down
7 changes: 4 additions & 3 deletions stdlib/multiprocessing/pool.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from _typeshed import Self
from contextlib import AbstractContextManager
from types import TracebackType
from typing import Any, Callable, Generic, Iterable, Iterator, Mapping, TypeVar
from typing_extensions import Literal

Expand Down Expand Up @@ -67,7 +67,7 @@ class IMapIterator(Iterator[_T]):

class IMapUnorderedIterator(IMapIterator[_T]): ...

class Pool(AbstractContextManager[Pool]):
class Pool:
def __init__(
self,
processes: int | None = ...,
Expand Down Expand Up @@ -111,8 +111,9 @@ class Pool(AbstractContextManager[Pool]):
def terminate(self) -> None: ...
def join(self) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, exc_type: type[BaseException], exc_val: BaseException, exc_tb: TracebackType) -> None: ...

class ThreadPool(Pool, AbstractContextManager[ThreadPool]):
class ThreadPool(Pool):
def __init__(
self, processes: int | None = ..., initializer: Callable[..., Any] | None = ..., initargs: Iterable[Any] = ...
) -> None: ...
Expand Down
1 change: 1 addition & 0 deletions stdlib/optparse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class Values:
def read_module(self, modname: str, mode: str = ...) -> None: ...
def __getattr__(self, name: str) -> Any: ...
def __setattr__(self, __name: str, __value: Any) -> None: ...
def __eq__(self, other: object) -> bool: ...

class OptionParser(OptionContainer):
allow_interspersed_args: bool
Expand Down
1 change: 1 addition & 0 deletions stdlib/pathlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PurePath(PathLike[str]):
stem: str
def __new__(cls: type[Self], *args: StrPath) -> Self: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
def __lt__(self, other: PurePath) -> bool: ...
def __le__(self, other: PurePath) -> bool: ...
def __gt__(self, other: PurePath) -> bool: ...
Expand Down
1 change: 1 addition & 0 deletions stdlib/plistlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ if sys.version_info >= (3, 8):
def __index__(self) -> int: ...
def __reduce__(self: Self) -> tuple[type[Self], tuple[int]]: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...

class InvalidFileException(ValueError):
def __init__(self, message: str = ...) -> None: ...
1 change: 1 addition & 0 deletions stdlib/shelve.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Shelf(MutableMapping[str, _VT]):
def __getitem__(self, key: str) -> _VT: ...
def __setitem__(self, key: str, value: _VT) -> None: ...
def __delitem__(self, key: str) -> None: ...
def __contains__(self, key: str) -> bool: ... # type: ignore[override]
def __enter__(self: Self) -> Self: ...
def __exit__(
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
Expand Down
1 change: 1 addition & 0 deletions stdlib/statistics.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ if sys.version_info >= (3, 8):
if sys.version_info >= (3, 9):
def zscore(self, x: float) -> float: ...

def __eq__(self, x2: object) -> bool: ...
def __add__(self, x2: float | NormalDist) -> NormalDist: ...
def __sub__(self, x2: float | NormalDist) -> NormalDist: ...
def __mul__(self, x2: float) -> NormalDist: ...
Expand Down
1 change: 1 addition & 0 deletions stdlib/tkinter/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class Variable:
def trace_vdelete(self, mode, cbname) -> None: ... # deprecated
def trace_vinfo(self): ... # deprecated
trace = trace_variable # deprecated
def __eq__(self, other: object) -> bool: ...

class StringVar(Variable):
def __init__(self, master: Misc | None = ..., value: str | None = ..., name: str | None = ...) -> None: ...
Expand Down
1 change: 1 addition & 0 deletions stdlib/tkinter/font.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Font:
@overload
def metrics(self, *, displayof: tkinter.Misc | None = ...) -> _MetricsDict: ...
def measure(self, text: str, displayof: tkinter.Misc | None = ...) -> int: ...
def __eq__(self, other: object) -> bool: ...

def families(root: tkinter.Misc | None = ..., displayof: tkinter.Misc | None = ...) -> tuple[str, ...]: ...
def names(root: tkinter.Misc | None = ...) -> tuple[str, ...]: ...
Expand Down
2 changes: 2 additions & 0 deletions stdlib/traceback.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class TracebackException:
cls: type[Self], exc: BaseException, *, limit: int | None = ..., lookup_lines: bool = ..., capture_locals: bool = ...
) -> Self: ...

def __eq__(self, other: object) -> bool: ...
def format(self, *, chain: bool = ...) -> Generator[str, None, None]: ...
def format_exception_only(self) -> Generator[str, None, None]: ...

Expand Down Expand Up @@ -173,6 +174,7 @@ class FrameSummary(Iterable[Any]):
@overload
def __getitem__(self, i: int) -> Any: ...
def __iter__(self) -> Iterator[Any]: ...
def __eq__(self, other: object) -> bool: ...
if sys.version_info >= (3, 8):
def __len__(self) -> Literal[4]: ...

Expand Down
4 changes: 4 additions & 0 deletions stdlib/tracemalloc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Statistic:
size: int
traceback: Traceback
def __init__(self, traceback: Traceback, size: int, count: int) -> None: ...
def __eq__(self, other: object) -> bool: ...

class StatisticDiff:
count: int
Expand All @@ -34,6 +35,7 @@ class StatisticDiff:
size_diff: int
traceback: Traceback
def __init__(self, traceback: Traceback, size: int, size_diff: int, count: int, count_diff: int) -> None: ...
def __eq__(self, other: object) -> bool: ...

_FrameTupleT = tuple[str, int]

Expand Down Expand Up @@ -61,6 +63,7 @@ class Trace:
size: int
traceback: Traceback
def __init__(self, trace: _TraceTupleT) -> None: ...
def __eq__(self, other: object) -> bool: ...

class Traceback(Sequence[Frame]):
if sys.version_info >= (3, 9):
Expand All @@ -78,6 +81,7 @@ class Traceback(Sequence[Frame]):
@overload
def __getitem__(self, s: slice) -> Sequence[Frame]: ...
def __len__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
def __lt__(self, other: Traceback) -> bool: ...
if sys.version_info >= (3, 11):
def __gt__(self, other: Traceback) -> bool: ...
Expand Down
1 change: 1 addition & 0 deletions stdlib/unittest/case.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class TestCase:
# undocumented
_testMethodDoc: str
def __init__(self, methodName: str = ...) -> None: ...
def __eq__(self, other: object) -> bool: ...
def setUp(self) -> None: ...
def tearDown(self) -> None: ...
@classmethod
Expand Down
2 changes: 2 additions & 0 deletions stdlib/unittest/mock.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class NonCallableMock(Base, Any):
**kwargs: Any,
) -> None: ...
def __getattr__(self, name: str) -> Any: ...
def __delattr__(self, name: str) -> None: ...
def __setattr__(self, name: str, value: Any) -> None: ...
if sys.version_info >= (3, 8):
def _calls_repr(self, prefix: str = ...) -> str: ...
def assert_called_with(self, *args: Any, **kwargs: Any) -> None: ...
Expand Down
1 change: 1 addition & 0 deletions stdlib/unittest/suite.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BaseTestSuite(Iterable[_TestType]):
def debug(self) -> None: ...
def countTestCases(self) -> int: ...
def __iter__(self) -> Iterator[_TestType]: ...
def __eq__(self, other: object) -> bool: ...

class TestSuite(BaseTestSuite):
def run(self, result: unittest.result.TestResult, debug: bool = ...) -> unittest.result.TestResult: ...
2 changes: 2 additions & 0 deletions stdlib/weakref.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ ProxyTypes: tuple[type[Any], ...]
class WeakMethod(ref[_CallableT], Generic[_CallableT]):
def __new__(cls: type[Self], meth: _CallableT, callback: Callable[[_CallableT], object] | None = ...) -> Self: ...
def __call__(self) -> _CallableT | None: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...

class WeakValueDictionary(MutableMapping[_KT, _VT]):
@overload
Expand Down
1 change: 1 addition & 0 deletions stdlib/xml/etree/ElementTree.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class QName:
def __le__(self, other: QName | str) -> bool: ...
def __gt__(self, other: QName | str) -> bool: ...
def __ge__(self, other: QName | str) -> bool: ...
def __eq__(self, other: object) -> bool: ...

class ElementTree:
def __init__(self, element: Element | None = ..., file: _File | None = ...) -> None: ...
Expand Down
1 change: 1 addition & 0 deletions stdlib/xmlrpc/client.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Binary:
def __init__(self, data: bytes | None = ...) -> None: ...
def decode(self, data: bytes) -> None: ...
def encode(self, out: SupportsWrite[str]) -> None: ...
def __eq__(self, other: object) -> bool: ...

def _binary(data: bytes) -> Binary: ... # undocumented

Expand Down