title: How to type hint an instance-level function (i.e. not a method)?
body: <p>Instance attributes are typically <a href="https://www.python.org/dev/peps/pep-0526/#class-and-instance-variable-annotations" rel="nofollow noreferrer">annotated</a> on the class:</p>
  <pre class="lang-py prettyprint-override"><code>class Foo:
      x: int
  
      def __init__(self, x):
          self.x = x
  
  Foo(0).x
  </code></pre>
  <p>This works and mypy doesn't report any issues. However, when the instance attribute is a <a href="https://docs.python.org/3/library/typing.html#typing.Callable" rel="nofollow noreferrer"><code>Callable</code></a> then mypy starts complaining:</p>
  <pre class="lang-py prettyprint-override"><code>from typing import Callable
  
  
  class Foo:
      func: Callable[[], int]
  
      def __init__(self, func):
          self.func = func
  
  
  Foo(lambda: 0).func()
  </code></pre>
  <p>I get the following error:</p>
  <pre class="lang-none prettyprint-override"><code>test.py:11: error: Attribute function &quot;func&quot; with type &quot;Callable[[], int]&quot; does not accept self argument
  Found 1 error in 1 file (checked 1 source file)
  </code></pre>
  <p>Since this function is not defined on the class, but only stored in the instance dict, it won't be bound to the instance during attribute lookup (in short: the above snippet works). So I don't see why mypy would complain about this. Is there another way to type hint such instance-level functions?</p>