Created by: Aurelius84
In this PR, we changed the way of inserting newly defined functionDef
nodes into AST root.
Instead of inserting all the func_nodes into outer body of AST root, we used nested structure by adding func_nodes in front of the current if/else
statement.
Pros:
- More clearly to understand the relationship between
cond
layer andtrue_func/false_func
- In some cases, it's easier to deal with the parameter
self
scope problem in Class. Because private variable withself
can't be visited friendly if insert func_nodes into AST root.
Raw code::
def foo():
if control_flow_if:
out= do_something
else:
out = do_nothing
return out
Before this PR:
def true_func():
return do_something
def false_func():
return do_nothing
def foo():
out = layers.cond(control_flow_if, true_func, false_func)
return out
In this PR:
def foo():
def true_func():
return do_something
def false_func():
return do_nothing
out = layers.cond(control_flow_if, true_func, false_func)
return out