| 1 |
import sys, itertools, unittest |
| 2 |
from test import test_support |
| 3 |
import ast |
| 4 |
|
| 5 |
def to_tuple(t): |
| 6 |
if t is None or isinstance(t, (basestring, int, long, complex)): |
| 7 |
return t |
| 8 |
elif isinstance(t, list): |
| 9 |
return [to_tuple(e) for e in t] |
| 10 |
result = [t.__class__.__name__] |
| 11 |
if hasattr(t, 'lineno') and hasattr(t, 'col_offset'): |
| 12 |
result.append((t.lineno, t.col_offset)) |
| 13 |
if t._fields is None: |
| 14 |
return tuple(result) |
| 15 |
for f in t._fields: |
| 16 |
result.append(to_tuple(getattr(t, f))) |
| 17 |
return tuple(result) |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
exec_tests = [ |
| 23 |
|
| 24 |
"None", |
| 25 |
|
| 26 |
"def f(): pass", |
| 27 |
|
| 28 |
"def f(a): pass", |
| 29 |
|
| 30 |
"def f(a=0): pass", |
| 31 |
|
| 32 |
"def f(*args): pass", |
| 33 |
|
| 34 |
"def f(**kwargs): pass", |
| 35 |
|
| 36 |
"def f(a, b=1, c=None, d=[], e={}, *args, **kwargs): pass", |
| 37 |
|
| 38 |
"class C:pass", |
| 39 |
|
| 40 |
"class C(object): pass", |
| 41 |
|
| 42 |
"def f():return 1", |
| 43 |
|
| 44 |
"del v", |
| 45 |
|
| 46 |
"v = 1", |
| 47 |
|
| 48 |
"v += 1", |
| 49 |
|
| 50 |
"print >>f, 1, ", |
| 51 |
|
| 52 |
"for v in v:pass", |
| 53 |
|
| 54 |
"while v:pass", |
| 55 |
|
| 56 |
"if v:pass", |
| 57 |
|
| 58 |
"raise Exception, 'string'", |
| 59 |
|
| 60 |
"try:\n pass\nexcept Exception:\n pass", |
| 61 |
|
| 62 |
"try:\n pass\nfinally:\n pass", |
| 63 |
|
| 64 |
"assert v", |
| 65 |
|
| 66 |
"import sys", |
| 67 |
|
| 68 |
"from sys import v", |
| 69 |
|
| 70 |
"exec 'v'", |
| 71 |
|
| 72 |
"global v", |
| 73 |
|
| 74 |
"1", |
| 75 |
|
| 76 |
"pass", |
| 77 |
|
| 78 |
"break", |
| 79 |
|
| 80 |
"continue", |
| 81 |
|
| 82 |
"for a,b in c: pass", |
| 83 |
"[(a,b) for a,b in c]", |
| 84 |
"((a,b) for a,b in c)", |
| 85 |
"((a,b) for (a,b) in c)", |
| 86 |
|
| 87 |
"""( |
| 88 |
( |
| 89 |
Aa |
| 90 |
, |
| 91 |
Bb |
| 92 |
) |
| 93 |
for |
| 94 |
Aa |
| 95 |
, |
| 96 |
Bb in Cc |
| 97 |
)""", |
| 98 |
|
| 99 |
"{a : b for w in x for m in p if g}", |
| 100 |
|
| 101 |
"{a : b for v,w in x}", |
| 102 |
|
| 103 |
"{r for l in x if g}", |
| 104 |
|
| 105 |
"{r for l,m in x}", |
| 106 |
|
| 107 |
"@deco1\n@deco2()\n@deco3(1)\ndef f(): pass", |
| 108 |
|
| 109 |
"@deco1\n@deco2()\n@deco3(1)\nclass C: pass", |
| 110 |
|
| 111 |
"@deco(a for a in b)\ndef f(): pass", |
| 112 |
] |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
single_tests = [ |
| 118 |
"1+2" |
| 119 |
] |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
eval_tests = [ |
| 124 |
|
| 125 |
"None", |
| 126 |
|
| 127 |
"a and b", |
| 128 |
|
| 129 |
"a + b", |
| 130 |
|
| 131 |
"not v", |
| 132 |
|
| 133 |
"lambda:None", |
| 134 |
|
| 135 |
"{ 1:2 }", |
| 136 |
|
| 137 |
"{}", |
| 138 |
|
| 139 |
"{None,}", |
| 140 |
|
| 141 |
"""{ |
| 142 |
1 |
| 143 |
: |
| 144 |
2 |
| 145 |
}""", |
| 146 |
|
| 147 |
"[a for b in c if d]", |
| 148 |
|
| 149 |
"(a for b in c if d)", |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
"1 < 2 < 3", |
| 154 |
|
| 155 |
"f(1,2,c=3,*d,**e)", |
| 156 |
|
| 157 |
"`v`", |
| 158 |
|
| 159 |
"10L", |
| 160 |
|
| 161 |
"'string'", |
| 162 |
|
| 163 |
"a.b", |
| 164 |
|
| 165 |
"a[b:c]", |
| 166 |
|
| 167 |
"v", |
| 168 |
|
| 169 |
"[1,2,3]", |
| 170 |
|
| 171 |
"[]", |
| 172 |
|
| 173 |
"1,2,3", |
| 174 |
|
| 175 |
"(1,2,3)", |
| 176 |
|
| 177 |
"()", |
| 178 |
|
| 179 |
"a.b.c.d(a.b[1:2])", |
| 180 |
|
| 181 |
] |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
class AST_Tests(unittest.TestCase): |
| 187 |
|
| 188 |
def _assertTrueorder(self, ast_node, parent_pos): |
| 189 |
if not isinstance(ast_node, ast.AST) or ast_node._fields is None: |
| 190 |
return |
| 191 |
if isinstance(ast_node, (ast.expr, ast.stmt, ast.excepthandler)): |
| 192 |
node_pos = (ast_node.lineno, ast_node.col_offset) |
| 193 |
self.assertTrue(node_pos >= parent_pos) |
| 194 |
parent_pos = (ast_node.lineno, ast_node.col_offset) |
| 195 |
for name in ast_node._fields: |
| 196 |
value = getattr(ast_node, name) |
| 197 |
if isinstance(value, list): |
| 198 |
for child in value: |
| 199 |
self._assertTrueorder(child, parent_pos) |
| 200 |
elif value is not None: |
| 201 |
self._assertTrueorder(value, parent_pos) |
| 202 |
|
| 203 |
def test_AST_objects(self): |
| 204 |
x = ast.AST() |
| 205 |
self.assertEqual(x._fields, ()) |
| 206 |
|
| 207 |
with self.assertRaises(AttributeError): |
| 208 |
x.vararg |
| 209 |
|
| 210 |
with self.assertRaises(AttributeError): |
| 211 |
x.foobar = 21 |
| 212 |
|
| 213 |
with self.assertRaises(AttributeError): |
| 214 |
ast.AST(lineno=2) |
| 215 |
|
| 216 |
with self.assertRaises(TypeError): |
| 217 |
|
| 218 |
ast.AST(2) |
| 219 |
|
| 220 |
def test_snippets(self): |
| 221 |
for input, output, kind in ((exec_tests, exec_results, "exec"), |
| 222 |
(single_tests, single_results, "single"), |
| 223 |
(eval_tests, eval_results, "eval")): |
| 224 |
for i, o in itertools.izip(input, output): |
| 225 |
ast_tree = compile(i, "?", kind, ast.PyCF_ONLY_AST) |
| 226 |
self.assertEqual(to_tuple(ast_tree), o) |
| 227 |
self._assertTrueorder(ast_tree, (0, 0)) |
| 228 |
|
| 229 |
def test_slice(self): |
| 230 |
slc = ast.parse("x[::]").body[0].value.slice |
| 231 |
self.assertIsNone(slc.upper) |
| 232 |
self.assertIsNone(slc.lower) |
| 233 |
self.assertIsInstance(slc.step, ast.Name) |
| 234 |
self.assertEqual(slc.step.id, "None") |
| 235 |
|
| 236 |
def test_from_import(self): |
| 237 |
im = ast.parse("from . import y").body[0] |
| 238 |
self.assertIsNone(im.module) |
| 239 |
|
| 240 |
def test_non_interned_future_from_ast(self): |
| 241 |
mod = ast.parse("from __future__ import division") |
| 242 |
self.assertIsInstance(mod.body[0], ast.ImportFrom) |
| 243 |
mod.body[0].module = " __future__ ".strip() |
| 244 |
compile(mod, "<test>", "exec") |
| 245 |
|
| 246 |
def test_base_classes(self): |
| 247 |
self.assertTrue(issubclass(ast.For, ast.stmt)) |
| 248 |
self.assertTrue(issubclass(ast.Name, ast.expr)) |
| 249 |
self.assertTrue(issubclass(ast.stmt, ast.AST)) |
| 250 |
self.assertTrue(issubclass(ast.expr, ast.AST)) |
| 251 |
self.assertTrue(issubclass(ast.comprehension, ast.AST)) |
| 252 |
self.assertTrue(issubclass(ast.Gt, ast.AST)) |
| 253 |
|
| 254 |
def test_field_attr_existence(self): |
| 255 |
for name, item in ast.__dict__.iteritems(): |
| 256 |
if isinstance(item, type) and name != 'AST' and name[0].isupper(): |
| 257 |
x = item() |
| 258 |
if isinstance(x, ast.AST): |
| 259 |
self.assertEqual(type(x._fields), tuple) |
| 260 |
|
| 261 |
def test_arguments(self): |
| 262 |
x = ast.arguments() |
| 263 |
self.assertEqual(x._fields, ('args', 'vararg', 'kwarg', 'defaults')) |
| 264 |
|
| 265 |
with self.assertRaises(AttributeError): |
| 266 |
x.vararg |
| 267 |
|
| 268 |
x = ast.arguments(1, 2, 3, 4) |
| 269 |
self.assertEqual(x.vararg, 2) |
| 270 |
|
| 271 |
def test_field_attr_writable(self): |
| 272 |
x = ast.Num() |
| 273 |
|
| 274 |
x._fields = 666 |
| 275 |
self.assertEqual(x._fields, 666) |
| 276 |
|
| 277 |
def test_classattrs(self): |
| 278 |
x = ast.Num() |
| 279 |
self.assertEqual(x._fields, ('n',)) |
| 280 |
|
| 281 |
with self.assertRaises(AttributeError): |
| 282 |
x.n |
| 283 |
|
| 284 |
x = ast.Num(42) |
| 285 |
self.assertEqual(x.n, 42) |
| 286 |
|
| 287 |
with self.assertRaises(AttributeError): |
| 288 |
x.lineno |
| 289 |
|
| 290 |
with self.assertRaises(AttributeError): |
| 291 |
x.foobar |
| 292 |
|
| 293 |
x = ast.Num(lineno=2) |
| 294 |
self.assertEqual(x.lineno, 2) |
| 295 |
|
| 296 |
x = ast.Num(42, lineno=0) |
| 297 |
self.assertEqual(x.lineno, 0) |
| 298 |
self.assertEqual(x._fields, ('n',)) |
| 299 |
self.assertEqual(x.n, 42) |
| 300 |
|
| 301 |
self.assertRaises(TypeError, ast.Num, 1, 2) |
| 302 |
self.assertRaises(TypeError, ast.Num, 1, 2, lineno=0) |
| 303 |
|
| 304 |
def test_module(self): |
| 305 |
body = [ast.Num(42)] |
| 306 |
x = ast.Module(body) |
| 307 |
self.assertEqual(x.body, body) |
| 308 |
|
| 309 |
def test_nodeclasses(self): |
| 310 |
|
| 311 |
x = ast.BinOp() |
| 312 |
self.assertEqual(x._fields, ('left', 'op', 'right')) |
| 313 |
|
| 314 |
|
| 315 |
x.foobarbaz = 5 |
| 316 |
self.assertEqual(x.foobarbaz, 5) |
| 317 |
|
| 318 |
n1 = ast.Num(1) |
| 319 |
n3 = ast.Num(3) |
| 320 |
addop = ast.Add() |
| 321 |
x = ast.BinOp(n1, addop, n3) |
| 322 |
self.assertEqual(x.left, n1) |
| 323 |
self.assertEqual(x.op, addop) |
| 324 |
self.assertEqual(x.right, n3) |
| 325 |
|
| 326 |
x = ast.BinOp(1, 2, 3) |
| 327 |
self.assertEqual(x.left, 1) |
| 328 |
self.assertEqual(x.op, 2) |
| 329 |
self.assertEqual(x.right, 3) |
| 330 |
|
| 331 |
x = ast.BinOp(1, 2, 3, lineno=0) |
| 332 |
self.assertEqual(x.left, 1) |
| 333 |
self.assertEqual(x.op, 2) |
| 334 |
self.assertEqual(x.right, 3) |
| 335 |
self.assertEqual(x.lineno, 0) |
| 336 |
|
| 337 |
|
| 338 |
self.assertRaises(TypeError, ast.BinOp, 1, 2) |
| 339 |
|
| 340 |
self.assertRaises(TypeError, ast.BinOp, 1, 2, 3, 4) |
| 341 |
|
| 342 |
self.assertRaises(TypeError, ast.BinOp, 1, 2, lineno=0) |
| 343 |
|
| 344 |
self.assertRaises(TypeError, ast.BinOp, 1, 2, 3, 4, lineno=0) |
| 345 |
|
| 346 |
|
| 347 |
x = ast.BinOp(left=1, op=2, right=3, lineno=0) |
| 348 |
self.assertEqual(x.left, 1) |
| 349 |
self.assertEqual(x.op, 2) |
| 350 |
self.assertEqual(x.right, 3) |
| 351 |
self.assertEqual(x.lineno, 0) |
| 352 |
|
| 353 |
|
| 354 |
x = ast.BinOp(1, 2, 3, foobarbaz=42) |
| 355 |
self.assertEqual(x.foobarbaz, 42) |
| 356 |
|
| 357 |
def test_no_fields(self): |
| 358 |
|
| 359 |
x = ast.Sub() |
| 360 |
self.assertEqual(x._fields, ()) |
| 361 |
|
| 362 |
def test_pickling(self): |
| 363 |
import pickle |
| 364 |
mods = [pickle] |
| 365 |
try: |
| 366 |
import cPickle |
| 367 |
mods.append(cPickle) |
| 368 |
except ImportError: |
| 369 |
pass |
| 370 |
protocols = [0, 1, 2] |
| 371 |
for mod in mods: |
| 372 |
for protocol in protocols: |
| 373 |
for ast in (compile(i, "?", "exec", 0x400) for i in exec_tests): |
| 374 |
ast2 = mod.loads(mod.dumps(ast, protocol)) |
| 375 |
self.assertEqual(to_tuple(ast2), to_tuple(ast)) |
| 376 |
|
| 377 |
def test_invalid_identitifer(self): |
| 378 |
m = ast.Module([ast.Expr(ast.Name(u"x", ast.Load()))]) |
| 379 |
ast.fix_missing_locations(m) |
| 380 |
with self.assertRaises(TypeError) as cm: |
| 381 |
compile(m, "<test>", "exec") |
| 382 |
self.assertIn("identifier must be of type str", str(cm.exception)) |
| 383 |
|
| 384 |
def test_invalid_string(self): |
| 385 |
m = ast.Module([ast.Expr(ast.Str(43))]) |
| 386 |
ast.fix_missing_locations(m) |
| 387 |
with self.assertRaises(TypeError) as cm: |
| 388 |
compile(m, "<test>", "exec") |
| 389 |
self.assertIn("string must be of type str or uni", str(cm.exception)) |
| 390 |
|
| 391 |
|
| 392 |
class ASTHelpers_Test(unittest.TestCase): |
| 393 |
|
| 394 |
def test_parse(self): |
| 395 |
a = ast.parse('foo(1 + 1)') |
| 396 |
b = compile('foo(1 + 1)', '<unknown>', 'exec', ast.PyCF_ONLY_AST) |
| 397 |
self.assertEqual(ast.dump(a), ast.dump(b)) |
| 398 |
|
| 399 |
def test_dump(self): |
| 400 |
node = ast.parse('spam(eggs, "and cheese")') |
| 401 |
self.assertEqual(ast.dump(node), |
| 402 |
"Module(body=[Expr(value=Call(func=Name(id='spam', ctx=Load()), " |
| 403 |
"args=[Name(id='eggs', ctx=Load()), Str(s='and cheese')], " |
| 404 |
"keywords=[], starargs=None, kwargs=None))])" |
| 405 |
) |
| 406 |
self.assertEqual(ast.dump(node, annotate_fields=False), |
| 407 |
"Module([Expr(Call(Name('spam', Load()), [Name('eggs', Load()), " |
| 408 |
"Str('and cheese')], [], None, None))])" |
| 409 |
) |
| 410 |
self.assertEqual(ast.dump(node, include_attributes=True), |
| 411 |
"Module(body=[Expr(value=Call(func=Name(id='spam', ctx=Load(), " |
| 412 |
"lineno=1, col_offset=0), args=[Name(id='eggs', ctx=Load(), " |
| 413 |
"lineno=1, col_offset=5), Str(s='and cheese', lineno=1, " |
| 414 |
"col_offset=11)], keywords=[], starargs=None, kwargs=None, " |
| 415 |
"lineno=1, col_offset=0), lineno=1, col_offset=0)])" |
| 416 |
) |
| 417 |
|
| 418 |
def test_copy_location(self): |
| 419 |
src = ast.parse('1 + 1', mode='eval') |
| 420 |
src.body.right = ast.copy_location(ast.Num(2), src.body.right) |
| 421 |
self.assertEqual(ast.dump(src, include_attributes=True), |
| 422 |
'Expression(body=BinOp(left=Num(n=1, lineno=1, col_offset=0), ' |
| 423 |
'op=Add(), right=Num(n=2, lineno=1, col_offset=4), lineno=1, ' |
| 424 |
'col_offset=0))' |
| 425 |
) |
| 426 |
|
| 427 |
def test_fix_missing_locations(self): |
| 428 |
src = ast.parse('write("spam")') |
| 429 |
src.body.append(ast.Expr(ast.Call(ast.Name('spam', ast.Load()), |
| 430 |
[ast.Str('eggs')], [], None, None))) |
| 431 |
self.assertEqual(src, ast.fix_missing_locations(src)) |
| 432 |
self.assertEqual(ast.dump(src, include_attributes=True), |
| 433 |
"Module(body=[Expr(value=Call(func=Name(id='write', ctx=Load(), " |
| 434 |
"lineno=1, col_offset=0), args=[Str(s='spam', lineno=1, " |
| 435 |
"col_offset=6)], keywords=[], starargs=None, kwargs=None, " |
| 436 |
"lineno=1, col_offset=0), lineno=1, col_offset=0), " |
| 437 |
"Expr(value=Call(func=Name(id='spam', ctx=Load(), lineno=1, " |
| 438 |
"col_offset=0), args=[Str(s='eggs', lineno=1, col_offset=0)], " |
| 439 |
"keywords=[], starargs=None, kwargs=None, lineno=1, " |
| 440 |
"col_offset=0), lineno=1, col_offset=0)])" |
| 441 |
) |
| 442 |
|
| 443 |
def test_increment_lineno(self): |
| 444 |
src = ast.parse('1 + 1', mode='eval') |
| 445 |
self.assertEqual(ast.increment_lineno(src, n=3), src) |
| 446 |
self.assertEqual(ast.dump(src, include_attributes=True), |
| 447 |
'Expression(body=BinOp(left=Num(n=1, lineno=4, col_offset=0), ' |
| 448 |
'op=Add(), right=Num(n=1, lineno=4, col_offset=4), lineno=4, ' |
| 449 |
'col_offset=0))' |
| 450 |
) |
| 451 |
|
| 452 |
src = ast.parse('1 + 1', mode='eval') |
| 453 |
self.assertEqual(ast.increment_lineno(src.body, n=3), src.body) |
| 454 |
self.assertEqual(ast.dump(src, include_attributes=True), |
| 455 |
'Expression(body=BinOp(left=Num(n=1, lineno=4, col_offset=0), ' |
| 456 |
'op=Add(), right=Num(n=1, lineno=4, col_offset=4), lineno=4, ' |
| 457 |
'col_offset=0))' |
| 458 |
) |
| 459 |
|
| 460 |
def test_iter_fields(self): |
| 461 |
node = ast.parse('foo()', mode='eval') |
| 462 |
d = dict(ast.iter_fields(node.body)) |
| 463 |
self.assertEqual(d.pop('func').id, 'foo') |
| 464 |
self.assertEqual(d, {'keywords': [], 'kwargs': None, |
| 465 |
'args': [], 'starargs': None}) |
| 466 |
|
| 467 |
def test_iter_child_nodes(self): |
| 468 |
node = ast.parse("spam(23, 42, eggs='leek')", mode='eval') |
| 469 |
self.assertEqual(len(list(ast.iter_child_nodes(node.body))), 4) |
| 470 |
iterator = ast.iter_child_nodes(node.body) |
| 471 |
self.assertEqual(next(iterator).id, 'spam') |
| 472 |
self.assertEqual(next(iterator).n, 23) |
| 473 |
self.assertEqual(next(iterator).n, 42) |
| 474 |
self.assertEqual(ast.dump(next(iterator)), |
| 475 |
"keyword(arg='eggs', value=Str(s='leek'))" |
| 476 |
) |
| 477 |
|
| 478 |
def test_get_docstring(self): |
| 479 |
node = ast.parse('def foo():\n """line one\n line two"""') |
| 480 |
self.assertEqual(ast.get_docstring(node.body[0]), |
| 481 |
'line one\nline two') |
| 482 |
|
| 483 |
def test_literal_eval(self): |
| 484 |
self.assertEqual(ast.literal_eval('[1, 2, 3]'), [1, 2, 3]) |
| 485 |
self.assertEqual(ast.literal_eval('{"foo": 42}'), {"foo": 42}) |
| 486 |
self.assertEqual(ast.literal_eval('(True, False, None)'), (True, False, None)) |
| 487 |
self.assertRaises(ValueError, ast.literal_eval, 'foo()') |
| 488 |
|
| 489 |
def test_literal_eval_issue4907(self): |
| 490 |
self.assertEqual(ast.literal_eval('2j'), 2j) |
| 491 |
self.assertEqual(ast.literal_eval('10 + 2j'), 10 + 2j) |
| 492 |
self.assertEqual(ast.literal_eval('1.5 - 2j'), 1.5 - 2j) |
| 493 |
self.assertRaises(ValueError, ast.literal_eval, '2 + (3 + 4j)') |
| 494 |
|
| 495 |
|
| 496 |
def test_main(): |
| 497 |
with test_support.check_py3k_warnings(("backquote not supported", |
| 498 |
SyntaxWarning)): |
| 499 |
test_support.run_unittest(AST_Tests, ASTHelpers_Test) |
| 500 |
|
| 501 |
def main(): |
| 502 |
if __name__ != '__main__': |
| 503 |
return |
| 504 |
if sys.argv[1:] == ['-g']: |
| 505 |
for statements, kind in ((exec_tests, "exec"), (single_tests, "single"), |
| 506 |
(eval_tests, "eval")): |
| 507 |
print kind+"_results = [" |
| 508 |
for s in statements: |
| 509 |
print repr(to_tuple(compile(s, "?", kind, 0x400)))+"," |
| 510 |
print "]" |
| 511 |
print "main()" |
| 512 |
raise SystemExit |
| 513 |
test_main() |
| 514 |
|
| 515 |
|
| 516 |
exec_results = [ |
| 517 |
('Module', [('Expr', (1, 0), ('Name', (1, 0), 'None', ('Load',)))]), |
| 518 |
('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, []), [('Pass', (1, 9))], [])]), |
| 519 |
('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('Name', (1, 6), 'a', ('Param',))], None, None, []), [('Pass', (1, 10))], [])]), |
| 520 |
('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('Name', (1, 6), 'a', ('Param',))], None, None, [('Num', (1, 8), 0)]), [('Pass', (1, 12))], [])]), |
| 521 |
('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], 'args', None, []), [('Pass', (1, 14))], [])]), |
| 522 |
('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, 'kwargs', []), [('Pass', (1, 17))], [])]), |
| 523 |
('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('Name', (1, 6), 'a', ('Param',)), ('Name', (1, 9), 'b', ('Param',)), ('Name', (1, 14), 'c', ('Param',)), ('Name', (1, 22), 'd', ('Param',)), ('Name', (1, 28), 'e', ('Param',))], 'args', 'kwargs', [('Num', (1, 11), 1), ('Name', (1, 16), 'None', ('Load',)), ('List', (1, 24), [], ('Load',)), ('Dict', (1, 30), [], [])]), [('Pass', (1, 52))], [])]), |
| 524 |
('Module', [('ClassDef', (1, 0), 'C', [], [('Pass', (1, 8))], [])]), |
| 525 |
('Module', [('ClassDef', (1, 0), 'C', [('Name', (1, 8), 'object', ('Load',))], [('Pass', (1, 17))], [])]), |
| 526 |
('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, []), [('Return', (1, 8), ('Num', (1, 15), 1))], [])]), |
| 527 |
('Module', [('Delete', (1, 0), [('Name', (1, 4), 'v', ('Del',))])]), |
| 528 |
('Module', [('Assign', (1, 0), [('Name', (1, 0), 'v', ('Store',))], ('Num', (1, 4), 1))]), |
| 529 |
('Module', [('AugAssign', (1, 0), ('Name', (1, 0), 'v', ('Store',)), ('Add',), ('Num', (1, 5), 1))]), |
| 530 |
('Module', [('Print', (1, 0), ('Name', (1, 8), 'f', ('Load',)), [('Num', (1, 11), 1)], False)]), |
| 531 |
('Module', [('For', (1, 0), ('Name', (1, 4), 'v', ('Store',)), ('Name', (1, 9), 'v', ('Load',)), [('Pass', (1, 11))], [])]), |
| 532 |
('Module', [('While', (1, 0), ('Name', (1, 6), 'v', ('Load',)), [('Pass', (1, 8))], [])]), |
| 533 |
('Module', [('If', (1, 0), ('Name', (1, 3), 'v', ('Load',)), [('Pass', (1, 5))], [])]), |
| 534 |
('Module', [('Raise', (1, 0), ('Name', (1, 6), 'Exception', ('Load',)), ('Str', (1, 17), 'string'), None)]), |
| 535 |
('Module', [('TryExcept', (1, 0), [('Pass', (2, 2))], [('ExceptHandler', (3, 0), ('Name', (3, 7), 'Exception', ('Load',)), None, [('Pass', (4, 2))])], [])]), |
| 536 |
('Module', [('TryFinally', (1, 0), [('Pass', (2, 2))], [('Pass', (4, 2))])]), |
| 537 |
('Module', [('Assert', (1, 0), ('Name', (1, 7), 'v', ('Load',)), None)]), |
| 538 |
('Module', [('Import', (1, 0), [('alias', 'sys', None)])]), |
| 539 |
('Module', [('ImportFrom', (1, 0), 'sys', [('alias', 'v', None)], 0)]), |
| 540 |
('Module', [('Exec', (1, 0), ('Str', (1, 5), 'v'), None, None)]), |
| 541 |
('Module', [('Global', (1, 0), ['v'])]), |
| 542 |
('Module', [('Expr', (1, 0), ('Num', (1, 0), 1))]), |
| 543 |
('Module', [('Pass', (1, 0))]), |
| 544 |
('Module', [('Break', (1, 0))]), |
| 545 |
('Module', [('Continue', (1, 0))]), |
| 546 |
('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))], [])]), |
| 547 |
('Module', [('Expr', (1, 0), ('ListComp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])]))]), |
| 548 |
('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])]))]), |
| 549 |
('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 12), [('Name', (1, 12), 'a', ('Store',)), ('Name', (1, 14), 'b', ('Store',))], ('Store',)), ('Name', (1, 20), 'c', ('Load',)), [])]))]), |
| 550 |
('Module', [('Expr', (1, 0), ('GeneratorExp', (2, 4), ('Tuple', (3, 4), [('Name', (3, 4), 'Aa', ('Load',)), ('Name', (5, 7), 'Bb', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (8, 4), [('Name', (8, 4), 'Aa', ('Store',)), ('Name', (10, 4), 'Bb', ('Store',))], ('Store',)), ('Name', (10, 10), 'Cc', ('Load',)), [])]))]), |
| 551 |
('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',))])]))]), |
| 552 |
('Module', [('Expr', (1, 0), ('DictComp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), ('Name', (1, 5), 'b', ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'v', ('Store',)), ('Name', (1, 13), 'w', ('Store',))], ('Store',)), ('Name', (1, 18), 'x', ('Load',)), [])]))]), |
| 553 |
('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',))])]))]), |
| 554 |
('Module', [('Expr', (1, 0), ('SetComp', (1, 1), ('Name', (1, 1), 'r', ('Load',)), [('comprehension', ('Tuple', (1, 7), [('Name', (1, 7), 'l', ('Store',)), ('Name', (1, 9), 'm', ('Store',))], ('Store',)), ('Name', (1, 14), 'x', ('Load',)), [])]))]), |
| 555 |
('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, []), [('Pass', (4, 9))], [('Name', (1, 1), 'deco1', ('Load',)), ('Call', (2, 1), ('Name', (2, 1), 'deco2', ('Load',)), [], [], None, None), ('Call', (3, 1), ('Name', (3, 1), 'deco3', ('Load',)), [('Num', (3, 7), 1)], [], None, None)])]), |
| 556 |
('Module', [('ClassDef', (1, 0), 'C', [], [('Pass', (4, 9))], [('Name', (1, 1), 'deco1', ('Load',)), ('Call', (2, 1), ('Name', (2, 1), 'deco2', ('Load',)), [], [], None, None), ('Call', (3, 1), ('Name', (3, 1), 'deco3', ('Load',)), [('Num', (3, 7), 1)], [], None, None)])]), |
| 557 |
('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, []), [('Pass', (2, 9))], [('Call', (1, 1), ('Name', (1, 1), 'deco', ('Load',)), [('GeneratorExp', (1, 6), ('Name', (1, 6), 'a', ('Load',)), [('comprehension', ('Name', (1, 12), 'a', ('Store',)), ('Name', (1, 17), 'b', ('Load',)), [])])], [], None, None)])]), |
| 558 |
] |
| 559 |
single_results = [ |
| 560 |
('Interactive', [('Expr', (1, 0), ('BinOp', (1, 0), ('Num', (1, 0), 1), ('Add',), ('Num', (1, 2), 2)))]), |
| 561 |
] |
| 562 |
eval_results = [ |
| 563 |
('Expression', ('Name', (1, 0), 'None', ('Load',))), |
| 564 |
('Expression', ('BoolOp', (1, 0), ('And',), [('Name', (1, 0), 'a', ('Load',)), ('Name', (1, 6), 'b', ('Load',))])), |
| 565 |
('Expression', ('BinOp', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Add',), ('Name', (1, 4), 'b', ('Load',)))), |
| 566 |
('Expression', ('UnaryOp', (1, 0), ('Not',), ('Name', (1, 4), 'v', ('Load',)))), |
| 567 |
('Expression', ('Lambda', (1, 0), ('arguments', [], None, None, []), ('Name', (1, 7), 'None', ('Load',)))), |
| 568 |
('Expression', ('Dict', (1, 0), [('Num', (1, 2), 1)], [('Num', (1, 4), 2)])), |
| 569 |
('Expression', ('Dict', (1, 0), [], [])), |
| 570 |
('Expression', ('Set', (1, 0), [('Name', (1, 1), 'None', ('Load',))])), |
| 571 |
('Expression', ('Dict', (1, 0), [('Num', (2, 6), 1)], [('Num', (4, 10), 2)])), |
| 572 |
('Expression', ('ListComp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))])])), |
| 573 |
('Expression', ('GeneratorExp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))])])), |
| 574 |
('Expression', ('Compare', (1, 0), ('Num', (1, 0), 1), [('Lt',), ('Lt',)], [('Num', (1, 4), 2), ('Num', (1, 8), 3)])), |
| 575 |
('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',)))), |
| 576 |
('Expression', ('Repr', (1, 0), ('Name', (1, 1), 'v', ('Load',)))), |
| 577 |
('Expression', ('Num', (1, 0), 10L)), |
| 578 |
('Expression', ('Str', (1, 0), 'string')), |
| 579 |
('Expression', ('Attribute', (1, 0), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',))), |
| 580 |
('Expression', ('Subscript', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None), ('Load',))), |
| 581 |
('Expression', ('Name', (1, 0), 'v', ('Load',))), |
| 582 |
('Expression', ('List', (1, 0), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))), |
| 583 |
('Expression', ('List', (1, 0), [], ('Load',))), |
| 584 |
('Expression', ('Tuple', (1, 0), [('Num', (1, 0), 1), ('Num', (1, 2), 2), ('Num', (1, 4), 3)], ('Load',))), |
| 585 |
('Expression', ('Tuple', (1, 1), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))), |
| 586 |
('Expression', ('Tuple', (1, 0), [], ('Load',))), |
| 587 |
('Expression', ('Call', (1, 0), ('Attribute', (1, 0), ('Attribute', (1, 0), ('Attribute', (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)), |
| 588 |
] |
| 589 |
main() |