Use a broader definition for the "modified" list when extracting block variables, by looking at Scope.bound instead of Scope.modified. Most of the time these are identical, but the latter includes symbols captured by e.g. del.

PiperOrigin-RevId: 329704730
Change-Id: I0f84002d8469e281ed6990520ac064509d79cb7a
This commit is contained in:
Dan Moldovan 2020-09-02 06:59:35 -07:00 committed by TensorFlower Gardener
parent 963e2693da
commit 5363cf3d1d

View File

@ -212,7 +212,7 @@ class ControlFlowTransformer(converter.Base):
orelse_scope = anno.getanno(node, annos.NodeAnno.ORELSE_SCOPE)
cond_vars, undefined, nouts = self._get_block_vars(
node, body_scope.modified | orelse_scope.modified)
node, body_scope.bound | orelse_scope.bound)
undefined_assigns = self._create_undefined_assigns(undefined)
@ -267,7 +267,7 @@ class ControlFlowTransformer(converter.Base):
node = self.generic_visit(node)
body_scope = anno.getanno(node, annos.NodeAnno.BODY_SCOPE)
loop_vars, undefined, _ = self._get_block_vars(node, body_scope.modified)
loop_vars, undefined, _ = self._get_block_vars(node, body_scope.bound)
undefined_assigns = self._create_undefined_assigns(undefined)
@ -319,7 +319,7 @@ class ControlFlowTransformer(converter.Base):
iter_scope = anno.getanno(node, annos.NodeAnno.ITERATE_SCOPE)
loop_vars, undefined, _ = self._get_block_vars(
node, body_scope.modified | iter_scope.modified)
node, body_scope.bound | iter_scope.bound)
undefined_assigns = self._create_undefined_assigns(undefined)