You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The probable reason NonCallableMock (and the other mock classes) were defined like this is so that they can be passed in place as any other object without type checkers complaining. I think I remember some discussion about it where it was suggested that the mock classes should derive from Any instead, something like this:
classNonCallableMock(Base, Any):
def__getattr__(self, name: str) ->Any: ...
# other methods go here
I quickly tried this, and it seems to work fine with mypy. I think this is worth a go.
I'm using pycharm and found on this stack overflow answer that pycharm uses typeshed for its stub autocompletion.
I'm not having the autocompletions of any Mock or MagickMock methods (such as
assert_called
,assert_called_once
and so on).Browsing the typeshed code I stumbled upon this line
typeshed/stdlib/3/unittest/mock.pyi
Line 38 in 5162c53
There's a TODO annotation 3 lines above mentioning some false positives
typeshed/stdlib/3/unittest/mock.pyi
Line 35 in 5162c53
What does the
Any
do onNonCallableMock
?Shouldn't we have all methods declared no this
NonCallableMock
? Or this was the cause of the TODO?I'm volunteering to open a PR if we should have all mock methods declared
The text was updated successfully, but these errors were encountered: