You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 5, 2023. It is now read-only.
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?
changed the title [-]parsing f-string -- opening brace gets duplicated when escaped backslash is followed by an expression[/-][+]f-strings -- opening brace gets duplicated when escaped backslash is followed by an expression[/+]on Mar 14, 2017
changed the title [-]f-strings -- opening brace gets duplicated when escaped backslash is followed by an expression[/-][+]parsing f-strings -- opening brace gets duplicated when escaped backslash is followed by an expression[/+]on Mar 14, 2017
changed the title [-]parsing f-strings -- opening brace gets duplicated when escaped backslash is followed by an expression[/-][+]parsing f-strings -- opening brace gets duplicated when backslash is followed by an expression[/+]on Mar 14, 2017
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 \{ in normal vs. f-strings.
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 \{ seems to be in discussion about possible alternate expression opening/closing delimiters.
Activity
[-]parsing f-string -- opening brace gets duplicated when escaped backslash is followed by an expression[/-][+]f-strings -- opening brace gets duplicated when escaped backslash is followed by an expression[/+][-]f-strings -- opening brace gets duplicated when escaped backslash is followed by an expression[/-][+]parsing f-strings -- opening brace gets duplicated when escaped backslash is followed by an expression[/+][-]parsing f-strings -- opening brace gets duplicated when escaped backslash is followed by an expression[/-][+]parsing f-strings -- opening brace gets duplicated when backslash is followed by an expression[/+]gvanrossum commentedon Mar 14, 2017
What does the stdlib ast module print for the same inputs?
refi64 commentedon Mar 14, 2017
Sounds like you might have hit a CPython bug...
mbdevpl commentedon Mar 14, 2017
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
\{
in normal vs. f-strings.gvanrossum commentedon Mar 14, 2017
Check the PEP, there's a rule against backslashes before curly braces.
ddfisher commentedon Mar 14, 2017
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.
mbdevpl commentedon Mar 15, 2017
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
\{
seems to be in discussion about possible alternate expression opening/closing delimiters.I reported this issue here: https://bugs.python.org/issue29814
gvanrossum commentedon Mar 15, 2017
Where it was deemed a dupe of https://bugs.python.org/issue29104.
Merge pull request python#34 from python-lz4/development