Skip to content

Commit b9909b1

Browse files
Add missing typings to unittest.mock (#7431)
1 parent bc72b25 commit b9909b1

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

pyrightconfig.stricter.json

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"stdlib/sqlite3/dbapi2.pyi",
1414
"stdlib/_tkinter.pyi",
1515
"stdlib/tkinter",
16-
"stdlib/unittest/mock.pyi",
1716
"stdlib/xml/dom/NodeFilter.pyi",
1817
"stdlib/xml/dom/expatbuilder.pyi",
1918
"stdlib/xml/dom/minidom.pyi",

stdlib/unittest/mock.pyi

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
from _typeshed import Self
3+
from contextlib import _GeneratorContextManager
34
from typing import Any, Awaitable, Callable, Generic, Iterable, Mapping, Sequence, TypeVar, overload
45
from typing_extensions import Literal
56

@@ -75,11 +76,15 @@ class _Sentinel:
7576
sentinel: Any
7677
DEFAULT: Any
7778

79+
_ArgsKwargs = tuple[tuple[Any, ...], Mapping[str, Any]]
80+
_NameArgsKwargs = tuple[str, tuple[Any, ...], Mapping[str, Any]]
81+
_CallValue = str | tuple[Any, ...] | Mapping[str, Any] | _ArgsKwargs | _NameArgsKwargs
82+
7883
class _Call(tuple[Any, ...]):
7984
def __new__(
8085
cls: type[Self],
81-
value: Any = ...,
82-
name: Any | None = ...,
86+
value: _CallValue = ...,
87+
name: str | None = ...,
8388
parent: Any | None = ...,
8489
two: bool = ...,
8590
from_kall: bool = ...,
@@ -88,7 +93,7 @@ class _Call(tuple[Any, ...]):
8893
parent: Any
8994
from_kall: Any
9095
def __init__(
91-
self, value: Any = ..., name: Any | None = ..., parent: Any | None = ..., two: bool = ..., from_kall: bool = ...
96+
self, value: _CallValue = ..., name: str | None = ..., parent: Any | None = ..., two: bool = ..., from_kall: bool = ...
9297
) -> None: ...
9398
def __eq__(self, other: object) -> bool: ...
9499
def __ne__(self, __other: object) -> bool: ...
@@ -97,9 +102,9 @@ class _Call(tuple[Any, ...]):
97102
def __getattribute__(self, attr: str) -> Any: ...
98103
if sys.version_info >= (3, 8):
99104
@property
100-
def args(self): ...
105+
def args(self) -> tuple[Any, ...]: ...
101106
@property
102-
def kwargs(self): ...
107+
def kwargs(self) -> Mapping[str, Any]: ...
103108

104109
def call_list(self) -> Any: ...
105110

@@ -244,7 +249,9 @@ class _patch(Generic[_T]):
244249
@overload
245250
def __call__(self, func: Callable[..., _R]) -> Callable[..., _R]: ...
246251
if sys.version_info >= (3, 8):
247-
def decoration_helper(self, patched, args, keywargs): ...
252+
def decoration_helper(
253+
self, patched: _patch[Any], args: Sequence[Any], keywargs: Any
254+
) -> _GeneratorContextManager[tuple[Sequence[Any], Any]]: ...
248255

249256
def decorate_class(self, klass: _TT) -> _TT: ...
250257
def decorate_callable(self, func: Callable[..., _R]) -> Callable[..., _R]: ...
@@ -428,14 +435,14 @@ if sys.version_info >= (3, 8):
428435
class AsyncMock(AsyncMockMixin, AsyncMagicMixin, Mock): ... # type: ignore # argument disparities between base classes
429436

430437
class MagicProxy:
431-
name: Any
438+
name: str
432439
parent: Any
433-
def __init__(self, name, parent) -> None: ...
440+
def __init__(self, name: str, parent: Any) -> None: ...
434441
if sys.version_info < (3, 8):
435442
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
436443

437-
def create_mock(self): ...
438-
def __get__(self, obj, _type: Any | None = ...): ...
444+
def create_mock(self) -> Any: ...
445+
def __get__(self, obj: Any, _type: Any | None = ...) -> Any: ...
439446

440447
class _ANY:
441448
def __eq__(self, other: object) -> Literal[True]: ...

0 commit comments

Comments
 (0)