title: Python type hint for classes that support __getitem__
body: <p>I want to add type hints to a function that will accept any object with a <code>__getitem__</code> method. For instance, in</p>
  
  <pre><code>def my_function(hasitems, locator):
      hasitems[locator]
  </code></pre>
  
  <p>I don't want to restrict <code>hasitems</code> to be a specific type like <code>list</code> or <code>dict</code>. As long as it supports <code>__getitem__</code>, it's an appropriate argument to <code>my_function</code>. How can I annotate its type without being unnecessarily restrictive?</p>
  
  <p>Edit: apparently PyCharm can deduce the appropriate hint in a number of common cases, but not in my actual use case. I can't post the code since it's for work, and I haven't been able to find a nonproprietary minimal example where PyCharm fails. In any case, the original question doesn't reference PyCharm and it is still a valid use case for type hints.</p>