From b839d628b4c3c318081a14ba3186f404c0fc6741 Mon Sep 17 00:00:00 2001 From: Max R Date: Thu, 27 Aug 2026 07:35:31 -0400 Subject: [PATCH 1/2] Add overloads to `unittest.mock._patch_dict.__call__` --- stdlib/unittest/mock.pyi | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/stdlib/unittest/mock.pyi b/stdlib/unittest/mock.pyi index 1b6ab756d253..f467d6b66070 100644 --- a/stdlib/unittest/mock.pyi +++ b/stdlib/unittest/mock.pyi @@ -301,7 +301,14 @@ class _patch_dict: values: Any clear: Any def __init__(self, in_dict: Any, values: Any = (), clear: Any = False, **kwargs: Any) -> None: ... - def __call__(self, f: Any) -> Any: ... + + @overload + def __call__(self, f: _TT) -> _TT: ... + @overload + def __call__(self, f: _AF) -> _AF: ... + @overload + def __call__(self, f: _F) -> _F: ... + def __enter__(self) -> Any: ... def __exit__(self, *args: object) -> Any: ... def decorate_callable(self, f: _F) -> _F: ... From 3cd03d2841ae70037db4a23ff354a253c7e34b12 Mon Sep 17 00:00:00 2001 From: Max R Date: Fri, 28 Aug 2026 22:48:05 -0400 Subject: [PATCH 2/2] Simplify _patch_dict.__call__ to single overload _F's bound (Callable[..., Any]) already covers the class and async cases, and generic solving binds to the actual argument type rather than the bound, so the separate _TT/_AF overloads were redundant. --- stdlib/unittest/mock.pyi | 7 ------- 1 file changed, 7 deletions(-) diff --git a/stdlib/unittest/mock.pyi b/stdlib/unittest/mock.pyi index f467d6b66070..a7a0eec39136 100644 --- a/stdlib/unittest/mock.pyi +++ b/stdlib/unittest/mock.pyi @@ -301,14 +301,7 @@ class _patch_dict: values: Any clear: Any def __init__(self, in_dict: Any, values: Any = (), clear: Any = False, **kwargs: Any) -> None: ... - - @overload - def __call__(self, f: _TT) -> _TT: ... - @overload - def __call__(self, f: _AF) -> _AF: ... - @overload def __call__(self, f: _F) -> _F: ... - def __enter__(self) -> Any: ... def __exit__(self, *args: object) -> Any: ... def decorate_callable(self, f: _F) -> _F: ...