aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/autograph
diff options
context:
space:
mode:
authorGravatar Dan Moldovan <mdan@google.com>2018-09-24 10:21:00 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-09-24 10:36:48 -0700
commit594936f7ce57aa6623b78a0345c728f0bef5a4cf (patch)
treec66b15d7b119c9f793c17d8522623f71b85b2a73 /tensorflow/python/autograph
parentac84ad4b4a83003e1dbfebc505ca994c8126e625 (diff)
Remove the pretty formatting of generated code. The astor library that did that uses circular references, which can be problematic in eager mode.
PiperOrigin-RevId: 214287432
Diffstat (limited to 'tensorflow/python/autograph')
-rw-r--r--tensorflow/python/autograph/pyct/compiler.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/tensorflow/python/autograph/pyct/compiler.py b/tensorflow/python/autograph/pyct/compiler.py
index 37f3e72f6e..21281aeb56 100644
--- a/tensorflow/python/autograph/pyct/compiler.py
+++ b/tensorflow/python/autograph/pyct/compiler.py
@@ -57,8 +57,15 @@ def ast_to_source(node, indentation=' '):
# In some versions of Python, literals may appear as actual values. This
# ensures everything is string.
- code = map(str, generator.result)
- code = astor.source_repr.pretty_source(code).lstrip()
+ code = ''.join(map(str, generator.result))
+
+ # Strip leading blank lines.
+ code_lines = code.split('\n')
+ trimmed_code_lines = []
+ for l in code_lines:
+ if l.rstrip() or trimmed_code_lines:
+ trimmed_code_lines.append(l)
+ code = '\n'.join(trimmed_code_lines)
return code