typing.Any vs object?
<p>Is there any difference between using <code>typing.Any</code> as opposed to <code>object</code> in typing? For example:</p>

<pre><code>def get_item(L: list, i: int) -&gt; typing.Any:
    return L[i]
</code></pre>

<p>Compared to:</p>

<pre><code>def get_item(L: list, i: int) -&gt; object:
    return L[i]
</code></pre>

<p>Yes, there is a difference. Although in Python 3, all objects are instances of <code>object</code>, including <code>object</code> itself, only <code>Any</code> documents that the return value should be disregarded by the typechecker.</p>

<p>The <code>Any</code> type docstring states that object is a subclass of <code>Any</code> and vice-versa:</p>

<pre><code>&gt;&gt;&gt; import typing
&gt;&gt;&gt; print(typing.Any.__doc__)
Special type indicating an unconstrained type.

    - Any object is an instance of Any.
    - Any class is a subclass of Any.
    - As a special case, Any and object are subclasses of each other.
</code></pre>

<p>However, a proper typechecker (one that goes beyond <code>isinstance()</code> checks, and which inspects how the object is actually <em>used</em> in the function) can readily object to <code>object</code> where <code>Any</code> is always accepted.</p>

<p>From the <a href="https://docs.python.org/3/library/typing.html#the-any-type" rel="nofollow"><code>Any</code> type documentation</a>:</p>

<blockquote>
  <p>Notice that no typechecking is performed when assigning a value of type <code>Any</code> to a more precise type.</p>
</blockquote>

<p>and</p>

<blockquote>
  <p>Contrast the behavior of <code>Any</code> with the behavior of <code>object</code>. Similar to <code>Any</code>, every type is a subtype of <code>object</code>. However, unlike <code>Any</code>, the reverse is not true: object is not a subtype of every other type.</p>
  
  <p>That means when the type of a value is <code>object</code>, a type checker will reject almost all operations on it, and assigning it to a variable (or using it as a return value) of a more specialized type is a type error.</p>
</blockquote>

<p>and from the mypy documentation section <a href="http://mypy.readthedocs.io/en/latest/dynamic_typing.html#any-vs-object" rel="nofollow"><em>Any vs. object</em></a>:</p>

<blockquote>
  <p>The type <code>object</code> is another type that can have an instance of arbitrary type as a value. Unlike <code>Any</code>, <code>object</code> is an ordinary static type (it is similar to <code>Object</code> in Java), and only operations valid for all types are accepted for object values.</p>
</blockquote>

<p><code>object</code> can be <a href="http://mypy.readthedocs.io/en/latest/casts.html#casts" rel="nofollow">cast</a> to a more specific type, while <code>Any</code> really means <em>anything goes</em> and a type checker disengages from any use of the object (even if you later assign such an object to a name that <em>is</em> typechecked).</p>

<p>You already painted your function into a an un-typed corner by accepting <code>list</code>, which comes down to being the same thing as <code>List[Any]</code>. The typechecker <em>disengaged there</em> and the return value no longer matters, but since your function accepts a list containing <code>Any</code> objects, the proper return value would be <code>Any</code> here.</p>

<p>To properly participate in type-checked code, you need to mark your input as <code>List[T]</code> (a genericly typed container) for a typechecker to then be able to care about the return value. Which in your case would be <code>T</code> since you are retrieving a value from the list. Create <code>T</code> from a <code>TypeVar</code>:</p>

<pre><code>from typing import TypeVar, List

T = TypeVar('T')

def get_item(L: List[T], i: int) -&gt; T:
    return L[i]
</code></pre>

python python-3.5 type-hinting