]> granicus.if.org Git - python/commitdiff
Simplify main() of test_ast
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 8 Feb 2016 16:15:21 +0000 (17:15 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 8 Feb 2016 16:15:21 +0000 (17:15 +0100)
* Use ast.parse() to get the AST for a statement
* Use str%args syntax for format a line

Issue #26204.

Lib/test/test_ast.py

index 57060d833c2fd3702c373bad0b7d28dde576b712..f5c4adeb6f8ae50be89913fc916a44a4e12d6003 100644 (file)
@@ -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