diff -r da485c6c744e Doc/whatsnew/3.6.rst --- a/Doc/whatsnew/3.6.rst Mon Sep 12 19:27:46 2016 +0200 +++ b/Doc/whatsnew/3.6.rst Mon Sep 12 22:35:45 2016 +0200 @@ -72,7 +72,7 @@ * PEP 515: Underscores in Numeric Literals -* PEP 526: Syntax for Variable Annotations +* PEP 526: :ref:`Syntax for Variable Annotations ` * PEP 525: Asynchronous Generators @@ -275,6 +275,38 @@ See :pep:`498` and the main documentation at :ref:`f-strings`. + +.. _variable-annotations: + +PEP 526: Syntax for variable annotations +======================================== + +:pep:`484` introduced standard for type annotations of function parameters, +a.k.a. type hints. This PEP adds syntax to Python for annotating the +types of variables (including class variables and instance variables):: + + primes: List[int] = [] + + captain: str # Note: no initial value! + + class Starship: + stats: Dict[str, int] = {} + +Just as for function annotations, Python interpreter does not attach any +particular meaning to variable annotations and only stores them in a special +attribute ``__annotations__`` of a class or module. +In contrast to variable declarations in statically typed languages, +the goal of annotation syntax is to provide an easy way to specify structured +type metadata for third party tools and libraries via abstract syntax tree and +the ``__annotations__`` attribute. + +.. seealso:: + + :pep:`526` -- Syntax for variable annotations. + PEP written by Ryan Gonzalez, Philip House, Ivan Levkivskyi, Lisa Roach, + and Guido van Rossum + + .. _pep-529: PEP 529: Change Windows filesystem encoding to UTF-8