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:
parent
20a904017c
commit
92e9bf1c61
@ -45,6 +45,7 @@ CONVERSION_RULES = (
|
||||
DoNotConvert('pstats'),
|
||||
DoNotConvert('re'),
|
||||
DoNotConvert('threading'),
|
||||
DoNotConvert('urllib'),
|
||||
|
||||
# Known libraries
|
||||
DoNotConvert('matplotlib'),
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user