typing - Support for type hints

This module provides runtime support for type hints as specified by PEP 484, PEP 526, PEP 544, PEP 586, PEP 589, PEP 591, PEP 612 and PEP 613. The most fundamental support consists of the types Any, Union, Tuple, Callable, TypeVar, and Generic. For full specification please see PEP 484. For a simplified introduction to type hints see PEP 483.

import typing

# preferred
from typing import Dict, List, Union, Any

myvar: Dict = {}
# non-preferred
import typing

myvar: typing.Dict = {}

Code examples

from typing import Mapping, Dict, Any, Union

example1: Dict = {}

example2: Dict[str, Any]

example2: Mapping[str, int]

example3: Union[Dict[str, int], None]

example4: Union[str, None]

def hello(name: str) -> str:
    return f"Hello {name}"


See Also

pydantic 1.8.2

Data validation and settings management using python 3.6 type hinting