Type Hints
December 11, 2020Syntax support for type hints (Python 3.5+)
The Python runtime does not enforce function and variable type annotations. They can be used by third party tools such as type checkers, IDEs, linters, etc.
Function Signature Annotations
from typing import Any, Dict, List, Tuple
def example(
s: str,
i: int,
l: List[int],
t: Tuple[int,int],
tt: Tuple[Any,...]
) -> List[Tuple[Dict[str, int], bool]]:
return
Variable Annotations
some_number: int # variable without initial value
some_list: List[int] = [] # variable with initial value
t: Tuple[int, ...] = (1, 2, 3)
other_var: int = 'a' # Flagged as error by type