Yes, there is a difference. Although in Python 3 all objects are instances of the object , including the object itself, only Any documents whose return values ββshould be ignored by type checking.
A documentation line of type Any states that the object is a subclass of Any and vice versa:
>>> import typing >>> 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.
However, a proper type checker (which goes beyond isinstance() and that checks how an object is actually used in a function) can easily object to an object where Any always accepted.
From Any type documentation :
Note that when assigning a value of type Any more accurate type, type checking is not performed.
and
Compare the behavior of Any with the behavior of object . Like Any , each type is a subtype of object . However, unlike Any , the converse is not true: an object is not a subtype of any other type.
This means that when the value type is object , the 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.
and from the documentation section of mypy Any against object :
The type object is another type that can have an instance of an arbitrary type as a value. Unlike Any , an object is a regular static type (it is similar to Object in Java), and only values ββvalid for all types are accepted for the values ββof the object.
object can be cast to a more specific type, while Any really means that something is coming, and the type checker is disconnected from any use of the object (even if you subsequently assign such an object to a name checked by type).
You have already drawn your function in an untyped corner by accepting list , which comes down to the same as List[Any] . Type checking is disabled here, and the return value no longer matters, but since your function accepts a list containing Any objects, the correct return value will be Any here.
To participate in the code being checked correctly, you must mark your input as List[T] (a generic type container) for type checking, so that you can then take care of the return value. Which in your case will be T since you get the value from the list. Create T from TypeVar :
from typing import TypeVar, List T = TypeVar('T') def get_item(L: List[T], i: int) -> T: return L[i]