This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: \\N in f-string causes next { to be literal if not escaped
Type: Stage: resolved
Components: Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Mital Ashok, ned.deily
Priority: normal Keywords:

Created on 2017-07-17 22:09 by Mital Ashok, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg298563 - (view) Author: Mital Ashok (Mital Ashok) * Date: 2017-07-17 22:09
Take this format python code:

    import unicodedata
    c = chr(0x012345)

To print that character as a string literal, you would expect to do:

    print(f"'\\N{{{unicodedata.name(c)}}}'")

Which should print a literal quote (`'`), a backwards slash (`\\` -> `\`), an `N`, and the two `{{` should escape and print `{`, followed by the f-expression `unicodedata.name(c)`, then the `}}` would print one `}`, and then another literal quote (`'`).

However, this raises a `SyntaxError: f-string: single '}' is not allowed`. The way to do this without a syntax error is like so:

    print(f"'\\N{{unicodedata.name(c)}}}'")

Which prints the expected:

    '\N{CUNEIFORM SIGN URU TIMES KI}'

The shortest way to reproduce this is:

    f'\\N{'

Which works, and:

    f'\\N{{'

which raises an error, even though the first one should raise an error (`SyntaxError: f-string: expecting '}'`).
msg298564 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2017-07-17 22:26
Thanks for the report.  This problem has been fixed in Python 3.6.2 which was just released.  I believe it was fixed by the changes for Issue29104.
History
Date User Action Args
2022-04-11 14:58:49adminsetgithub: 75138
2017-07-17 22:26:19ned.deilysetstatus: open -> closed

nosy: + ned.deily
messages: + msg298564

resolution: out of date
stage: resolved
2017-07-17 22:09:08Mital Ashokcreate