@@ -690,7 +690,10 @@ def __init__(
690
690
# Dump the AST so that failing tests have helpful output.
691
691
print (f"Statements: { self .statements } " )
692
692
print (f"Multiline map: { self .multiline } " )
693
- ast_dump (self .root_node )
693
+ dumpkw : Dict [str , Any ] = {}
694
+ if sys .version_info >= (3 , 9 ):
695
+ dumpkw ["indent" ] = 4
696
+ print (ast .dump (self .root_node , include_attributes = True , ** dumpkw ))
694
697
695
698
self .arcs : Set [TArc ] = set ()
696
699
@@ -1350,74 +1353,3 @@ def _code_object__ClassDef(self, node: ast.ClassDef) -> None:
1350
1353
_code_object__DictComp = _make_expression_code_method ("dictionary comprehension" )
1351
1354
_code_object__SetComp = _make_expression_code_method ("set comprehension" )
1352
1355
_code_object__ListComp = _make_expression_code_method ("list comprehension" )
1353
-
1354
-
1355
- # Code only used when dumping the AST for debugging.
1356
-
1357
- SKIP_DUMP_FIELDS = ["ctx" ]
1358
-
1359
- def _is_simple_value (value : Any ) -> bool :
1360
- """Is `value` simple enough to be displayed on a single line?"""
1361
- return (
1362
- value in [None , [], (), {}, set (), frozenset (), Ellipsis ] or
1363
- isinstance (value , (bytes , int , float , str ))
1364
- )
1365
-
1366
- def ast_dump (
1367
- node : ast .AST ,
1368
- depth : int = 0 ,
1369
- print : Callable [[str ], None ] = print , # pylint: disable=redefined-builtin
1370
- ) -> None :
1371
- """Dump the AST for `node`.
1372
-
1373
- This recursively walks the AST, printing a readable version.
1374
-
1375
- """
1376
- indent = " " * depth
1377
- lineno = getattr (node , "lineno" , None )
1378
- if lineno is not None :
1379
- linemark = f" @ { node .lineno } ,{ node .col_offset } "
1380
- if hasattr (node , "end_lineno" ):
1381
- assert hasattr (node , "end_col_offset" )
1382
- linemark += ":"
1383
- if node .end_lineno != node .lineno :
1384
- linemark += f"{ node .end_lineno } ,"
1385
- linemark += f"{ node .end_col_offset } "
1386
- else :
1387
- linemark = ""
1388
- head = f"{ indent } <{ node .__class__ .__name__ } { linemark } "
1389
-
1390
- named_fields = [
1391
- (name , value )
1392
- for name , value in ast .iter_fields (node )
1393
- if name not in SKIP_DUMP_FIELDS
1394
- ]
1395
- if not named_fields :
1396
- print (f"{ head } >" )
1397
- elif len (named_fields ) == 1 and _is_simple_value (named_fields [0 ][1 ]):
1398
- field_name , value = named_fields [0 ]
1399
- print (f"{ head } { field_name } : { value !r} >" )
1400
- else :
1401
- print (head )
1402
- if 0 :
1403
- print ("{}# mro: {}" .format ( # type: ignore[unreachable]
1404
- indent , ", " .join (c .__name__ for c in node .__class__ .__mro__ [1 :]),
1405
- ))
1406
- next_indent = indent + " "
1407
- for field_name , value in named_fields :
1408
- prefix = f"{ next_indent } { field_name } :"
1409
- if _is_simple_value (value ):
1410
- print (f"{ prefix } { value !r} " )
1411
- elif isinstance (value , list ):
1412
- print (f"{ prefix } [" )
1413
- for n in value :
1414
- if _is_simple_value (n ):
1415
- print (f"{ next_indent } { n !r} " )
1416
- else :
1417
- ast_dump (n , depth + 8 , print = print )
1418
- print (f"{ next_indent } ]" )
1419
- else :
1420
- print (prefix )
1421
- ast_dump (value , depth + 8 , print = print )
1422
-
1423
- print (f"{ indent } >" )
0 commit comments