title: How to use typing.Protocol with modules?
body: <p>I'd like to define a protocol which could be satisfied by an object, which might be a module:</p>
  
  <pre class="lang-py prettyprint-override"><code>from typing import Protocol
  
  class MyType(Protocol):
      def foo(self) -&gt; int:
          ...
  
  
  class MyClass:
      def foo(self) -&gt; int:
          return 1
  
  # this is OK
  a = MyClass()  # type: MyType
  
  import mymodule
  # mymodule.py just contains 
  # def foo() -&gt; int:
  #     return 42
  
  # but this is not.
  b = mymodule  # type: MyType
  # mypy complains saying
  # Incompatible types in assignment (expression has type Module, variable has type "MyType")
  
  
  import inspect
  print(inspect.signature(a.foo))
  print(inspect.signature(b.foo))
  # both print: () -&gt; int
  </code></pre>
  
  <p>gist here: <a href="https://gist.github.com/hjwp/e322c86d14ce0b11f08b27d7b17f7791" rel="noreferrer">https://gist.github.com/hjwp/e322c86d14ce0b11f08b27d7b17f7791</a></p>