-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Need a way to specify types for mock objects (e.g. mock.Mock()) #1188
Comments
Here is one way of supporting this:
Another approach would be to special case |
Yeah, I think that approach makes a lot of sense. |
I'm writing unit tests and this is a real nuisance for PEP8 compliance. example code:
PEP8 Type check will throw a warning saying it expected a type worker but got type magic mock instead. |
What is "PEP8 Type check"? Note that we waffled a bit on this -- up till mypy 0.610 there was no typeshed definition for Mock. Then we added one, but we found it was too noisy, and we rolled it back, instead changing it so that we have See also python/typing#567. (Maybe this is the feature Tim was looking for?) |
Any updates on this? Running Mypy on any test that involves mocks is painful... |
If you want help, please post a full example of what you’re experiencing.
On Thu, Apr 11, 2019 at 8:17 AM Matan Rubin ***@***.***> wrote:
Any updates on this? Running Mypy on any test that involves mocks is
painful...
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1188 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACwrMmqE8aOI-a5a_BNeNzvQaXyKSJ8tks5vf1IegaJpZM4HOzDL>
.
--
--Guido (mobile)
|
@gvanrossum, after re-examining the behavior I'm experiencing, I think it's related to this issue but not exactly the same. Opened a separate issue to track what I'm seeing: #6713 |
Would/Could using Protocols work to annotate mocked objects? class MyMockedObjectProtocol(MockProtocol, MyObjectProtocol, Protocol):
...
mymock: MyMockedObjectProtocol = Mock() |
Example test case code here:
Posting this in mypy, since I don't think it's possible to specify a typeshed type for mock.Mock that won't throw an error; e.g. if stubs say
mock.Mock
is anAny
, you get/home/tabbott/foo.py:7: error: Invalid assignment target
Reporting as separate from #1152 since this might be worth solving even if that is not, since most every use of mock.Mock() will have this problem.
The text was updated successfully, but these errors were encountered: