-
-
Notifications
You must be signed in to change notification settings - Fork 54
parsing f-strings -- opening brace gets duplicated when backslash is followed by an expression #34
Comments
What does the stdlib ast module print for the same inputs? |
Sounds like you might have hit a CPython bug... |
When parsing using built-in ast, the exact same thing happens:
Also, I just noticed that when I escape the backslash once, what gets parsed is actually unescaped backslash. So this might just boil down to inconsistency in parsing |
Check the PEP, there's a rule against backslashes before curly braces. |
It looks like the PEP only disallows backslashes within fstrings. @mbdevpl: this seems like a CPython bug -- could you file it in the Python bug tracker? typed_ast's is intended to match the implicit spec that is CPython, so until this behavior is fixed upstream, typed_ast is behaving correctly. |
Sure, thanks for taking a look! I had yet another careful read of the PEP, and I also cannot find anything about backslashes being disallowed outside of expressions. The only mention of I reported this issue here: https://bugs.python.org/issue29814 |
Where it was deemed a dupe of https://bugs.python.org/issue29104. |
Merge development branch
with Python 3.6.0 and typed-ast 1.0.2, I get the following:
output:
Therefore, the normal string is
'\\{x}'
.But the f-string has two parts:
'\\{'
and an expressionName(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?The text was updated successfully, but these errors were encountered: