Skip to content

Commit

Permalink
Restrict the check for possibly-undefined variables to basic symbols …
Browse files Browse the repository at this point in the history
…- composite ones, like attributes and slices are resolved at runtime.

PiperOrigin-RevId: 220609776
  • Loading branch information
Dan Moldovan authored and tensorflower-gardener committed Nov 8, 2018
1 parent ac0b848 commit aeb04dd
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tensorflow/python/autograph/converters/control_flow.py
Expand Up @@ -131,14 +131,18 @@ def visit_If(self, node):
created_in_body = body_scope.modified & returned_from_cond - defined_in
created_in_orelse = orelse_scope.modified & returned_from_cond - defined_in

if created_in_body != created_in_orelse:
basic_created_in_body = tuple(
s for s in created_in_body if not s.is_composite())
basic_created_in_orelse = tuple(
s for s in created_in_orelse if not s.is_composite())
if basic_created_in_body != basic_created_in_orelse:
raise ValueError(
'if statement may not initialize all variables: the true branch'
' creates %s, while the false branch creates %s. Make sure all'
' these variables are initialized either in both'
' branches or before the if statement.' %
(self._fmt_symbols(created_in_body),
self._fmt_symbols(created_in_orelse)))
(self._fmt_symbols(basic_created_in_body),
self._fmt_symbols(basic_created_in_orelse)))

# Alias the closure variables inside the conditional functions, to allow
# the functions access to the respective variables.
Expand Down

0 comments on commit aeb04dd

Please sign in to comment.