-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add missing typings to unittest.mock
#7431
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
Add missing typings to unittest.mock
#7431
Conversation
@@ -428,14 +428,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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I should change this, however it doesn't really make much sense to me that name
is typed as Any
in the module's stubs, when it's clear that it's supposed to be a string (at least from what I could tell from the CPython source).
Note that I doubt that mypy_primer's output will be of use here, as tests in Python projects are usually not type-checked, and the unittest module is usually not used in regular (non-test) code. |
If these are the only missing annotations in this file, you could also delete this line as part of this PR, increasing pyright's strictness when checking this file as part of CI: typeshed/pyrightconfig.stricter.json Line 16 in c50cb06
|
@AlexWaygood will do! |
This comment has been minimized.
This comment has been minimized.
Seems like there are some missing typings which mypy didn't report. I'll look into pyright's output. |
This comment has been minimized.
This comment has been minimized.
@@ -74,21 +74,35 @@ class _Sentinel: | |||
|
|||
sentinel: Any | |||
DEFAULT: Any | |||
_ArgsKwargs = tuple[tuple[Any, ...], Mapping[str, Any]] | |||
_NameArgsKwargs = tuple[str, tuple[Any, ...], Mapping[str, Any]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that kwargs
is typed as Any
in the rest of the stubs, but I wanted to be more strict here.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skimmed, the simple annotation additions look good to me. If we do want to try making _Call
generic over something, I'd move that into its own PR. We've had at least a couple bad regressions involving unittest.mock
, so it's something I'm wary of :-)
@hauntsaninja I agree :) I'll revert some of my newer additions. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
(I found these by adding the
--disallow-incomplete-defs
flag to the mypy tests.)