diff options
author | Guido 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) |
commit | dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c (patch) | |
tree | 07829c4f286194d0e3d08151a26ef1f3494a849b /Lib/ast.py | |
parent | d97daebfa69b4df95231bcae4123eacad6a48d14 (diff) | |
download | cpython-dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c.zip cpython-dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c.tar.gz cpython-dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c.tar.bz2 |
bpo-35766: Merge typed_ast back into CPython (GH-11645)
Diffstat (limited to 'Lib/ast.py')
-rw-r--r-- | Lib/ast.py | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -27,12 +27,16 @@ from _ast import * -def parse(source, filename='<unknown>', mode='exec'): +def parse(source, filename='<unknown>', mode='exec', *, type_comments=False): """ Parse the source into an AST node. Equivalent to compile(source, filename, mode, PyCF_ONLY_AST). + Pass type_comments=True to get back type comments where the syntax allows. """ - return compile(source, filename, mode, PyCF_ONLY_AST) + flags = PyCF_ONLY_AST + if type_comments: + flags |= PyCF_TYPE_COMMENTS + return compile(source, filename, mode, flags) def literal_eval(node_or_string): |