Skip to content

Commit

Permalink
Avoid unconditionally using gast.Ellipsis, which doesn't exist in gas…
Browse files Browse the repository at this point in the history
…t 0.3.

Also unpin dependency, to allow gast 0.3+
Keeping the pin for the TF1 nightly, because that one is itself broken on gast 0.3+

Fixes tensorflow#552.

PiperOrigin-RevId: 270138305
  • Loading branch information
axch authored and tensorflower-gardener committed Sep 19, 2019
1 parent 88fa16d commit ae7a9d9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
'numpy >= 1.13.3',
'decorator',
'cloudpickle == 1.1.1',
'gast >= 0.2, < 0.3' # For autobatching
'gast >= 0.2' # For autobatching
]

if '--release' in sys.argv:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,31 @@ def maybe_replace_function_argument(parent, field_name, child):
return node, ctx


_LITERALS = (gast.Num, gast.Str, gast.Bytes, gast.Ellipsis, gast.NameConstant)
def _is_literal(node):
"""Detects whether the given node is a literal.
This is surprisingly difficult to do robustly across versions of Python and
gast, as the parsing of constants has changed, if I may, constantly.
def _is_literal(node):
if isinstance(node, _LITERALS):
return True
Args:
node: The node whose status to check.
Returns:
literal: A Python `bool` giving whether the node is constant or not.
"""
try:
# TODO(b/140808434): Once we or TF decide to roll forward to gast 0.3, we
# won't need this clause.
# gast pre-0.3
literals = (gast.Num, gast.Str, gast.Bytes, gast.Ellipsis,
gast.NameConstant)
if isinstance(node, literals):
return True
except AttributeError:
# gast 0.3+
if isinstance(node, gast.Constant):
return True
# Python 2
if isinstance(node, gast.Name) and node.id in ['True', 'False', 'None']:
return True
return False
Expand Down
3 changes: 2 additions & 1 deletion testing/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ find_version_str() {
install_python_packages() {
# NB: tf-nightly pulls in other deps, like numpy, absl, and six, transitively.
TF_VERSION_STR=$(find_version_str tf-nightly)
pip install tf-nightly==$TF_VERSION_STR gast==0.2.2 \
pip install tf-nightly==$TF_VERSION_STR \
gast==0.2.2 \
tf-estimator-nightly==1.14.0.dev2019091701

# The following unofficial dependencies are used only by tests.
Expand Down

0 comments on commit ae7a9d9

Please sign in to comment.