Message320790
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 '}' |
|
| Date |
User |
Action |
Args |
| 2018-06-30 16:21:18 | skreft | set | recipients:
+ skreft, eric.smith, benjamin.peterson, steven.daprano |
| 2018-06-30 16:21:18 | skreft | set | messageid: <[email protected]> |
| 2018-06-30 16:21:18 | skreft | link | issue33991 messages |
| 2018-06-30 16:21:18 | skreft | create | |
|