Skip to content

Fix unittest.mock.patch and unittest.mock.patch.object when new_callable is not None #14358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

leonarduschen
Copy link

@leonarduschen leonarduschen commented Jul 1, 2025

This PR fixes wrong type unittest.mock.patch and unittest.mock.patch.object when new_callable is not None.

They should return patch[T] when new callable is Callable[..., T]

Details on #14339

@leonarduschen leonarduschen changed the title Fix patch and patch.object when new_callable is not None Fix unittest.mock.patch and unittest.mock.patch.object when new_callable is not None Jul 1, 2025
Copy link
Contributor

github-actions bot commented Jul 1, 2025

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

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be interested in adding a few test cases to https://github.com/python/typeshed/blob/main/stdlib/%40tests/test_cases/check_unittest.py ? (the unittest.mock stubs can get a little tricky)

@leonarduschen
Copy link
Author

sure!

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.

2 participants