node.cf_is_null = True
if node.allow_null or entry.from_closure or entry.is_pyclass_attr:
pass # Can be uninitialized here
+ elif entry.in_closure:
+ pass # not smart enough to get this right
elif node.cf_is_null:
if (entry.type.is_pyobject or entry.type.is_unspecified or
entry.error_on_uninitialized):
return node
return kwargs
-class InlineDefNodeCalls(Visitor.CythonTransform):
+class InlineDefNodeCalls(Visitor.EnvTransform):
visit_Node = Visitor.VisitorTransform.recurse_to_children
def visit_SimpleCallNode(self, node):
if not self.current_directives.get('optimize.inline_defnode_calls'):
return node
function_name = node.function
- if not function_name.is_name:
+ if not function_name.is_name or function_name.cf_state is None:
return node
- if (function_name.cf_state is None # global scope
- or not function_name.cf_state.is_single):
+ entry = self.current_env().lookup(function_name.name)
+ if not entry or (not entry.cf_assignments
+ or len(entry.cf_assignments) != 1):
return node
- function = function_name.cf_state.one().rhs
+ function = entry.cf_assignments[0].rhs
if not isinstance(function, ExprNodes.PyCFunctionNode):
return node
inlined = ExprNodes.InlinedDefNodeCallNode(
pass
call(1, sideeffect(2), 3, sideeffect(4), sideeffect(5))
return L
+
+
+def test_redef(redefine):
+ """
+ >>> test_redef(False)
+ 1
+ >>> test_redef(True)
+ 2
+ """
+ def inner():
+ return 1
+ def inner2():
+ return 2
+ def redef():
+ nonlocal inner
+ inner = inner2
+ if redefine:
+ redef()
+ assert inner == inner2
+ else:
+ assert inner != inner2
+ return inner()