[Python-checkins] cpython (3.6): Add text about PEP 526 to What's new in 3.6. Ivan L.
guido.van.rossum
python-checkins at python.org
Tue Sep 13 12:27:14 EDT 2016
https://hg.python.org/cpython/rev/f9b22b1bec2d
changeset: 103769:f9b22b1bec2d
branch: 3.6
parent: 103767:12d88d08f191
user: Guido van Rossum <guido at python.org>
date: Tue Sep 13 09:26:38 2016 -0700
summary:
Add text about PEP 526 to What's new in 3.6. Ivan L.
files:
Doc/whatsnew/3.6.rst | 38 +++++++++++++++++++++++++++++++-
1 files changed, 37 insertions(+), 1 deletions(-)
diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst
--- a/Doc/whatsnew/3.6.rst
+++ b/Doc/whatsnew/3.6.rst
@@ -72,7 +72,7 @@
* PEP 515: Underscores in Numeric Literals
-* PEP 526: Syntax for Variable Annotations
+* PEP 526: :ref:`Syntax for Variable Annotations <variable-annotations>`
* PEP 525: Asynchronous Generators
@@ -277,6 +277,42 @@
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, the 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 the 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. Implemented by Ivan Levkivskyi.
+
+ Tools that use or will use the new syntax:
+ `mypy <http://github.com/python/mypy>`_,
+ `pytype <http://github.com/google/pytype>`_, PyCharm, etc.
+
+
.. _pep-529:
PEP 529: Change Windows filesystem encoding to UTF-8
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list