From: Victor Stinner Date: Mon, 8 Feb 2016 16:15:21 +0000 (+0100) Subject: Simplify main() of test_ast X-Git-Tag: v3.6.0a1~636 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f089196beb0ad8fb262be42eddd92af3f0fe81c1;p=python Simplify main() of test_ast * Use ast.parse() to get the AST for a statement * Use str%args syntax for format a line Issue #26204. --- diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 57060d833c..f5c4adeb6f 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -1064,8 +1064,9 @@ def main(): for statements, kind in ((exec_tests, "exec"), (single_tests, "single"), (eval_tests, "eval")): print(kind+"_results = [") - for s in statements: - print(repr(to_tuple(compile(s, "?", kind, 0x400)))+",") + for statement in statements: + tree = ast.parse(statement, "?", kind) + print("%r," % (to_tuple(tree),)) print("]") print("main()") raise SystemExit