Fix regression that caused xrange to be ignored.

PiperOrigin-RevId: 215844450
This commit is contained in:
Dan Moldovan 2018-10-04 19:26:26 -07:00 committed by TensorFlower Gardener
parent 5608454c31
commit f4cef34fad
3 changed files with 9 additions and 0 deletions

View File

@ -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_,
}

View File

@ -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):

View File

@ -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."""