[proxy] bugs.python.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light

Issue 27948: f-strings: allow backslashes only in the string parts, not in the expression parts

Issue27948

classification
Title: f-strings: allow backslashes only in the string parts, not in the expression parts
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: eric.smith, flying sheep, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2016-09-03 13:24 by eric.smith, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
27948-1.diff eric.smith, 2016-09-07 13:56 review
27948-2.diff eric.smith, 2016-09-09 11:17 review
Messages (5)
msg274294 - (view) Author: Eric V. Smith (eric.smith) * Date: 2016-09-03 13:24
See issue 27921.

Currently (and for 3.6 beta 1), backslashes are not allowed anywhere in f-strings. This needs to be changed to allow them in the string parts, but not in the expression parts.

Also, require that the start and end of an expression be literal '{' and '}, not escapes like '\0x7b' and '\u007d'.
msg274811 - (view) Author: Eric V. Smith (eric.smith) * Date: 2016-09-07 13:56
This patch implements the new logic. It passes all of the fstring tests (except of course the ones that had backslashes in the expressions). I'd still like to add some more tests, because I'm not convinced the named unicode escapes are correct (f"\N{LEFT CURLY BRACE}". Because I'm now scanning the decoded utf-8 version of the string, I need to be aware of this syntax and not decide it's part of an expression (because of the braces).
msg275309 - (view) Author: Eric V. Smith (eric.smith) * Date: 2016-09-09 11:17
Updated patch, works against HEAD. I added a few tests and tweaked some comments. My goal is to commit this today, before the 3.6b1 cutoff. I don't think there's much risk to it.

I still need to update the PEP.
msg275540 - (view) Author: Roundup Robot (python-dev) Date: 2016-09-10 01:56
New changeset b3ac1e154cdd by Eric V. Smith in branch 'default':
Issue 27948: Allow backslashes in the literal string portion of f-strings, but not in the expressions. Also, require expressions to begin and end with literal curly braces.
https://hg.python.org/cpython/rev/b3ac1e154cdd
msg275541 - (view) Author: Eric V. Smith (eric.smith) * Date: 2016-09-10 01:59
I've fixed the code and fixed/added tests. I still need to update the docs and PEP 498. I'll create a separate issue for the docs, once I'm done with the PEP.
History
Date User Action Args
2022-04-11 14:58:35adminsetgithub: 72135
2016-09-19 08:56:02flying sheepsetnosy: + flying sheep
2016-09-10 01:59:14eric.smithsetstatus: open -> closed
resolution: fixed
messages: + msg275541

stage: patch review -> resolved

2016-09-10 01:56:26python-devsetnosy: + python-dev
messages: + msg275540
2016-09-09 11:17:11eric.smithsetfiles: + 27948-2.diff

messages: + msg275309

2016-09-07 15:01:19serhiy.storchakasetnosy: + serhiy.storchaka
2016-09-07 13:56:20eric.smithsetstage: needs patch -> patch review
2016-09-07 13:56:03eric.smithsetfiles: + 27948-1.diff
keywords: + patch
messages: + msg274811
2016-09-03 13:24:05eric.smithcreate