8000 stdlib: Add many missing dunder overrides (#7231) · python/typeshed@fbc279e · GitHub
[go: up one dir, main page]

Skip to content

Commit fbc279e

Browse files
authored
stdlib: Add many missing dunder overrides (#7231)
1 parent 409beea commit fbc279e

28 files changed

+62
-6
lines changed

stdlib/argparse.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ class Namespace(_AttributeHolder):
324324
def __getattr__(self, name: str) -> Any: ...
325325
def __setattr__(self, __name: str, __value: Any) -> None: ...
326326
def __contains__(self, key: str) -> bool: ...
327+
def __eq__(self, other: object) -> bool: ...
327328

328329
class FileType:
329330
# undocumented

stdlib/asyncio/events.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class TimerHandle(Handle):
5959
def __le__(self, other: TimerHandle) -> bool: ...
6060
def __gt__(self, other: TimerHandle) -> bool: ...
6161
def __ge__(self, other: TimerHandle) -> bool: ...
62+
def __eq__(self, other: object) -> bool: ...
6263

6364
class AbstractServer:
6465
@abstractmethod

stdlib/collections/__init__.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class UserList(MutableSequence[_T]):
8282
def __le__(self, other: list[_T] | UserList[_T]) -> bool: ...
8383
def __gt__(self, other: list[_T] | UserList[_T]) -> bool: ...
8484
def __ge__(self, other: list[_T] | UserList[_T]) -> bool: ...
85+
def __eq__(self, other: object) -> bool: ...
8586
def __contains__(self, item: object) -> bool: ...
8687
def __len__(self) -> int: ...
8788
@overload
@@ -125,6 +126,7 @@ class UserString(Sequence[UserString]):
125126
def __le__(self, string: str | UserString) -> bool: ...
126127
def __gt__(self, string: str | UserString) -> bool: ...
127128
def __ge__(self, string: str | UserString) -> bool: ...
129+
def __eq__(self, string: object) -> bool: ...
128130
def __contains__(self, char: object) -> bool: ...
129131
def __len__(self) -> int: ...
130132
def __getitem__(self: Self, i: SupportsIndex | slice) -> Self: ...
@@ -267,6 +269,9 @@ class Counter(dict[_T, int], Generic[_T]):
267269
def update(self, __m: Iterable[_T] | Iterable[tuple[_T, int]], **kwargs: int) -> None: ...
268270
@overload
269271
def update(self, __m: None = ..., **kwargs: int) -> None: ...
272+
def __delitem__(self, elem: object) -> None: ...
273+
def __eq__(self, other: object) -> bool: ...
274+
def __ne__(self, other: object) -> bool: ...
270275
def __add__(self, other: Counter[_T]) -> Counter[_T]: ...
271276
def __sub__(self, other: Counter[_T]) -> Counter[_T]: ...
272277
def __and__(self, other: Counter[_T]) -> Counter[_T]: ...
@@ -362,6 +367,7 @@ class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
362367
def __getitem__(self, k: _KT) -> _VT: ...
363368
def __iter__(self) -> Iterator[_KT]: ...
364369
def __len__(self) -> int: ...
370+
def __contains__(self, key: object) -> bool: ...
365371
def __missing__(self, key: _KT) -> _VT: ... # undocumented
366372
def setdefault(self, key: _KT, default: _VT = ...) -> _VT: ...
367373
@overload

stdlib/configparser.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class RawConfigParser(_parser):
8080
def __setitem__(self, section: str, options: _section) -> None: ...
8181
def __delitem__(self, section: str) -> None: ...
8282
def __iter__(self) -> Iterator[str]: ...
83+
def __contains__(self, key: object) -> bool: ...
8384
def defaults(self) -> _section: ...
8485
def sections(self) -> list[str]: ...
8586
def add_section(self, section: str) -> None: ...

stdlib/contextlib.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class _GeneratorContextManager(AbstractContextManager[_T_co], ContextDecorator,
4646
func: Callable[..., Generator[_T_co, Any, Any]]
4747
args: tuple[Any, ...]
4848
kwds: dict[str, Any]
49+
def __exit__(
50+
self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
51+
) -> bool | None: ...
4952

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

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

6773
elif sys.version_info >= (3, 7):
6874
class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co], Generic[_T_co]):

stdlib/doctest.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Example:
4747
options: dict[int, bool] | None = ...,
4848
) -> None: ...
4949
def __hash__(self) -> int: ...
50+
def __eq__(self, other: object) -> bool: ...
5051

5152
class DocTest:
5253
examples: list[Example]
@@ -66,6 +67,7 @@ class DocTest:
6667
) -> None: ...
6768
def __hash__(self) -> int: ...
6869
def __lt__(self, other: DocTest) -> bool: ...
70+
def __eq__(self, other: object) -> bool: ...
6971

7072
class DocTestParser:
7173
def parse(self, string: str, name: str = ...) -> list[str | Example]: ...
@@ -172,6 +174,7 @@ class DocTestCase(unittest.TestCase):
172174
def debug(self) -> None: ...
173175
def id(self) -> str: ...
174176
def __hash__(self) -> int: ...
177+
def __eq__(self, other: object) -> bool: ...
175178
def shortDescription(self) -> str: ...
176179

177180
class SkipDocTestCase(DocTestCase):

stdlib/email/headerregistry.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,12 @@ class Address:
161161
def __init__(
162162
self, display_name: str = ..., username: str | None = ..., domain: str | None = ..., addr_spec: str | None = ...
163163
) -> None: ...
164+
def __eq__(self, other: object) -> bool: ...
164165

165166
class Group:
166167
@property
167168
def display_name(self) -> str | None: ...
168169
@property
169170
def addresses(self) -> tuple[Address, ...]: ...
170171
def __init__(self, display_name: str | None = ..., addresses: Iterable[Address] | None = ...) -> None: ...
172+
def __eq__(self, other: object) -> bool: ...

stdlib/enum.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ _EnumNames = Union[str, Iterable[str], Iterable[Iterable[Union[str, Any]]], Mapp
2525

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

2930
# Note: EnumMeta actually subclasses type directly, not ABCMeta.
3031
# This is a temporary workaround to allow multiple creation of enums with builtins
@@ -56,6 +57,8 @@ class EnumMeta(ABCMeta):
5657
def __members__(self: type[_T]) -> types.MappingProxyType[str, _T]: ...
5758
def __len__(self) -> int: ...
5859
def __bool__(self) -> Literal[True]: ...
60+
def __setattr__(self, name: str, value: Any) -> None: ...
61+
def __delattr__(self, name: str) -> None: ...
5962
if sys.version_info >= (3, 11):
6063
# Simple value lookup
6164
@overload # type: ignore[override]

stdlib/http/cookies.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class Morsel(dict[str, Any], Generic[_T]):
3838
def output(self, attrs: list[str] | None = ..., header: str = ...) -> str: ...
3939
def js_output(self, attrs: list[str] | None = ...) -> str: ...
4040
def OutputString(self, attrs: list[str] | None = ...) -> str: ...
41+
def __eq__(self, morsel: object) -> bool: ...
42+
def __setitem__(self, K: str, V: Any) -> None: ...
4143
if sys.version_info >= (3, 9):
4244
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
4345

stdlib/importlib/machinery.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ModuleSpec:
2424
cached: str | None
2525
parent: str | None
2626
has_location: bool
27+
def __eq__(self, other: object) -> bool: ...
2728

2829
class BuiltinImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader):
2930
# MetaPathFinder
@@ -144,3 +145,4 @@ class ExtensionFileLoader(importlib.abc.ExecutionLoader):
144145
def exec_module(self, module: types.ModuleType) -> None: ...
145146
def is_package(self, fullname: str) -> bool: ...
146147
def get_code(self, fullname: str) -> None: ...
148+
def __eq__(self, other: object) -> bool: ...

stdlib/inspect.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ class Signature:
189189
@classmethod
190190
def from_callable(cls: type[Self], obj: Callable[..., Any], *, follow_wrapped: bool = ...) -> Self: ...
191191

192+
def __eq__(self, other: object) -> bool: ...
193+
192194
if sys.version_info >= (3, 10):
193195
def get_annotations(
194196
obj: Callable[..., Any] | type[Any] | ModuleType,
@@ -235,6 +237,7 @@ class Parameter:
235237
default: Any = ...,
236238
annotation: Any = ...,
237239
) -> Self: ...
240+
def __eq__(self, other: object) -> bool: ...
238241

239242
class BoundArguments:
240243
arguments: OrderedDict[str, Any]
@@ -243,6 +246,7 @@ class BoundArguments:
243246
signature: Signature
244247
def __init__(self, signature: Signature, arguments: OrderedDict[str, Any]) -> None: ...
245248
def apply_defaults(self) -> None: ...
249+
def __eq__(self, other: object) -> bool: ...
246250

247251
#
248252
# Classes and functions

stdlib/multiprocessing/managers.pyi

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import queue
22
import sys
33
import threading
4-
from contextlib import AbstractContextManager
4+
from _typeshed import Self
5+
from types import TracebackType
56
from typing import Any, AnyStr, Callable, Generic, Iterable, Mapping, Sequence, TypeVar
67

78
from .connection import Connection
@@ -69,7 +70,7 @@ class Server:
6970
def serve_forever(self) -> None: ...
7071
def accept_connection(self, c: Connection, name: str) -> None: ...
7172

72-
class BaseManager(AbstractContextManager[BaseManager]):
73+
class BaseManager:
7374
def __init__(
7475
self, address: Any | None = ..., authkey: bytes | None = ..., serializer: str = ..., ctx: BaseContext | None = ...
7576
) -> None: ...
@@ -90,12 +91,14 @@ class BaseManager(AbstractContextManager[BaseManager]):
9091
method_to_typeid: Mapping[str, str] | None = ...,
9192
create_method: bool = ...,
9293
) -> None: ...
94+
def __enter__(self: Self) -> Self: ...
95+
def __exit__(self, exc_type: type[BaseException], exc_val: BaseException, exc_tb: TracebackType) -> None: ...
9396

9497
# Conflicts with method names
9598
_dict = dict
9699
_list = list
97100

98-
class SyncManager(BaseManager, AbstractContextManager[SyncManager]):
101+
class SyncManager(BaseManager):
99102
def BoundedSemaphore(self, value: Any = ...) -> threading.BoundedSemaphore: ...
100103
def Condition(self, lock: Any = ...) -> threading.Condition: ...
101104
def Event(self) -> threading.Event: ...

stdlib/multiprocessing/pool.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from _typeshed import Self
3-
from contextlib import AbstractContextManager
3+
from types import TracebackType
44
from typing import Any, Callable, Generic, Iterable, Iterator, Mapping, TypeVar
55
from typing_extensions import Literal
66

@@ -67,7 +67,7 @@ class IMapIterator(Iterator[_T]):
6767

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

70-
class Pool(AbstractContextManager[Pool]):
70+
class Pool:
7171
def __init__(
7272
self,
7373
processes: int | None = ...,
@@ -111,8 +111,9 @@ class Pool(AbstractContextManager[Pool]):
111111
def terminate(self) -> None: ...
112112
def join(self) -> None: ...
113113
def __enter__(self: Self) -> Self: ...
114+
def __exit__(self, exc_type: type[BaseException], exc_val: BaseException, exc_tb: TracebackType) -> None: ...
114115

115-
class ThreadPool(Pool, AbstractContextManager[ThreadPool]):
116+
class ThreadPool(Pool):
116117
def __init__(
117118
self, processes: int | None = ..., initializer: Callable[..., Any] | None = ..., initargs: Iterable[Any] = ...
118119
) -> None: ...

stdlib/optparse.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class Values:
161161
def read_module(self, modname: str, mode: str = ...) -> None: ...
162162
def __getattr__(self, name: str) -> Any: ...
163163
def __setattr__(self, __name: str, __value: Any) -> None: ...
164+
def __eq__(self, other: object) -> bool: ...
164165

165166
class OptionParser(OptionContainer):
166167
allow_interspersed_args: bool

stdlib/pathlib.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class PurePath(PathLike[str]):
2828
stem: str
2929
def __new__(cls: type[Self], *args: StrPath) -> Self: ...
3030
def __hash__(self) -> int: ...
31+
def __eq__(self, other: object) -> bool: ...
3132
def __lt__(self, other: PurePath) -> bool: ...
3233
def __le__(self, other: PurePath) -> bool: ...
3334
def __gt__(self, other: PurePath) -> bool: ...

stdlib/plistlib.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ if sys.version_info >= (3, 8):
7171
def __index__(self) -> int: ...
7272
def __reduce__(self: Self) -> tuple[type[Self], tuple[int]]: ...
7373
def __hash__(self) -> int: ...
74+
def __eq__(self, other: object) -> bool: ...
7475

7576
class InvalidFileException(ValueError):
7677
def __init__(self, message: str = ...) -> None: ...

stdlib/shelve.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Shelf(MutableMapping[str, _VT]):
2020
def __getitem__(self, key: str) -> _VT: ...
2121
def __setitem__(self, key: str, value: _VT) -> None: ...
2222
def __delitem__(self, key: str) -> None: ...
23+
def __contains__(self, key: str) -> bool: ... # type: ignore[override]
2324
def __enter__(self: Self) -> Self: ...
2425
def __exit__(
2526
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None

stdlib/statistics.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ if sys.version_info >= (3, 8):
6767
if sys.version_info >= (3, 9):
6868
def zscore(self, x: float) -> float: ...
6969

70+
def __eq__(self, x2: object) -> bool: ...
7071
def __add__(self, x2: float | NormalDist) -> NormalDist: ...
7172
def __sub__(self, x2: float | NormalDist) -> NormalDist: ...
7273
def __mul__(self, x2: float) -> NormalDist: ...

stdlib/tkinter/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class Variable:
142142
def trace_vdelete(self, mode, cbname) -> None: ... # deprecated
143143
def trace_vinfo(self): ... # deprecated
144144
trace = trace_variable # deprecated
145+
def __eq__(self, other: object) -> bool: ...
145146

146147
class StringVar(Variable):
147148
def __init__(self, master: Misc | None = ..., value: str | None = ..., name: str | None = ...) -> None: ...

stdlib/tkinter/font.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class Font:
101101
@overload
102102
def metrics(self, *, displayof: tkinter.Misc | None = ...) -> _MetricsDict: ...
103103
def measure(self, text: str, displayof: tkinter.Misc | None = ...) -> int: ...
104+
def __eq__(self, other: object) -> bool: ...
104105

105106
def families(root: tkinter.Misc | None = ..., displayof: tkinter.Misc | None = ...) -> tuple[str, ...]: ...
106107
def names(root: tkinter.Misc | None = ...) -> tuple[str, ...]: ...

stdlib/traceback.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class TracebackException:
124124
cls: type[Self], exc: BaseException, *, limit: int | None = ..., lookup_lines: bool = ..., capture_locals: bool = ...
125125
) -> Self: ...
126126

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

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

stdlib/tracemalloc.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Statistic:
2626
size: int
2727
traceback: Traceback
2828
def __init__(self, traceback: Traceback, size: int, count: int) -> None: ...
29+
def __eq__(self, other: object) -> bool: ...
2930

3031
class StatisticDiff:
3132
count: int
@@ -34,6 +35,7 @@ class StatisticDiff:
3435
size_diff: int
3536
traceback: Traceback
3637
def __init__(self, traceback: Traceback, size: int, size_diff: int, count: int, count_diff: int) -> None: ...
38+
def __eq__(self, other: object) -> bool: ...
3739

3840
_FrameTupleT = tuple[str, int]
3941

@@ -61,6 +63,7 @@ class Trace:
6163
size: int
6264
traceback: Traceback
6365
def __init__(self, trace: _TraceTupleT) -> None: ...
66+
def __eq__(self, other: object) -> bool: ...
6467

6568
class Traceback(Sequence[Frame]):
6669
if sys.version_info >= (3, 9):
@@ -78,6 +81,7 @@ class Traceback(Sequence[Frame]):
7881
@overload
7982
def __getitem__(self, s: slice) -> Sequence[Frame]: ...
8083
def __len__(self) -> int: ...
84+
def __eq__(self, other: object) -> bool: ...
8185
def __lt__(self, other: Traceback) -> bool: ...
8286
if sys.version_info >= (3, 11):
8387
def __gt__(self, other: Traceback) -> bool: ...

stdlib/unittest/case.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class TestCase:
8282
# undocumented
8383
_testMethodDoc: str
8484
def __init__(self, methodName: str = ...) -> None: ...
85+
def __eq__(self, other: object) -> bool: ...
8586
def setUp(self) -> None: ...
8687
def tearDown(self) -> None: ...
8788
@classmethod

stdlib/unittest/mock.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class NonCallableMock(Base, Any):
128128
**kwargs: Any,
129129
) -> None: ...
130130
def __getattr__(self, name: str) -> Any: ...
131+
def __delattr__(self, name: str) -> None: ...
132+
def __setattr__(self, name: str, value: Any) -> None: ...
131133
if sys.version_info >= (3, 8):
132134
def _calls_repr(self, prefix: str = ...) -> str: ...
133135
def assert_called_with(self, *args: Any, **kwargs: Any) -> None: ...

stdlib/unittest/suite.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class BaseTestSuite(Iterable[_TestType]):
1515
def debug(self) -> None: ...
1616
def countTestCases(self) -> int: ...
1717
def __iter__(self) -> Iterator[_TestType]: ...
18+
def __eq__(self, other: object) -> bool: ...
1819

1920
class TestSuite(BaseTestSuite):
2021
def run(self, result: unittest.result.TestResult, debug: bool = ...) -> unittest.result.TestResult: ...

stdlib/weakref.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ ProxyTypes: tuple[type[Any], ...]
2727
class WeakMethod(ref[_CallableT], Generic[_CallableT]):
2828
def __new__(cls: type[Self], meth: _CallableT, callback: Callable[[_CallableT], object] | None = ...) -> Self: ...
2929
def __call__(self) -> _CallableT | None: ...
30+
def __eq__(self, other: object) -> bool: ...
31+
def __ne__(self, other: object) -> bool: ...
3032

3133
class WeakValueDictionary(MutableMapping[_KT, _VT]):
3234
@overload

stdlib/xml/etree/ElementTree.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class QName:
115115
def __le__(self, other: QName | str) -> bool: ...
116116
def __gt__(self, other: QName | str) -> bool: ...
117117
def __ge__(self, other: QName | str) -> bool: ...
118+
def __eq__(self, other: object) -> bool: ...
118119

119120
class ElementTree:
120121
def __init__(self, element: Element | None = ..., file: _File | None = ...) -> None: ...

stdlib/xmlrpc/client.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class Binary:
8383
def __init__(self, data: bytes | None = ...) -> None: ...
8484
def decode(self, data: bytes) -> None: ...
8585
def encode(self, out: SupportsWrite[str]) -> None: ...
86+
def __eq__(self, other: object) -> bool: ...
8687

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

0 commit comments

Comments
 (0)
0