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: f-strings: do not allow backslashes
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: barry, eric.smith, martin.panter, ned.deily, python-dev, serhiy.storchaka
Priority: release blocker Keywords: patch

Created on 2016-08-31 23:49 by eric.smith, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
27921.patch eric.smith, 2016-09-01 00:41 review
27921-1.patch eric.smith, 2016-09-02 12:08 review
Messages (12)
msg274079 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2016-08-31 23:49
See https://mail.python.org/pipermail/python-dev/2016-August/145979.html for details.

PEP 498 is going to be changed to disallow backslashes inside braces (the expression portions of an f-string).

However, I can't get that change done in time for 3.6 beta 1. So, this bug will disallow any backslashes in f-strings. Before the next beta, I'll implement the correct behavior.

This is a breaking change: f-strings like f'\\t{3}' which worked in 3.6 alphas will not work in 3.6 beta 1, but will work in beta 2. f-strings like f'{\'x\'}' which worked in 3.6 alphas, will not work in any beta or release version of 3.6.
msg274172 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-09-01 19:28
> -            result.append(f'  [Previous line repeated {count-3} more times]\n')
> +            result.append(f'  [Previous line repeated {count-3} more times]''\n')

This looks a little ugly.
msg274235 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2016-09-02 12:08
> This looks a little ugly.

True. My goal is to get the simplest possible thing working now, and then before beta 2 fix it so that backslashes again work in the text portions of an f-string. After that, I'll fix this particular piece of code (and the others, plus the tests that can be made to work).

Here's an updated patch. I'm planning on committing it today.
msg274293 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-03 13:18
New changeset d7ce127b5c0f by Eric V. Smith in branch 'default':
Closes issue 27921: Disallow backslashes anywhere in f-strings. This is a temporary restriction. In 3.6 beta 2, the plan is to again allow backslashes in the string parts of f-strings, but disallow them in the expression parts.
https://hg.python.org/cpython/rev/d7ce127b5c0f
msg274295 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2016-09-03 13:24
See issue 27948 for adding backslashes back in to the string parts of an f-string.
msg274296 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-03 14:43
New changeset 899ee1e68a8d by Eric V. Smith in branch 'default':
Issue 27921: Remove backslash from another f-string.
https://hg.python.org/cpython/rev/899ee1e68a8d
msg274301 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-03 15:07
New changeset 80eb6eb57537 by Eric V. Smith in branch 'default':
Issue 27921: Remove backslash from another f-string. I'll revert this change before beta 2.
https://hg.python.org/cpython/rev/80eb6eb57537
msg274309 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-03 16:33
New changeset fd4e4fa75260 by Eric V. Smith in branch 'default':
Issue 27921: Remove backslash from another f-string. I'll revert this change before beta 2. I also need to look in to why test_tools/test_unparse fails with the files that are now being skipped.
https://hg.python.org/cpython/rev/fd4e4fa75260
msg274329 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-09-03 22:49
I haven’t looked, but my guess at why test_unparse could fail would be trying to generate code for an f-string with control characters in. Maybe it is taking stuff like

f'''{x}
{y}
'''

and generating

f'{x}\n{y}\n'
msg274416 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-05 18:13
New changeset df5b6d1c7ea8 by Benjamin Peterson in branch 'default':
fix skipping #27921 for windows
https://hg.python.org/cpython/rev/df5b6d1c7ea8
msg274839 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2016-09-07 17:07
The problem with test_unparse is that:
f'''{"'"}'''
becomes:
f'{"\'"}'
when it's run through Tools/parser/unparse.py.

I'll open another issue for this.
msg274843 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2016-09-07 17:19
Issue 28002 tracks the problem with Tools/parser/unparse.py.
History
Date User Action Args
2022-04-11 14:58:35adminsetgithub: 72108
2016-09-07 17:19:58eric.smithsetmessages: + msg274843
2016-09-07 17:07:26eric.smithsetmessages: + msg274839
2016-09-05 18:13:32python-devsetmessages: + msg274416
2016-09-03 22:49:22martin.pantersetnosy: + martin.panter
messages: + msg274329
2016-09-03 16:33:48python-devsetmessages: + msg274309
2016-09-03 15:07:33python-devsetmessages: + msg274301
2016-09-03 14:43:28python-devsetmessages: + msg274296
2016-09-03 13:24:42eric.smithsetmessages: + msg274295
2016-09-03 13:18:41python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg274293

resolution: fixed
stage: patch review -> resolved
2016-09-02 12:08:27eric.smithsetfiles: + 27921-1.patch

messages: + msg274235
2016-09-01 19:28:28serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg274172
2016-09-01 10:32:55barrysetnosy: + barry
2016-09-01 00:41:30eric.smithsetfiles: + 27921.patch
keywords: + patch
2016-09-01 00:40:33eric.smithsetstage: patch review
2016-08-31 23:49:40eric.smithcreate