google / pytype

A static type analyzer for Python code

Home Page:https://google.github.io/pytype

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Might mock.MagicMock be given a type parameter?

nathanielmanistaatgoogle opened this issue · comments

In the case of

class MyClass:
  def method_that_exists_on_my_class(self):
    pass

my_mock_thing = mock.create_autospec(MyClass)
my_mock_thing.method_that_exists_on_my_class()
my_mock_thing.method_that_does_not_exist_on_my_class()
my_mock_thing.method_that_exists_on_my_class.assert_called_once()
my_mock_thing.method_that_does_not_exist_on_my_class.assert_called_once()

it would be nice if the type of my_mock_thing were mock.MagicMock[MyClass] (instead of "raw" mock.MagicMock) so that type-checkers could alert me that my call to my_mock_thing.method_that_does_not_exist_on_my_class is a flaw in my test.

Ooops; wrong browser tab, wrong issue tracker. 😛 Please look over here instead.