Skip to content

Add typing to unittest.mock._patch_dict.__call__ - #16310

Open
mxr wants to merge 2 commits into
python:mainfrom
mxr:patch-dict
Open

Add typing to unittest.mock._patch_dict.__call__#16310
mxr wants to merge 2 commits into
python:mainfrom
mxr:patch-dict

Conversation

@mxr

@mxr mxr commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Resolves #16307

@github-actions

This comment has been minimized.

Comment thread stdlib/unittest/mock.pyi Outdated
@AlexWaygood

Copy link
Copy Markdown
Member

I dug through the blame a bit to see if there had been any previous churn or discussion about this signature, since annotations in unittest.mock have caused us some level of difficulty in the past... it looks like this has been unchanged since 2017! Type annotations were added in #973

@AlexWaygood

Copy link
Copy Markdown
Member

This LGTM other than the simplification I suggested above, it does seem like this preserves the wrapped function's signature. Thanks!

_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.
@mxr mxr changed the title Add overloads to unittest.mock._patch_dict.__call__ Add typing to unittest.mock._patch_dict.__call__ Aug 29, 2026
@mxr
mxr requested a review from AlexWaygood August 29, 2026 02:49
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@patch.dict(...) loses wrapped function's signature

2 participants