Message320790
| Author |
skreft |
| Recipients |
benjamin.peterson, eric.smith, skreft, steven.daprano |
| Date |
2018年06月30日.16:21:18 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1530375678.24.0.56676864532.issue33991@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Note also, that lib2to3 will parse invalid f-strings like f"hello {", whereas ast.parse will raise a SyntaxError exception.
See below for reproduction cases:
In [2]: lib2to3.tests.support.parse_string('f"hello {"')
Out[2]: Node(file_input, [Node(simple_stmt, [Leaf(3, 'f"hello {"'), Leaf(4, '\n')]), Leaf(0, '')])
In [4]: ast.parse('f"hello {"')
Traceback (most recent call last):
File "/Users/skreft/.virtualenvs/pyfaster/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2963, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-4-78a4f2773f7f>", line 1, in <module>
ast.parse('f"hello {"')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ast.py", line 35, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
File "<unknown>", line 1
SyntaxError: f-string: expecting '}' |
|