####  Next topic

[ ` pydoc  ` â Documentation generator and online help system ](pydoc.html
"next chapter")

###  This Page

  * [ Report a Bug ](../bugs.html)
  * [ Show Source ](https://github.com/python/cpython/blob/main/Doc/library/typing.rst)

###  Navigation

  * [ index ](../genindex.html "General Index")
  * [ modules ](../py-modindex.html "Python Module Index") | 
  * [ next ](pydoc.html "pydoc â Documentation generator and online help system") | 
  * [ previous ](development.html "Development Tools") | 
  * ![Python logo](../_static/py.svg)
  * [ Python ](https://www.python.org/) » 
  *   *   * [ 3.12.3 Documentation ](../index.html) » 
  * [ The Python Standard Library ](index.html) » 
  * [ Development Tools ](development.html) » 
  * [ ` typing  ` â Support for type hints ]()
  * | 
  * Theme  Auto  Light  Dark  | 

#  ` typing  ` â Support for type hints  Â¶

New in version 3.5.

**Source code:** [ Lib/typing.py
](https://github.com/python/cpython/tree/3.12/Lib/typing.py)

Note

The Python runtime does not enforce function and variable type annotations.
They can be used by third party tools such as [ type checkers
](../glossary.html#term-static-type-checker) , IDEs, linters, etc.

* * *

This module provides runtime support for type hints.

Consider the function below:

    
    
    def moon_weight(earth_weight: float) -> str:
        return f'On the moon, you would weigh {earth_weight * 0.166} kilograms.'
    

The function ` moon_weight  ` takes an argument expected to be an instance of
[ ` float  ` ](functions.html#float "float") , as indicated by the _type hint_
` earth_weight:  float  ` . The function is expected to return an instance of
[ ` str  ` ](stdtypes.html#str "str") , as indicated by the ` -> str  ` hint.

While type hints can be simple classes like [ ` float  `
](functions.html#float "float") or [ ` str  ` ](stdtypes.html#str "str") ,
they can also be more complex. The  ` typing  ` module provides a vocabulary
of more advanced type hints.

New features are frequently added to the ` typing  ` module. The [
typing_extensions ](https://pypi.org/project/typing_extensions/) package
provides backports of these new features to older versions of Python.

See also

[ âTyping cheat sheetâ
](https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html)

    

A quick overview of type hints (hosted at the mypy docs)

âType System Referenceâ section of [ the mypy docs
](https://mypy.readthedocs.io/en/stable/index.html)

    

The Python typing system is standardised via PEPs, so this reference should
broadly apply to most Python type checkers. (Some parts may still be specific
to mypy.)

[ âStatic Typing with Pythonâ ](https://typing.readthedocs.io/en/latest/)

    

Type-checker-agnostic documentation written by the community detailing type
system features, useful typing related tools and typing best practices.

##  Specification for the Python Type System  Â¶

The canonical, up-to-date specification of the Python type system can be found
at [ âSpecification for the Python type systemâ
](https://typing.readthedocs.io/en/latest/spec/index.html) .

##  Type aliases  Â¶

A type alias is defined using the [ ` type  `
](../reference/simple_stmts.html#type) statement, which creates an instance of
` TypeAliasType  ` . In this example, ` Vector  ` and ` list[float]  ` will be
treated equivalently by static type checkers:

    
    
    type Vector = list[float]
    
    def scale(scalar: float, vector: Vector) -> Vector:
        return [scalar * num for num in vector]
    
    # passes type checking; a list of floats qualifies as a Vector.
    new_vector = scale(2.0, [1.0, -4.2, 5.4])
    

Type aliases are useful for simplifying complex type signatures. For example:

    
    
    from collections.abc import Sequence
    
    type ConnectionOptions = dict[str, str]
    type Address = tuple[str, int]
    type Server = tuple[Address, ConnectionOptions]
    
    def broadcast_message(message: str