diff options
Diffstat (limited to 'tensorflow/python/autograph')
-rw-r--r-- | tensorflow/python/autograph/pyct/compiler.py | 11 |
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 |