This repository was archived by the owner on Jul 5, 2023. It is now read-only.
This repository was archived by the owner on Jul 5, 2023. It is now read-only.
parsing f-strings -- opening brace gets duplicated when backslash is followed by an expression #34
Closed
Description
with Python 3.6.0 and typed-ast 1.0.2, I get the following:
#!/usr/bin/env python3.6
import typed_ast.ast3 as ast
code1 = '''"\\{x}"'''
code2 = '''f"\\{x}"'''
tree1 = ast.parse(code1, mode='eval')
print(ast.dump(tree1))
tree2 = ast.parse(code2, mode='eval')
print(ast.dump(tree2))
output:
Expression(body=Str(s='\\{x}'))
Expression(body=JoinedStr(values=[Str(s='\\{'), FormattedValue(value=Name(id='x', ctx=Load()), conversion=-1, format_spec=None)]))
Therefore, the normal string is '\\{x}'
.
But the f-string has two parts: '\\{'
and an expression Name(id='x', ctx=Load())
.
Where does the {
in the string part of f-string come from? This happens also with built-in ast. I can't believe this is the intended behavior... Is it?
Metadata
Metadata
Assignees
Labels
No labels