[ ![Python logo](../_static/py.svg) ](https://www.python.org/)

Theme  Auto  Light  Dark

###  [ Table of Contents ](../contents.html)

  * ` typing  ` â Support for type hints 
    * Specification for the Python Type System 
    * Type aliases 
    * NewType 
    * Annotating callable objects 
    * Generics 
    * Annotating tuples 
    * The type of class objects 
    * User-defined generic types 
    * The ` Any  ` type 
    * Nominal vs structural subtyping 
    * Module contents 
      * Special typing primitives 
        * Special types 
        * Special forms 
        * Building generic types and type aliases 
        * Other special directives 
      * Protocols 
      * ABCs for working with IO 
      * Functions and decorators 
      * Introspection helpers 
      * Constant 
      * Deprecated aliases 
        * Aliases to built-in types 
        * Aliases to types in ` collections  `
        * Aliases to other concrete types 
        * Aliases to container ABCs in ` collections.abc  `
        * Aliases to asynchronous ABCs in ` collections.abc  `
        * Aliases to other ABCs in ` collections.abc  `
        * Aliases to ` contextlib  ` ABCs 
    * Deprecation Timeline of Major Features 

####  Previous topic

[ Development Tools ](development.html "previous chapter")

####  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.2 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 Py