[issue24002] Add un-parse function to ast

2015-04-19 Thread Larry Hastings
Larry Hastings added the comment: Actually eval(ast) is all I need for #23967 too. But eval is a builtin, so it feels wrong to have it supporting--and therefore dependent on--ast. -- ___ Python tracker rep...@bugs.python.org

[issue24002] Add un-parse function to ast

2015-04-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I think there is standard way to transform ast to bytecode and evaluate it. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24002 ___

[issue24002] Add un-parse function to ast

2015-04-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: For issue24001 you need rather eval(ast). But a function for stringifying ast would be useful in any case. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24002

[issue24002] Add un-parse function to ast

2015-04-19 Thread Larry Hastings
Larry Hastings added the comment: There is! compile() will do it, though the docstring doesn't mention it. (The full documentation does.) The following function meets both my use cases: def eval_ast_expr(node, symbols=None, *, filename='-'): Takes an ast.Expr node.

[issue24002] Add un-parse function to ast

2015-04-18 Thread Larry Hastings
New submission from Larry Hastings: Twice recently I've wanted a function that transforms an AST node tree back into text: * In the hacked-up Tools/clinic/clinic.py for issue #24001 * In the hacked-up Lib/inspect.py for issue #23967 Both times I did a half-assed job just to get the patch

[issue24002] Add un-parse function to ast

2015-04-18 Thread Larry Hastings
Changes by Larry Hastings la...@hastings.org: -- nosy: +serhiy.storchaka, zach.ware ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24002 ___ ___

[issue24002] Add un-parse function to ast

2015-04-18 Thread Berker Peksag
Berker Peksag added the comment: Perhaps a NodeVisitor subclass (something like Armin Ronacher's codegen module https://github.com/berkerpeksag/astor/blob/master/astor/codegen.py#L54 can be added to the ast module. -- nosy: +berker.peksag ___

[issue24002] Add un-parse function to ast

2015-04-18 Thread Larry Hastings
Larry Hastings added the comment: Good idea, I'll go ahead and borrow Guido's time machine. https://docs.python.org/3/library/ast.html#ast.NodeVisitor However, NodeVisitor does not transform the ast tree back into text. So in what way is this helpful? Also, for what it's worth: both my use