summaryrefslogtreecommitdiffstats
path: root/Doc/library/ast.rst
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2019-01-31 11:40:27 (GMT)
committerƁukasz Langa <lukasz@langa.pl>2019-01-31 11:40:27 (GMT)
commitdcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c (patch)
tree07829c4f286194d0e3d08151a26ef1f3494a849b /Doc/library/ast.rst
parentd97daebfa69b4df95231bcae4123eacad6a48d14 (diff)
downloadcpython-dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c.zip
cpython-dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c.tar.gz
cpython-dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c.tar.bz2
bpo-35766: Merge typed_ast back into CPython (GH-11645)
Diffstat (limited to 'Doc/library/ast.rst')
-rw-r--r--Doc/library/ast.rst19
1 files changed, 18 insertions, 1 deletions
diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst
index 7715a28..3df7f9e 100644
--- a/Doc/library/ast.rst
+++ b/Doc/library/ast.rst
@@ -126,16 +126,33 @@ The abstract grammar is currently defined as follows:
Apart from the node classes, the :mod:`ast` module defines these utility functions
and classes for traversing abstract syntax trees:
-.. function:: parse(source, filename='<unknown>', mode='exec')
+.. function:: parse(source, filename='<unknown>', mode='exec', *, type_comments=False)
Parse the source into an AST node. Equivalent to ``compile(source,
filename, mode, ast.PyCF_ONLY_AST)``.
+ If ``type_comments=True`` is given, the parser is modified to check
+ and return type comments as specified by :pep:`484` and :pep:`526`.
+ This is equivalent to adding :data:`ast.PyCF_TYPE_COMMENTS` to the
+ flags passed to :func:`compile()`. This will report syntax errors
+ for misplaced type comments. Without this flag, type comments will
+ be ignored, and the ``type_comment`` field on selected AST nodes
+ will always be ``None``. In addition, the locations of ``# type:
+ ignore`` comments will be returned as the ``type_ignores``
+ attribute of :class:`Module` (otherwise it is always an empty list).
+
+ In addition, if ``mode`` is ``'func_type'``, the input syntax is
+ modified to correspond to :pep:`484` "signature type comments",
+ e.g. ``(str, int) -> List[str]``.
+
.. warning::
It is possible to crash the Python interpreter with a
sufficiently large/complex string due to stack depth limitations
in Python's AST compiler.
+ .. versionchanged:: 3.8
+ Added ``type_comments=True`` and ``mode='func_type'``.
+
.. function:: literal_eval(node_or_string)