diff options
author | Dan Moldovan <mdan@google.com> | 2018-10-04 19:26:26 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-10-04 19:30:55 -0700 |
commit | f4cef34fad7b00a3b1f288ff5c95001c5b83c1f8 (patch) | |
tree | 77d2d4bcd8f4e710850609179b563581b41f6fa9 /tensorflow/python/autograph | |
parent | 5608454c31bb298096bb6aa463b33baa2fa68f08 (diff) |
Fix regression that caused xrange to be ignored.
PiperOrigin-RevId: 215844450
Diffstat (limited to 'tensorflow/python/autograph')
-rw-r--r-- | tensorflow/python/autograph/operators/py_builtins.py | 1 | ||||
-rw-r--r-- | tensorflow/python/autograph/pyct/inspect_utils.py | 4 | ||||
-rw-r--r-- | tensorflow/python/autograph/pyct/static_analysis/live_values.py | 4 |
3 files changed, 9 insertions, 0 deletions
diff --git a/tensorflow/python/autograph/operators/py_builtins.py b/tensorflow/python/autograph/operators/py_builtins.py index 91a2a22cc2..70e59272a9 100644 --- a/tensorflow/python/autograph/operators/py_builtins.py +++ b/tensorflow/python/autograph/operators/py_builtins.py @@ -228,5 +228,6 @@ BUILTIN_FUINCTIONS_MAP = { 'len': len_, 'print': print_, 'range': range_, + # TODO(mdan): This might make more sense as tf.data.range. 'xrange': range_, } diff --git a/tensorflow/python/autograph/pyct/inspect_utils.py b/tensorflow/python/autograph/pyct/inspect_utils.py index eef74599a7..1416988ea3 100644 --- a/tensorflow/python/autograph/pyct/inspect_utils.py +++ b/tensorflow/python/autograph/pyct/inspect_utils.py @@ -30,10 +30,14 @@ from tensorflow.python.util import tf_inspect def isbuiltin(f): + """Returns True if the argument is a built-in function.""" # Note these return false for isinstance(f, types.BuiltinFunctionType) so we # need to specifically check for them. if f in (range, int, float): return True + if six.PY2: + if f in (xrange,): + return True if isinstance(f, types.BuiltinFunctionType): return True if tf_inspect.isbuiltin(f): diff --git a/tensorflow/python/autograph/pyct/static_analysis/live_values.py b/tensorflow/python/autograph/pyct/static_analysis/live_values.py index 36b9e7074d..4ceddce53b 100644 --- a/tensorflow/python/autograph/pyct/static_analysis/live_values.py +++ b/tensorflow/python/autograph/pyct/static_analysis/live_values.py @@ -24,6 +24,7 @@ from __future__ import division from __future__ import print_function import gast +import six from tensorflow.python.autograph.pyct import anno from tensorflow.python.autograph.pyct import transformer @@ -35,6 +36,9 @@ from tensorflow.python.autograph.pyct.static_analysis.annos import NodeAnno # These symbols are legal in Python, but don't appear in the namespace. _SPECIAL_SYMBOLS = {'range': range, 'print': print} +if six.PY2: + _SPECIAL_SYMBOLS['xrange'] = xrange + class LiveValueResolver(transformer.Base): """Annotates nodes with live values.""" |