Reject code containing the for/else pattern, which is not being faithfully converted at the moment. This replaces silently incorrect behavior with a warning. Also whitelist known urllib module.

PiperOrigin-RevId: 298586574
Change-Id: Idd9113ccc699eb6b13cd5ec76c563a79b20b7aef
This commit is contained in:
Dan Moldovan 2020-03-03 05:53:21 -08:00 committed by TensorFlower Gardener
parent 20a904017c
commit 92e9bf1c61
2 changed files with 17 additions and 5 deletions

View File

@ -45,6 +45,7 @@ CONVERSION_RULES = (
DoNotConvert('pstats'),
DoNotConvert('re'),
DoNotConvert('threading'),
DoNotConvert('urllib'),
# Known libraries
DoNotConvert('matplotlib'),

View File

@ -33,17 +33,28 @@ class UnsupportedFeaturesChecker(gast.NodeVisitor):
if (node.attr is not None
and node.attr.startswith('__') and not node.attr.endswith('__')):
raise errors.UnsupportedLanguageElementError(
'mangled names are not yet supported by AutoGraph')
'mangled names are not yet supported')
self.generic_visit(node)
def visit_For(self, node):
if node.orelse:
raise errors.UnsupportedLanguageElementError(
'for/else statement not yet supported')
self.generic_visit(node)
def visit_While(self, node):
if node.orelse:
raise errors.UnsupportedLanguageElementError(
'while/else statement not yet supported')
self.generic_visit(node)
# These checks could potentially be replaced with inspect.isgeneratorfunction
# to avoid a getsource/parse/ast-walk round trip.
def visit_Yield(self, node):
raise errors.UnsupportedLanguageElementError(
'generators are not supported by AutoGraph')
raise errors.UnsupportedLanguageElementError('generators are not supported')
def visit_YieldFrom(self, node):
raise errors.UnsupportedLanguageElementError(
'generators are not supported by AutoGraph')
raise errors.UnsupportedLanguageElementError('generators are not supported')
def verify(node):