tensorflow: tf_upgrade_v2 fails if the file contains f-strings and gives pasta.base.annotate.AnnotationError
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS 10.14.3
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: NA
- TensorFlow installed from (source or binary): pip install tensorflow==2.0.0-alpha0
- TensorFlow version (use command below): 2.0.0-alpha0
- Python version: 3.6.8
- Bazel version (if compiling from source):
- GCC/Compiler version (if compiling from source):
- CUDA/cuDNN version: NA
- GPU model and memory: NA
Describe the current behavior
tf_upgrade_v2
fails if the file contains f-strings
Describe the expected behavior
tf_upgrade_v2
does not fails if the file contains f-strings
Code to reproduce the issue
File foo.py
:
print(f'tf_upgrade_v2 fails to convert f-strings, like this one: {42}')
Command that produces the error: tf_upgrade_v2 --infile foo.py --outfile foo_tf20.py
Other info / logs
Traceback (most recent call last):
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 1161, in visit
super(AstAnnotator, self).visit(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 127, in visit
super(BaseVisitor, self).visit(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/ast.py", line 253, in visit
return visitor(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 47, in wrapped
f(self, node, *args, **kwargs)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 1213, in visit_Num
self.attr(node, 'content', contentargs, deps=('n',), default=str(node.n))
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 1352, in attr
attr_parts.append(attr_val())
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 1210, in <lambda>
contentargs = [lambda: self.tokens.next_of_type(token_number_type).src]
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/token_generator.py", line 347, in next_of_type
self.lines[token.start[0] - 1]))
ValueError: Expected 'NUMBER' but found ')'
line 1: print(f'tf_upgrade_v2 fails to convert f-strings, like this one: {42}')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/anaconda3/envs/tf2.0/bin/tf_upgrade_v2", line 10, in <module>
sys.exit(main())
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/tensorflow/tools/compatibility/tf_upgrade_v2_main.py", line 110, in main
args.input_file, output_file, upgrade)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/tensorflow/tools/compatibility/tf_upgrade_v2_main.py", line 33, in process_file
upgrader.process_file(in_filename, out_filename)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/tensorflow/tools/compatibility/ast_edits.py", line 494, in process_file
temp_file)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/tensorflow/tools/compatibility/ast_edits.py", line 548, in process_opened_file
self.update_string_pasta("".join(lines), in_filename))
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/tensorflow/tools/compatibility/ast_edits.py", line 510, in update_string_pasta
t = pasta.parse(text)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/__init__.py", line 25, in parse
annotator.visit(t)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 1161, in visit
super(AstAnnotator, self).visit(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 127, in visit
super(BaseVisitor, self).visit(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/ast.py", line 253, in visit
return visitor(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 47, in wrapped
f(self, node, *args, **kwargs)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 211, in visit_Module
self.generic_visit(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/ast.py", line 261, in generic_visit
self.visit(item)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 1161, in visit
super(AstAnnotator, self).visit(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 127, in visit
super(BaseVisitor, self).visit(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/ast.py", line 253, in visit
return visitor(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 47, in wrapped
f(self, node, *args, **kwargs)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 574, in visit_Expr
self.visit(node.value)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 1161, in visit
super(AstAnnotator, self).visit(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 127, in visit
super(BaseVisitor, self).visit(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/ast.py", line 253, in visit
return visitor(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 47, in wrapped
f(self, node, *args, **kwargs)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 703, in visit_Call
any_args = self.visit_Call_arguments35(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 770, in visit_Call_arguments35
self.visit(arg)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 1161, in visit
super(AstAnnotator, self).visit(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 127, in visit
super(BaseVisitor, self).visit(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/ast.py", line 253, in visit
return visitor(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/ast.py", line 261, in generic_visit
self.visit(item)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 1161, in visit
super(AstAnnotator, self).visit(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 127, in visit
super(BaseVisitor, self).visit(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/ast.py", line 253, in visit
return visitor(node)
File "/anaconda3/envs/tf2.0/lib/python3.6/ast.py", line 263, in generic_visit
self.visit(value)
File "/anaconda3/envs/tf2.0/lib/python3.6/site-packages/pasta/base/annotate.py", line 1163, in visit
raise AnnotationError(e)
pasta.base.annotate.AnnotationError: Expected 'NUMBER' but found ')'
line 1: print(f'tf_upgrade_v2 fails to convert f-strings, like this one: {42}')
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 18 (7 by maintainers)
It should be fixed in
0.1.7
.