berkerpeksag / astor

Python AST read/write
https://pypi.org/project/astor/
BSD 3-Clause "New" or "Revised" License
810 stars 102 forks source link

Add a func to add missing attrs to the AST to make it compilable #185

Open KOLANICH opened 4 years ago

KOLANICH commented 4 years ago

ASTs parsed from source contains lot of stuff it is inconvenient to set when generating AST. Such as lone numbers and ctxes. Without them the code won't compile and run. An obvious way to recreate them is to serialize the AST into source and then parse it. But it seems inefficient. Since the stuff is redundant and can be restored from the AST itself, it's nice to have a function doing that.