@@ -600,43 +600,12 @@ def build(self) -> ast.Module:
600600 return ast .fix_missing_locations (ret )
601601
602602
603- def unparse (tree : ast .AST , short_fallback : bool = False ) -> str :
604- """Returns Python code equivalent to executing ``tree``."""
605- if sys .version_info >= (3 , 9 ):
606- return ast .unparse (tree )
607- try :
608- import astunparse # type: ignore
609-
610- return cast (str , astunparse .unparse (tree ))
611- except ImportError :
612- pass
613- return (
614- fallback_unparse (tree )
615- if not short_fallback
616- else f"# { ast .dump (tree )} # --explain has instructions to make this readable"
617- )
618-
619-
620- def fallback_unparse (tree : ast .AST ) -> str :
621- return f"""
622- from ast import *
623- tree = fix_missing_locations({ ast .dump (tree )} )
624-
625- # To see this in human readable form, run pyp with Python 3.9
626- # Alternatively, install a third party ast unparser: `python3 -m pip install astunparse`
627- # Once you've done that, simply re-run.
628- # In the meantime, this script is fully functional, if not easily readable or modifiable...
629-
630- exec(compile(tree, filename="<ast>", mode="exec"), {{}})
631- """
632-
633-
634603def run_pyp (args : argparse .Namespace ) -> None :
635604 config = PypConfig ()
636605 tree = PypTransform (args .before , args .code , args .after , args .define_pypprint , config ).build ()
637606 if args .explain :
638607 print (config .shebang )
639- print (unparse (tree ))
608+ print (ast . unparse (tree ))
640609 return
641610 try :
642611 exec (compile (tree , filename = "<pyp>" , mode = "exec" ), {})
@@ -654,7 +623,7 @@ def code_for_line(lineno: int) -> str:
654623 for _ , value in ast .iter_fields (node ):
655624 if isinstance (value , list ) and value and isinstance (value [0 ], ast .stmt ):
656625 value .clear ()
657- return unparse (node , short_fallback = True ).strip ()
626+ return ast . unparse (node ).strip ()
658627
659628 # Time to commit several sins against CPython implementation details
660629 tb_except = traceback .TracebackException (
0 commit comments