diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index b19bffc4cc47..d4eb2899be82 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -13,7 +13,6 @@ "stdlib/sqlite3/dbapi2.pyi", "stdlib/_tkinter.pyi", "stdlib/tkinter", - "stdlib/unittest/mock.pyi", "stdlib/xml/dom/NodeFilter.pyi", "stdlib/xml/dom/expatbuilder.pyi", "stdlib/xml/dom/minidom.pyi", diff --git a/stdlib/unittest/mock.pyi b/stdlib/unittest/mock.pyi index 7b14b0f78250..4f520528cd2e 100644 --- a/stdlib/unittest/mock.pyi +++ b/stdlib/unittest/mock.pyi @@ -1,5 +1,6 @@ import sys from _typeshed import Self +from contextlib import _GeneratorContextManager from typing import Any, Awaitable, Callable, Generic, Iterable, Mapping, Sequence, TypeVar, overload from typing_extensions import Literal @@ -75,11 +76,15 @@ class _Sentinel: sentinel: Any DEFAULT: Any +_ArgsKwargs = tuple[tuple[Any, ...], Mapping[str, Any]] +_NameArgsKwargs = tuple[str, tuple[Any, ...], Mapping[str, Any]] +_CallValue = str | tuple[Any, ...] | Mapping[str, Any] | _ArgsKwargs | _NameArgsKwargs + class _Call(tuple[Any, ...]): def __new__( cls: type[Self], - value: Any = ..., - name: Any | None = ..., + value: _CallValue = ..., + name: str | None = ..., parent: Any | None = ..., two: bool = ..., from_kall: bool = ..., @@ -88,7 +93,7 @@ class _Call(tuple[Any, ...]): parent: Any from_kall: Any def __init__( - self, value: Any = ..., name: Any | None = ..., parent: Any | None = ..., two: bool = ..., from_kall: bool = ... + self, value: _CallValue = ..., name: str | None = ..., parent: Any | None = ..., two: bool = ..., from_kall: bool = ... ) -> None: ... def __eq__(self, other: object) -> bool: ... def __ne__(self, __other: object) -> bool: ... @@ -97,9 +102,9 @@ class _Call(tuple[Any, ...]): def __getattribute__(self, attr: str) -> Any: ... if sys.version_info >= (3, 8): @property - def args(self): ... + def args(self) -> tuple[Any, ...]: ... @property - def kwargs(self): ... + def kwargs(self) -> Mapping[str, Any]: ... def call_list(self) -> Any: ... @@ -244,7 +249,9 @@ class _patch(Generic[_T]): @overload def __call__(self, func: Callable[..., _R]) -> Callable[..., _R]: ... if sys.version_info >= (3, 8): - def decoration_helper(self, patched, args, keywargs): ... + def decoration_helper( + self, patched: _patch[Any], args: Sequence[Any], keywargs: Any + ) -> _GeneratorContextManager[tuple[Sequence[Any], Any]]: ... def decorate_class(self, klass: _TT) -> _TT: ... def decorate_callable(self, func: Callable[..., _R]) -> Callable[..., _R]: ... @@ -428,14 +435,14 @@ if sys.version_info >= (3, 8): class AsyncMock(AsyncMockMixin, AsyncMagicMixin, Mock): ... # type: ignore # argument disparities between base classes class MagicProxy: - name: Any + name: str parent: Any - def __init__(self, name, parent) -> None: ... + def __init__(self, name: str, parent: Any) -> None: ... if sys.version_info < (3, 8): def __call__(self, *args: Any, **kwargs: Any) -> Any: ... - def create_mock(self): ... - def __get__(self, obj, _type: Any | None = ...): ... + def create_mock(self) -> Any: ... + def __get__(self, obj: Any, _type: Any | None = ...) -> Any: ... class _ANY: def __eq__(self, other: object) -> Literal[True]: ...