Type inference

Mypy considers the initial assignment as the definition of a variable.If you do not explicitlyspecify the type of the variable, mypy infers the type based on thestatic type of the value expression:

  1. i = 1 # Infer type "int" for i
  2. l = [1, 2] # Infer type "List[int]" for l

Type inference is not used in dynamically typed functions (thosewithout a function type annotation) — every local variable type defaultsto Any in such functions. Any is discussed later in more detail.