Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(37)

## Delta Between Two Patch Sets: Lib/test/test_ast.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 6 years, 4 months ago
Right Patch Set: Created 5 years, 11 months ago
 Left: Base Patch Set 1: None Patch Set 2: None Patch Set 3: None Patch Set 4: None Patch Set 5: None Right: Patch Set 1: None Patch Set 2: None Patch Set 3: None Patch Set 4: None Patch Set 5: None
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_abc.py ('k') | Lib/test/test_asyncore.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Hide Comments ('s')
LEFTRIGHT
1 import os 1 import os
2 import sys 2 import sys
3 import unittest 3 import unittest
4 import ast 4 import ast
5 import weakref 5 import weakref
6 6
7 from test import support 7 from test import support
8 8
9 def to_tuple(t): 9 def to_tuple(t):
10 if t is None or isinstance(t, (str, int, complex)): 10 if t is None or isinstance(t, (str, int, complex)):
11 return t 11 return t
12 elif isinstance(t, list): 12 elif isinstance(t, list):
13 return [to_tuple(e) for e in t] 13 return [to_tuple(e) for e in t]
14 result = [t.__class__.__name__] 14 result = [t.__class__.__name__]
15 if hasattr(t, 'lineno') and hasattr(t, 'col_offset'): 15 if hasattr(t, 'lineno') and hasattr(t, 'col_offset'):
16 result.append((t.lineno, t.col_offset)) 16 result.append((t.lineno, t.col_offset))
17 if t._fields is None: 17 if t._fields is None:
18 return tuple(result) 18 return tuple(result)
19 for f in t._fields: 19 for f in t._fields:
20 result.append(to_tuple(getattr(t, f))) 20 result.append(to_tuple(getattr(t, f)))
21 return tuple(result) 21 return tuple(result)
22 22
23 23
24 # These tests are compiled through "exec" 24 # These tests are compiled through "exec"
25 # There should be atleast one test per statement 25 # There should be at least one test per statement
26 exec_tests = [ 26 exec_tests = [
27 # None 27 # None
28 "None", 28 "None",
29 # FunctionDef 29 # FunctionDef
30 "def f(): pass", 30 "def f(): pass",
31 # FunctionDef with arg 31 # FunctionDef with arg
32 "def f(a): pass", 32 "def f(a): pass",
33 # FunctionDef with arg and default value 33 # FunctionDef with arg and default value
34 "def f(a=0): pass", 34 "def f(a=0): pass",
35 # FunctionDef with varargs 35 # FunctionDef with varargs
(...skipping 137 matching lines...)
173 # Combination 173 # Combination
174 "a.b.c.d(a.b[1:2])", 174 "a.b.c.d(a.b[1:2])",
175 175
176 ] 176 ]
177 177
178 # TODO: expr_context, slice, boolop, operator, unaryop, cmpop, comprehension 178 # TODO: expr_context, slice, boolop, operator, unaryop, cmpop, comprehension
179 # excepthandler, arguments, keywords, alias 179 # excepthandler, arguments, keywords, alias
180 180
181 class AST_Tests(unittest.TestCase): 181 class AST_Tests(unittest.TestCase):
182 182
183 def _assertTrueorder(self, ast_node, parent_pos): 183 def _assertTrueorder(self, ast_node, parent_pos, reverse_check = False):
184 def should_reverse_check(parent, child):
185 # In some situations, the children of nodes occur before
186 # their parents, for example in a.b.c, a occurs before b
187 # but a is a child of b.
188 if isinstance(parent, ast.Call):
189 if parent.func == child:
190 return True
191 if isinstance(parent, (ast.Attribute, ast.Subscript)):
192 return True
193 return False
194
184 if not isinstance(ast_node, ast.AST) or ast_node._fields is None: 195 if not isinstance(ast_node, ast.AST) or ast_node._fields is None:
185 return 196 return
186 if isinstance(ast_node, (ast.expr, ast.stmt, ast.excepthandler)): 197 if isinstance(ast_node, (ast.expr, ast.stmt, ast.excepthandler)):
187 node_pos = (ast_node.lineno, ast_node.col_offset) 198 node_pos = (ast_node.lineno, ast_node.col_offset)
188 self.assertGreaterEqual(node_pos, parent_pos) 199 if reverse_check:
200 self.assertLessEqual(node_pos, parent_pos)
201 else:
202 self.assertGreaterEqual(node_pos, parent_pos)
189 parent_pos = (ast_node.lineno, ast_node.col_offset) 203 parent_pos = (ast_node.lineno, ast_node.col_offset)
190 for name in ast_node._fields: 204 for name in ast_node._fields:
191 value = getattr(ast_node, name) 205 value = getattr(ast_node, name)
192 if isinstance(value, list): 206 if isinstance(value, list):
193 for child in value: 207 for child in value:
194 self._assertTrueorder(child, parent_pos) 208 self._assertTrueorder(child, parent_pos,
209 should_reverse_check(ast_node, child))
195 elif value is not None: 210 elif value is not None:
196 self._assertTrueorder(value, parent_pos) 211 self._assertTrueorder(value, parent_pos,
212 should_reverse_check(ast_node, value))
197 213
198 def test_AST_objects(self): 214 def test_AST_objects(self):
199 x = ast.AST() 215 x = ast.AST()
200 self.assertEqual(x._fields, ()) 216 self.assertEqual(x._fields, ())
201 x.foobar = 42 217 x.foobar = 42
202 self.assertEqual(x.foobar, 42) 218 self.assertEqual(x.foobar, 42)
203 self.assertEqual(x.__dict__["foobar"], 42) 219 self.assertEqual(x.__dict__["foobar"], 42)
204 220
205 with self.assertRaises(AttributeError): 221 with self.assertRaises(AttributeError):
206 x.vararg 222 x.vararg
(...skipping 48 matching lines...)
255 271
256 def test_field_attr_existence(self): 272 def test_field_attr_existence(self):
257 for name, item in ast.__dict__.items(): 273 for name, item in ast.__dict__.items():
258 if isinstance(item, type) and name != 'AST' and name[0].isupper(): 274 if isinstance(item, type) and name != 'AST' and name[0].isupper():
259 x = item() 275 x = item()
260 if isinstance(x, ast.AST): 276 if isinstance(x, ast.AST):
261 self.assertEqual(type(x._fields), tuple) 277 self.assertEqual(type(x._fields), tuple)
262 278
263 def test_arguments(self): 279 def test_arguments(self):
264 x = ast.arguments() 280 x = ast.arguments()
265 self.assertEqual(x._fields, ('args', 'vararg', 'varargannotation', 281 self.assertEqual(x._fields, ('args', 'vararg',
266 'kwonlyargs', 'kwarg', 'kwargannotation', 282 'kwonlyargs', 'kw_defaults',
267 'defaults', 'kw_defaults')) 283 'kwarg', 'defaults'))
268 284
269 with self.assertRaises(AttributeError): 285 with self.assertRaises(AttributeError):
270 x.vararg 286 x.vararg
271 287
272 x = ast.arguments(*range(1, 9)) 288 x = ast.arguments(*range(1, 7))
273 self.assertEqual(x.vararg, 2) 289 self.assertEqual(x.vararg, 2)
274 290
275 def test_field_attr_writable(self): 291 def test_field_attr_writable(self):
276 x = ast.Num() 292 x = ast.Num()
277 # We can assign to _fields 293 # We can assign to _fields
278 x._fields = 666 294 x._fields = 666
279 self.assertEqual(x._fields, 666) 295 self.assertEqual(x._fields, 666)
280 296
281 def test_classattrs(self): 297 def test_classattrs(self):
282 x = ast.Num() 298 x = ast.Num()
(...skipping 149 matching lines...)
432 ) 448 )
433 self.assertEqual(ast.dump(node, annotate_fields=False), 449 self.assertEqual(ast.dump(node, annotate_fields=False),
434 "Module([Expr(Call(Name('spam', Load()), [Name('eggs', Load()), " 450 "Module([Expr(Call(Name('spam', Load()), [Name('eggs', Load()), "
435 "Str('and cheese')], [], None, None))])" 451 "Str('and cheese')], [], None, None))])"
436 ) 452 )
437 self.assertEqual(ast.dump(node, include_attributes=True), 453 self.assertEqual(ast.dump(node, include_attributes=True),
438 "Module(body=[Expr(value=Call(func=Name(id='spam', ctx=Load(), " 454 "Module(body=[Expr(value=Call(func=Name(id='spam', ctx=Load(), "
439 "lineno=1, col_offset=0), args=[Name(id='eggs', ctx=Load(), " 455 "lineno=1, col_offset=0), args=[Name(id='eggs', ctx=Load(), "
440 "lineno=1, col_offset=5), Str(s='and cheese', lineno=1, " 456 "lineno=1, col_offset=5), Str(s='and cheese', lineno=1, "
441 "col_offset=11)], keywords=[], starargs=None, kwargs=None, " 457 "col_offset=11)], keywords=[], starargs=None, kwargs=None, "
442 "lineno=1, col_offset=0), lineno=1, col_offset=0)])" 458 "lineno=1, col_offset=4), lineno=1, col_offset=0)])"
443 ) 459 )
444 460
445 def test_copy_location(self): 461 def test_copy_location(self):
446 src = ast.parse('1 + 1', mode='eval') 462 src = ast.parse('1 + 1', mode='eval')
447 src.body.right = ast.copy_location(ast.Num(2), src.body.right) 463 src.body.right = ast.copy_location(ast.Num(2), src.body.right)
448 self.assertEqual(ast.dump(src, include_attributes=True), 464 self.assertEqual(ast.dump(src, include_attributes=True),
449 'Expression(body=BinOp(left=Num(n=1, lineno=1, col_offset=0), ' 465 'Expression(body=BinOp(left=Num(n=1, lineno=1, col_offset=0), '
450 'op=Add(), right=Num(n=2, lineno=1, col_offset=4), lineno=1, ' 466 'op=Add(), right=Num(n=2, lineno=1, col_offset=4), lineno=1, '
451 'col_offset=0))' 467 'col_offset=0))'
452 ) 468 )
453 469
454 def test_fix_missing_locations(self): 470 def test_fix_missing_locations(self):
455 src = ast.parse('write("spam")') 471 src = ast.parse('write("spam")')
456 src.body.append(ast.Expr(ast.Call(ast.Name('spam', ast.Load()), 472 src.body.append(ast.Expr(ast.Call(ast.Name('spam', ast.Load()),
457 [ast.Str('eggs')], [], None, None))) 473 [ast.Str('eggs')], [], None, None)))
458 self.assertEqual(src, ast.fix_missing_locations(src)) 474 self.assertEqual(src, ast.fix_missing_locations(src))
459 self.assertEqual(ast.dump(src, include_attributes=True), 475 self.assertEqual(ast.dump(src, include_attributes=True),
460 "Module(body=[Expr(value=Call(func=Name(id='write', ctx=Load(), " 476 "Module(body=[Expr(value=Call(func=Name(id='write', ctx=Load(), "
461 "lineno=1, col_offset=0), args=[Str(s='spam', lineno=1, " 477 "lineno=1, col_offset=0), args=[Str(s='spam', lineno=1, "
462 "col_offset=6)], keywords=[], starargs=None, kwargs=None, " 478 "col_offset=6)], keywords=[], starargs=None, kwargs=None, "
463 "lineno=1, col_offset=0), lineno=1, col_offset=0), " 479 "lineno=1, col_offset=5), lineno=1, col_offset=0), "
464 "Expr(value=Call(func=Name(id='spam', ctx=Load(), lineno=1, " 480 "Expr(value=Call(func=Name(id='spam', ctx=Load(), lineno=1, "
465 "col_offset=0), args=[Str(s='eggs', lineno=1, col_offset=0)], " 481 "col_offset=0), args=[Str(s='eggs', lineno=1, col_offset=0)], "
466 "keywords=[], starargs=None, kwargs=None, lineno=1, " 482 "keywords=[], starargs=None, kwargs=None, lineno=1, "
467 "col_offset=0), lineno=1, col_offset=0)])" 483 "col_offset=0), lineno=1, col_offset=0)])"
468 ) 484 )
469 485
470 def test_increment_lineno(self): 486 def test_increment_lineno(self):
471 src = ast.parse('1 + 1', mode='eval') 487 src = ast.parse('1 + 1', mode='eval')
472 self.assertEqual(ast.increment_lineno(src, n=3), src) 488 self.assertEqual(ast.increment_lineno(src, n=3), src)
473 self.assertEqual(ast.dump(src, include_attributes=True), 489 self.assertEqual(ast.dump(src, include_attributes=True),
(...skipping 79 matching lines...)
553 mod = ast.Module([stmt]) 569 mod = ast.Module([stmt])
554 self.mod(mod, msg) 570 self.mod(mod, msg)
555 571
556 def test_module(self): 572 def test_module(self):
557 m = ast.Interactive([ast.Expr(ast.Name("x", ast.Store()))]) 573 m = ast.Interactive([ast.Expr(ast.Name("x", ast.Store()))])
558 self.mod(m, "must have Load context", "single") 574 self.mod(m, "must have Load context", "single")
559 m = ast.Expression(ast.Name("x", ast.Store())) 575 m = ast.Expression(ast.Name("x", ast.Store()))
560 self.mod(m, "must have Load context", "eval") 576 self.mod(m, "must have Load context", "eval")
561 577
562 def _check_arguments(self, fac, check): 578 def _check_arguments(self, fac, check):
563 def arguments(args=None, vararg=None, varargannotation=None, 579 def arguments(args=None, vararg=None,
564 kwonlyargs=None, kwarg=None, kwargannotation=None, 580 kwonlyargs=None, kwarg=None,
565 defaults=None, kw_defaults=None): 581 defaults=None, kw_defaults=None):
566 if args is None: 582 if args is None:
567 args = [] 583 args = []
568 if kwonlyargs is None: 584 if kwonlyargs is None:
569 kwonlyargs = [] 585 kwonlyargs = []
570 if defaults is None: 586 if defaults is None:
571 defaults = [] 587 defaults = []
572 if kw_defaults is None: 588 if kw_defaults is None:
573 kw_defaults = [] 589 kw_defaults = []
574 args = ast.arguments(args, vararg, varargannotation, kwonlyargs, 590 args = ast.arguments(args, vararg, kwonlyargs, kw_defaults,
575 kwarg, kwargannotation, defaults, kw_defaults) 591 kwarg, defaults)
576 return fac(args) 592 return fac(args)
577 args = [ast.arg("x", ast.Name("x", ast.Store()))] 593 args = [ast.arg("x", ast.Name("x", ast.Store()))]
578 check(arguments(args=args), "must have Load context") 594 check(arguments(args=args), "must have Load context")
579 check(arguments(varargannotation=ast.Num(3)),
580 "varargannotation but no vararg")
581 check(arguments(varargannotation=ast.Name("x", ast.Store()), vararg="x") ,
582 "must have Load context")
583 check(arguments(kwonlyargs=args), "must have Load context") 595 check(arguments(kwonlyargs=args), "must have Load context")
584 check(arguments(kwargannotation=ast.Num(42)),
585 "kwargannotation but no kwarg")
586 check(arguments(kwargannotation=ast.Name("x", ast.Store()),
587 kwarg="x"), "must have Load context")
588 check(arguments(defaults=[ast.Num(3)]), 596 check(arguments(defaults=[ast.Num(3)]),
589 "more positional defaults than args") 597 "more positional defaults than args")
590 check(arguments(kw_defaults=[ast.Num(4)]), 598 check(arguments(kw_defaults=[ast.Num(4)]),
591 "length of kwonlyargs is not the same as kw_defaults") 599 "length of kwonlyargs is not the same as kw_defaults")
592 args = [ast.arg("x", ast.Name("x", ast.Load()))] 600 args = [ast.arg("x", ast.Name("x", ast.Load()))]
593 check(arguments(args=args, defaults=[ast.Name("x", ast.Store())]), 601 check(arguments(args=args, defaults=[ast.Name("x", ast.Store())]),
594 "must have Load context") 602 "must have Load context")
595 args = [ast.arg("a", ast.Name("x", ast.Load())), 603 args = [ast.arg("a", ast.Name("x", ast.Load())),
596 ast.arg("b", ast.Name("y", ast.Load()))] 604 ast.arg("b", ast.Name("y", ast.Load()))]
597 check(arguments(kwonlyargs=args, 605 check(arguments(kwonlyargs=args,
598 kw_defaults=[None, ast.Name("x", ast.Store())]), 606 kw_defaults=[None, ast.Name("x", ast.Store())]),
599 "must have Load context") 607 "must have Load context")
600 608
601 def test_funcdef(self): 609 def test_funcdef(self):
602 a = ast.arguments([], None, None, [], None, None, [], []) 610 a = ast.arguments([], None, [], [], None, [])
603 f = ast.FunctionDef("x", a, [], [], None) 611 f = ast.FunctionDef("x", a, [], [], None)
604 self.stmt(f, "empty body on FunctionDef") 612 self.stmt(f, "empty body on FunctionDef")
605 f = ast.FunctionDef("x", a, [ast.Pass()], [ast.Name("x", ast.Store())], 613 f = ast.FunctionDef("x", a, [ast.Pass()], [ast.Name("x", ast.Store())],
606 None) 614 None)
607 self.stmt(f, "must have Load context") 615 self.stmt(f, "must have Load context")
608 f = ast.FunctionDef("x", a, [ast.Pass()], [], 616 f = ast.FunctionDef("x", a, [ast.Pass()], [],
609 ast.Name("x", ast.Store())) 617 ast.Name("x", ast.Store()))
610 self.stmt(f, "must have Load context") 618 self.stmt(f, "must have Load context")
611 def fac(args): 619 def fac(args):
612 return ast.FunctionDef("x", args, [ast.Pass()], [], None) 620 return ast.FunctionDef("x", args, [ast.Pass()], [], None)
(...skipping 150 matching lines...)
763 b = ast.BoolOp(ast.And(), [ast.Num(4), None]) 771 b = ast.BoolOp(ast.And(), [ast.Num(4), None])
764 self.expr(b, "None disallowed") 772 self.expr(b, "None disallowed")
765 b = ast.BoolOp(ast.And(), [ast.Num(4), ast.Name("x", ast.Store())]) 773 b = ast.BoolOp(ast.And(), [ast.Num(4), ast.Name("x", ast.Store())])
766 self.expr(b, "must have Load context") 774 self.expr(b, "must have Load context")
767 775
768 def test_unaryop(self): 776 def test_unaryop(self):
769 u = ast.UnaryOp(ast.Not(), ast.Name("x", ast.Store())) 777 u = ast.UnaryOp(ast.Not(), ast.Name("x", ast.Store()))
770 self.expr(u, "must have Load context") 778 self.expr(u, "must have Load context")
771 779
772 def test_lambda(self): 780 def test_lambda(self):
773 a = ast.arguments([], None, None, [], None, None, [], []) 781 a = ast.arguments([], None, [], [], None, [])
774 self.expr(ast.Lambda(a, ast.Name("x", ast.Store())), 782 self.expr(ast.Lambda(a, ast.Name("x", ast.Store())),
775 "must have Load context") 783 "must have Load context")
776 def fac(args): 784 def fac(args):
777 return ast.Lambda(args, ast.Name("x", ast.Load())) 785 return ast.Lambda(args, ast.Name("x", ast.Load()))
778 self._check_arguments(fac, self.expr) 786 self._check_arguments(fac, self.expr)
779 787
780 def test_ifexp(self): 788 def test_ifexp(self):
781 l = ast.Name("x", ast.Load()) 789 l = ast.Name("x", ast.Load())
782 s = ast.Name("y", ast.Store()) 790 s = ast.Name("y", ast.Store())
783 for args in (s, l, l), (l, s, l), (l, l, s): 791 for args in (s, l, l), (l, s, l), (l, l, s):
(...skipping 148 matching lines...)
932 self.expr(ast.NameConstant(4), "singleton must be True, False, or None") 940 self.expr(ast.NameConstant(4), "singleton must be True, False, or None")
933 941
934 def test_stdlib_validates(self): 942 def test_stdlib_validates(self):
935 stdlib = os.path.dirname(ast.__file__) 943 stdlib = os.path.dirname(ast.__file__)
936 tests = [fn for fn in os.listdir(stdlib) if fn.endswith(".py")] 944 tests = [fn for fn in os.listdir(stdlib) if fn.endswith(".py")]
937 tests.extend(["test/test_grammar.py", "test/test_unpack_ex.py"]) 945 tests.extend(["test/test_grammar.py", "test/test_unpack_ex.py"])
938 for module in tests: 946 for module in tests:
939 fn = os.path.join(stdlib, module) 947 fn = os.path.join(stdlib, module)
940 with open(fn, "r", encoding="utf-8") as fp: 948 with open(fn, "r", encoding="utf-8") as fp:
941 source = fp.read() 949 source = fp.read()
942 mod = ast.parse(source) 950 mod = ast.parse(source, fn)
943 compile(mod, fn, "exec") 951 compile(mod, fn, "exec")
944 952
945
946 def test_main():
947 support.run_unittest(AST_Tests, ASTHelpers_Test, ASTValidatorTests)
948 953
949 def main(): 954 def main():
950 if __name__ != '__main__': 955 if __name__ != '__main__':
951 return 956 return
952 if sys.argv[1:] == ['-g']: 957 if sys.argv[1:] == ['-g']:
953 for statements, kind in ((exec_tests, "exec"), (single_tests, "single"), 958 for statements, kind in ((exec_tests, "exec"), (single_tests, "single"),
954 (eval_tests, "eval")): 959 (eval_tests, "eval")):
955 print(kind+"_results = [") 960 print(kind+"_results = [")
956 for s in statements: 961 for s in statements:
957 print(repr(to_tuple(compile(s, "?", kind, 0x400)))+",") 962 print(repr(to_tuple(compile(s, "?", kind, 0x400)))+",")
958 print("]") 963 print("]")
959 print("main()") 964 print("main()")
960 raise SystemExit 965 raise SystemExit
961 test_main() 966 unittest.main()
962 967
963 #### EVERYTHING BELOW IS GENERATED ##### 968 #### EVERYTHING BELOW IS GENERATED #####
964 exec_results = [ 969 exec_results = [
965 ('Module', [('Expr', (1, 0), ('NameConstant', (1, 0), None))]), 970 ('Module', [('Expr', (1, 0), ('NameConstant', (1, 0), None))]),
966 ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, [], None, None, [], []), [('Pass', (1, 9))], [], None)]), 971 ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, [], [], None, [ ]), [('Pass', (1, 9))], [], None)]),
967 ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', 'a', None)], Non e, None, [], None, None, [], []), [('Pass', (1, 10))], [], None)]), 972 ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', (1, 6), 'a', Non e)], None, [], [], None, []), [('Pass', (1, 10))], [], None)]),
968 ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', 'a', None)], Non e, None, [], None, None, [('Num', (1, 8), 0)], []), [('Pass', (1, 12))], [], Non e)]), 973 ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', (1, 6), 'a', Non e)], None, [], [], None, [('Num', (1, 8), 0)]), [('Pass', (1, 12))], [], None)]) ,
969 ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], 'args', None, [], Non e, None, [], []), [('Pass', (1, 14))], [], None)]), 974 ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], ('arg', (1, 7), 'args ', None), [], [], None, []), [('Pass', (1, 14))], [], None)]),
970 ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, [], 'kwar gs', None, [], []), [('Pass', (1, 17))], [], None)]), 975 ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, [], [], ('arg', (1, 8), 'kwargs', None), []), [('Pass', (1, 17))], [], None)]),
971 ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', 'a', None), ('ar g', 'b', None), ('arg', 'c', None), ('arg', 'd', None), ('arg', 'e', None)], 'ar gs', None, [], 'kwargs', None, [('Num', (1, 11), 1), ('NameConstant', (1, 16), N one), ('List', (1, 24), [], ('Load',)), ('Dict', (1, 30), [], [])], []), [('Pass ', (1, 52))], [], None)]), 976 ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', (1, 6), 'a', Non e), ('arg', (1, 9), 'b', None), ('arg', (1, 14), 'c', None), ('arg', (1, 22), 'd ', None), ('arg', (1, 28), 'e', None)], ('arg', (1, 35), 'args', None), [], [], ('arg', (1, 43), 'kwargs', None), [('Num', (1, 11), 1), ('NameConstant', (1, 16) , None), ('List', (1, 24), [], ('Load',)), ('Dict', (1, 30), [], [])]), [('Pass' , (1, 52))], [], None)]),
972 ('Module', [('ClassDef', (1, 0), 'C', [], [], None, None, [('Pass', (1, 8))], [] )]), 977 ('Module', [('ClassDef', (1, 0), 'C', [], [], None, None, [('Pass', (1, 8))], [] )]),
973 ('Module', [('ClassDef', (1, 0), 'C', [('Name', (1, 8), 'object', ('Load',))], [ ], None, None, [('Pass', (1, 17))], [])]), 978 ('Module', [('ClassDef', (1, 0), 'C', [('Name', (1, 8), 'object', ('Load',))], [ ], None, None, [('Pass', (1, 17))], [])]),
974 ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, [], None, None, [], []), [('Return', (1, 8), ('Num', (1, 15), 1))], [], None)]), 979 ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, [], [], None, [ ]), [('Return', (1, 8), ('Num', (1, 15), 1))], [], None)]),
975 ('Module', [('Delete', (1, 0), [('Name', (1, 4), 'v', ('Del',))])]), 980 ('Module', [('Delete', (1, 0), [('Name', (1, 4), 'v', ('Del',))])]),
976 ('Module', [('Assign', (1, 0), [('Name', (1, 0), 'v', ('Store',))], ('Num', (1, 4), 1))]), 981 ('Module', [('Assign', (1, 0), [('Name', (1, 0), 'v', ('Store',))], ('Num', (1, 4), 1))]),
977 ('Module', [('AugAssign', (1, 0), ('Name', (1, 0), 'v', ('Store',)), ('Add',), ( 'Num', (1, 5), 1))]), 982 ('Module', [('AugAssign', (1, 0), ('Name', (1, 0), 'v', ('Store',)), ('Add',), ( 'Num', (1, 5), 1))]),
978 ('Module', [('For', (1, 0), ('Name', (1, 4), 'v', ('Store',)), ('Name', (1, 9), 'v', ('Load',)), [('Pass', (1, 11))], [])]), 983 ('Module', [('For', (1, 0), ('Name', (1, 4), 'v', ('Store',)), ('Name', (1, 9), 'v', ('Load',)), [('Pass', (1, 11))], [])]),
979 ('Module', [('While', (1, 0), ('Name', (1, 6), 'v', ('Load',)), [('Pass', (1, 8) )], [])]), 984 ('Module', [('While', (1, 0), ('Name', (1, 6), 'v', ('Load',)), [('Pass', (1, 8) )], [])]),
980 ('Module', [('If', (1, 0), ('Name', (1, 3), 'v', ('Load',)), [('Pass', (1, 5))], [])]), 985 ('Module', [('If', (1, 0), ('Name', (1, 3), 'v', ('Load',)), [('Pass', (1, 5))], [])]),
981 ('Module', [('With', (1, 0), [('withitem', ('Name', (1, 5), 'x', ('Load',)), ('N ame', (1, 10), 'y', ('Store',)))], [('Pass', (1, 13))])]), 986 ('Module', [('With', (1, 0), [('withitem', ('Name', (1, 5), 'x', ('Load',)), ('N ame', (1, 10), 'y', ('Store',)))], [('Pass', (1, 13))])]),
982 ('Module', [('With', (1, 0), [('withitem', ('Name', (1, 5), 'x', ('Load',)), ('N ame', (1, 10), 'y', ('Store',))), ('withitem', ('Name', (1, 13), 'z', ('Load',)) , ('Name', (1, 18), 'q', ('Store',)))], [('Pass', (1, 21))])]), 987 ('Module', [('With', (1, 0), [('withitem', ('Name', (1, 5), 'x', ('Load',)), ('N ame', (1, 10), 'y', ('Store',))), ('withitem', ('Name', (1, 13), 'z', ('Load',)) , ('Name', (1, 18), 'q', ('Store',)))], [('Pass', (1, 21))])]),
983 ('Module', [('Raise', (1, 0), ('Call', (1, 6), ('Name', (1, 6), 'Exception', ('L oad',)), [('Str', (1, 16), 'string')], [], None, None), None)]), 988 ('Module', [('Raise', (1, 0), ('Call', (1, 15), ('Name', (1, 6), 'Exception', (' Load',)), [('Str', (1, 16), 'string')], [], None, None), None)]),
984 ('Module', [('Try', (1, 0), [('Pass', (2, 2))], [('ExceptHandler', (3, 0), ('Nam e', (3, 7), 'Exception', ('Load',)), None, [('Pass', (4, 2))])], [], [])]), 989 ('Module', [('Try', (1, 0), [('Pass', (2, 2))], [('ExceptHandler', (3, 0), ('Nam e', (3, 7), 'Exception', ('Load',)), None, [('Pass', (4, 2))])], [], [])]),
985 ('Module', [('Try', (1, 0), [('Pass', (2, 2))], [], [], [('Pass', (4, 2))])]), 990 ('Module', [('Try', (1, 0), [('Pass', (2, 2))], [], [], [('Pass', (4, 2))])]),
986 ('Module', [('Assert', (1, 0), ('Name', (1, 7), 'v', ('Load',)), None)]), 991 ('Module', [('Assert', (1, 0), ('Name', (1, 7), 'v', ('Load',)), None)]),
987 ('Module', [('Import', (1, 0), [('alias', 'sys', None)])]), 992 ('Module', [('Import', (1, 0), [('alias', 'sys', None)])]),
988 ('Module', [('ImportFrom', (1, 0), 'sys', [('alias', 'v', None)], 0)]), 993 ('Module', [('ImportFrom', (1, 0), 'sys', [('alias', 'v', None)], 0)]),
989 ('Module', [('Global', (1, 0), ['v'])]), 994 ('Module', [('Global', (1, 0), ['v'])]),
990 ('Module', [('Expr', (1, 0), ('Num', (1, 0), 1))]), 995 ('Module', [('Expr', (1, 0), ('Num', (1, 0), 1))]),
991 ('Module', [('Pass', (1, 0))]), 996 ('Module', [('Pass', (1, 0))]),
992 ('Module', [('Break', (1, 0))]), 997 ('Module', [('Break', (1, 0))]),
993 ('Module', [('Continue', (1, 0))]), 998 ('Module', [('Continue', (1, 0))]),
994 ('Module', [('For', (1, 0), ('Tuple', (1, 4), [('Name', (1, 4), 'a', ('Store',)) , ('Name', (1, 6), 'b', ('Store',))], ('Store',)), ('Name', (1, 11), 'c', ('Load ',)), [('Pass', (1, 14))], [])]), 999 ('Module', [('For', (1, 0), ('Tuple', (1, 4), [('Name', (1, 4), 'a', ('Store',)) , ('Name', (1, 6), 'b', ('Store',))], ('Store',)), ('Name', (1, 11), 'c', ('Load ',)), [('Pass', (1, 14))], [])]),
995 ('Module', [('Expr', (1, 0), ('ListComp', (1, 1), ('Tuple', (1, 2), [('Name', (1 , 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('compreh ension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13 ), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])]))]), 1000 ('Module', [('Expr', (1, 0), ('ListComp', (1, 1), ('Tuple', (1, 2), [('Name', (1 , 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('compreh ension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13 ), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])]))]),
996 ('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name' , (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('com prehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1 , 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])])) ]), 1001 ('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name' , (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('com prehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1 , 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])])) ]),
997 ('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name' , (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('com prehension', ('Tuple', (1, 12), [('Name', (1, 12), 'a', ('Store',)), ('Name', (1 , 14), 'b', ('Store',))], ('Store',)), ('Name', (1, 20), 'c', ('Load',)), [])])) ]), 1002 ('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name' , (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('com prehension', ('Tuple', (1, 12), [('Name', (1, 12), 'a', ('Store',)), ('Name', (1 , 14), 'b', ('Store',))], ('Store',)), ('Name', (1, 20), 'c', ('Load',)), [])])) ]),
998 ('Module', [('Expr', (1, 0), ('GeneratorExp', (2, 4), ('Tuple', (3, 4), [('Name' , (3, 4), 'Aa', ('Load',)), ('Name', (5, 7), 'Bb', ('Load',))], ('Load',)), [('c omprehension', ('Tuple', (8, 4), [('Name', (8, 4), 'Aa', ('Store',)), ('Name', ( 10, 4), 'Bb', ('Store',))], ('Store',)), ('Name', (10, 10), 'Cc', ('Load',)), [] )]))]), 1003 ('Module', [('Expr', (1, 0), ('GeneratorExp', (2, 4), ('Tuple', (3, 4), [('Name' , (3, 4), 'Aa', ('Load',)), ('Name', (5, 7), 'Bb', ('Load',))], ('Load',)), [('c omprehension', ('Tuple', (8, 4), [('Name', (8, 4), 'Aa', ('Store',)), ('Name', ( 10, 4), 'Bb', ('Store',))], ('Store',)), ('Name', (10, 10), 'Cc', ('Load',)), [] )]))]),
999 ('Module', [('Expr', (1, 0), ('DictComp', (1, 1), ('Name', (1, 1), 'a', ('Load', )), ('Name', (1, 5), 'b', ('Load',)), [('comprehension', ('Name', (1, 11), 'w', ('Store',)), ('Name', (1, 16), 'x', ('Load',)), []), ('comprehension', ('Name', (1, 22), 'm', ('Store',)), ('Name', (1, 27), 'p', ('Load',)), [('Name', (1, 32), 'g', ('Load',))])]))]), 1004 ('Module', [('Expr', (1, 0), ('DictComp', (1, 1), ('Name', (1, 1), 'a', ('Load', )), ('Name', (1, 5), 'b', ('Load',)), [('comprehension', ('Name', (1, 11), 'w', ('Store',)), ('Name', (1, 16), 'x', ('Load',)), []), ('comprehension', ('Name', (1, 22), 'm', ('Store',)), ('Name', (1, 27), 'p', ('Load',)), [('Name', (1, 32), 'g', ('Load',))])]))]),
1000 ('Module', [('Expr', (1, 0), ('DictComp', (1, 1), ('Name', (1, 1), 'a', ('Load', )), ('Name', (1, 5), 'b', ('Load',)), [('comprehension', ('Tuple', (1, 11), [('N ame', (1, 11), 'v', ('Store',)), ('Name', (1, 13), 'w', ('Store',))], ('Store',) ), ('Name', (1, 18), 'x', ('Load',)), [])]))]), 1005 ('Module', [('Expr', (1, 0), ('DictComp', (1, 1), ('Name', (1, 1), 'a', ('Load', )), ('Name', (1, 5), 'b', ('Load',)), [('comprehension', ('Tuple', (1, 11), [('N ame', (1, 11), 'v', ('Store',)), ('Name', (1, 13), 'w', ('Store',))], ('Store',) ), ('Name', (1, 18), 'x', ('Load',)), [])]))]),
1001 ('Module', [('Expr', (1, 0), ('SetComp', (1, 1), ('Name', (1, 1), 'r', ('Load',) ), [('comprehension', ('Name', (1, 7), 'l', ('Store',)), ('Name', (1, 12), 'x', ('Load',)), [('Name', (1, 17), 'g', ('Load',))])]))]), 1006 ('Module', [('Expr', (1, 0), ('SetComp', (1, 1), ('Name', (1, 1), 'r', ('Load',) ), [('comprehension', ('Name', (1, 7), 'l', ('Store',)), ('Name', (1, 12), 'x', ('Load',)), [('Name', (1, 17), 'g', ('Load',))])]))]),
1002 ('Module', [('Expr', (1, 0), ('SetComp', (1, 1), ('Name', (1, 1), 'r', ('Load',) ), [('comprehension', ('Tuple', (1, 7), [('Name', (1, 7), 'l', ('Store',)), ('Na me', (1, 9), 'm', ('Store',))], ('Store',)), ('Name', (1, 14), 'x', ('Load',)), [])]))]), 1007 ('Module', [('Expr', (1, 0), ('SetComp', (1, 1), ('Name', (1, 1), 'r', ('Load',) ), [('comprehension', ('Tuple', (1, 7), [('Name', (1, 7), 'l', ('Store',)), ('Na me', (1, 9), 'm', ('Store',))], ('Store',)), ('Name', (1, 14), 'x', ('Load',)), [])]))]),
1003 ] 1008 ]
1004 single_results = [ 1009 single_results = [
1005 ('Interactive', [('Expr', (1, 0), ('BinOp', (1, 0), ('Num', (1, 0), 1), ('Add',) , ('Num', (1, 2), 2)))]), 1010 ('Interactive', [('Expr', (1, 0), ('BinOp', (1, 0), ('Num', (1, 0), 1), ('Add',) , ('Num', (1, 2), 2)))]),
1006 ] 1011 ]
1007 eval_results = [ 1012 eval_results = [
1008 ('Expression', ('NameConstant', (1, 0), None)), 1013 ('Expression', ('NameConstant', (1, 0), None)),
1009 ('Expression', ('BoolOp', (1, 0), ('And',), [('Name', (1, 0), 'a', ('Load',)), ( 'Name', (1, 6), 'b', ('Load',))])), 1014 ('Expression', ('BoolOp', (1, 0), ('And',), [('Name', (1, 0), 'a', ('Load',)), ( 'Name', (1, 6), 'b', ('Load',))])),
1010 ('Expression', ('BinOp', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Add',), ('N ame', (1, 4), 'b', ('Load',)))), 1015 ('Expression', ('BinOp', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Add',), ('N ame', (1, 4), 'b', ('Load',)))),
1011 ('Expression', ('UnaryOp', (1, 0), ('Not',), ('Name', (1, 4), 'v', ('Load',)))), 1016 ('Expression', ('UnaryOp', (1, 0), ('Not',), ('Name', (1, 4), 'v', ('Load',)))),
1012 ('Expression', ('Lambda', (1, 0), ('arguments', [], None, None, [], None, None, [], []), ('NameConstant', (1, 7), None))), 1017 ('Expression', ('Lambda', (1, 0), ('arguments', [], None, [], [], None, []), ('N ameConstant', (1, 7), None))),
1013 ('Expression', ('Dict', (1, 0), [('Num', (1, 2), 1)], [('Num', (1, 4), 2)])), 1018 ('Expression', ('Dict', (1, 0), [('Num', (1, 2), 1)], [('Num', (1, 4), 2)])),
1014 ('Expression', ('Dict', (1, 0), [], [])), 1019 ('Expression', ('Dict', (1, 0), [], [])),
1015 ('Expression', ('Set', (1, 0), [('NameConstant', (1, 1), None)])), 1020 ('Expression', ('Set', (1, 0), [('NameConstant', (1, 1), None)])),
1016 ('Expression', ('Dict', (1, 0), [('Num', (2, 6), 1)], [('Num', (4, 10), 2)])), 1021 ('Expression', ('Dict', (1, 0), [('Num', (2, 6), 1)], [('Num', (4, 10), 2)])),
1017 ('Expression', ('ListComp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('compreh ension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [ ('Name', (1, 17), 'd', ('Load',))])])), 1022 ('Expression', ('ListComp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('compreh ension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [ ('Name', (1, 17), 'd', ('Load',))])])),
1018 ('Expression', ('GeneratorExp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('com prehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',) ), [('Name', (1, 17), 'd', ('Load',))])])), 1023 ('Expression', ('GeneratorExp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('com prehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',) ), [('Name', (1, 17), 'd', ('Load',))])])),
1019 ('Expression', ('Compare', (1, 0), ('Num', (1, 0), 1), [('Lt',), ('Lt',)], [('Nu m', (1, 4), 2), ('Num', (1, 8), 3)])), 1024 ('Expression', ('Compare', (1, 0), ('Num', (1, 0), 1), [('Lt',), ('Lt',)], [('Nu m', (1, 4), 2), ('Num', (1, 8), 3)])),
1020 ('Expression', ('Call', (1, 0), ('Name', (1, 0), 'f', ('Load',)), [('Num', (1, 2 ), 1), ('Num', (1, 4), 2)], [('keyword', 'c', ('Num', (1, 8), 3))], ('Name', (1, 11), 'd', ('Load',)), ('Name', (1, 15), 'e', ('Load',)))), 1025 ('Expression', ('Call', (1, 1), ('Name', (1, 0), 'f', ('Load',)), [('Num', (1, 2 ), 1), ('Num', (1, 4), 2)], [('keyword', 'c', ('Num', (1, 8), 3))], ('Name', (1, 11), 'd', ('Load',)), ('Name', (1, 15), 'e', ('Load',)))),
1021 ('Expression', ('Num', (1, 0), 10)), 1026 ('Expression', ('Num', (1, 0), 10)),
1022 ('Expression', ('Str', (1, 0), 'string')), 1027 ('Expression', ('Str', (1, 0), 'string')),
1023 ('Expression', ('Attribute', (1, 0), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Lo ad',))), 1028 ('Expression', ('Attribute', (1, 2), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Lo ad',))),
1024 ('Expression', ('Subscript', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None), ('Lo ad',))), 1029 ('Expression', ('Subscript', (1, 2), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None), ('Lo ad',))),
1025 ('Expression', ('Name', (1, 0), 'v', ('Load',))), 1030 ('Expression', ('Name', (1, 0), 'v', ('Load',))),
1026 ('Expression', ('List', (1, 0), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))), 1031 ('Expression', ('List', (1, 0), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))),
1027 ('Expression', ('List', (1, 0), [], ('Load',))), 1032 ('Expression', ('List', (1, 0), [], ('Load',))),
1028 ('Expression', ('Tuple', (1, 0), [('Num', (1, 0), 1), ('Num', (1, 2), 2), ('Num' , (1, 4), 3)], ('Load',))), 1033 ('Expression', ('Tuple', (1, 0), [('Num', (1, 0), 1), ('Num', (1, 2), 2), ('Num' , (1, 4), 3)], ('Load',))),
1029 ('Expression', ('Tuple', (1, 1), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num' , (1, 5), 3)], ('Load',))), 1034 ('Expression', ('Tuple', (1, 1), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num' , (1, 5), 3)], ('Load',))),
1030 ('Expression', ('Tuple', (1, 0), [], ('Load',))), 1035 ('Expression', ('Tuple', (1, 0), [], ('Load',))),
1031 ('Expression', ('Call', (1, 0), ('Attribute', (1, 0), ('Attribute', (1, 0), ('At tribute', (1, 0), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',)), 'c', ('Load ',)), 'd', ('Load',)), [('Subscript', (1, 8), ('Attribute', (1, 8), ('Name', (1, 8), 'a', ('Load',)), 'b', ('Load',)), ('Slice', ('Num', (1, 12), 1), ('Num', (1 , 14), 2), None), ('Load',))], [], None, None)), 1036 ('Expression', ('Call', (1, 7), ('Attribute', (1, 6), ('Attribute', (1, 4), ('At tribute', (1, 2), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',)), 'c', ('Load ',)), 'd', ('Load',)), [('Subscript', (1, 12), ('Attribute', (1, 10), ('Name', ( 1, 8), 'a', ('Load',)), 'b', ('Load',)), ('Slice', ('Num', (1, 12), 1), ('Num', (1, 14), 2), None), ('Load',))], [], None, None)),
1032 ] 1037 ]
1033 main() 1038 main()
LEFTRIGHT

This is Rietveld 894c83f36cb7+