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: ...

0 commit comments

Comments
 (0)