From 032f9195f9e3788a6e5c7ecb086f173a3ac92a95 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Wed, 19 Jul 2023 15:25:20 +0300 Subject: [PATCH] Add a more precise signature for `AsyncMock.reset_mock()` (#10481) --- stdlib/unittest/mock.pyi | 6 +++++- stubs/mock/mock/mock.pyi | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/stdlib/unittest/mock.pyi b/stdlib/unittest/mock.pyi index db1cc7d9b..66120197b 100644 --- a/stdlib/unittest/mock.pyi +++ b/stdlib/unittest/mock.pyi @@ -389,7 +389,11 @@ if sys.version_info >= (3, 8): class AsyncMagicMixin(MagicMixin): def __init__(self, *args: Any, **kw: Any) -> None: ... - class AsyncMock(AsyncMockMixin, AsyncMagicMixin, Mock): ... + class AsyncMock(AsyncMockMixin, AsyncMagicMixin, Mock): + # Improving the `reset_mock` signature. + # It is defined on `AsyncMockMixin` with `*args, **kwargs`, which is not ideal. + # But, `NonCallableMock` super-class has the better version. + def reset_mock(self, visited: Any = None, *, return_value: bool = False, side_effect: bool = False) -> None: ... class MagicProxy: name: str diff --git a/stubs/mock/mock/mock.pyi b/stubs/mock/mock/mock.pyi index fc09c7445..0479bde4c 100644 --- a/stubs/mock/mock/mock.pyi +++ b/stubs/mock/mock/mock.pyi @@ -329,7 +329,12 @@ class AsyncMockMixin(Base): __annotations__: dict[str, Any] | None # type: ignore[assignment] class AsyncMagicMixin(MagicMixin): ... -class AsyncMock(AsyncMockMixin, AsyncMagicMixin, Mock): ... + +class AsyncMock(AsyncMockMixin, AsyncMagicMixin, Mock): + # Improving the `reset_mock` signature. + # It is defined on `AsyncMockMixin` with `*args, **kwargs`, which is not ideal. + # But, `NonCallableMock` super-class has the better version. + def reset_mock(self, visited: Any = None, *, return_value: bool = False, side_effect: bool = False) -> None: ... class MagicProxy(Base): name: str