From dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 31 Jan 2019 03:40:27 -0800 Subject: bpo-35766: Merge typed_ast back into CPython (GH-11645) --- Lib/ast.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'Lib/ast.py') diff --git a/Lib/ast.py b/Lib/ast.py index 6c1e978b05..470a74b3b5 100644 --- a/Lib/ast.py +++ b/Lib/ast.py @@ -27,12 +27,16 @@ from _ast import * -def parse(source, filename='', mode='exec'): +def parse(source, filename='', 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): -- cgit v1.2.1