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.

Title: IDLE doesn't highlight f-strings properly
Type: behavior Stage: resolved
Components: IDLE Versions: Python 3.7, Python 3.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: Kenzie Togami, ammar2, python-dev, serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2016-12-26 01:16 by Kenzie Togami, last changed 2022-04-11 14:58 by admin. This issue is now closed.

File name Uploaded Description Edit
python_idle_3.6_bug.png Kenzie Togami, 2016-12-26 01:16 Screenshot of f- and r- strings in IDLE
idle-f-string-highlight.diff ammar2, 2016-12-26 23:38 review
Messages (11)
msg284010 - (view) Author: Kenzie Togami (Kenzie Togami) Date: 2016-12-26 01:16
IDLE doesn't highlight f-strings like r-strings or u-strings. See the attached screenshot.
msg284051 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2016-12-26 23:38
I've attached a patch that colorizes f-strings.

The issue is marked as "test needed" which the dev guide says "... reporter should post a script or instructions to let a triager or developer reproduce the issue." 

Steps to re-create are to open an IDLE window and type in the code
and notice the colorization difference.
msg284062 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-12-27 05:05
New changeset a48cc85e5706 by Terry Jan Reedy in branch '3.6':
Issue #29071: IDLE now colors f-string prefixes (but not invalid ur prefixes).
msg284064 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-12-27 05:20
There are 10 possible f-string prefixes, including combinations with r/R.  See

While adding these, I noticed that IDLE was coloring now invalid ur prefixes and deleted those.

I decided to test by modifying the existing human visual htest.

Ammar: thank you for submitting a patch.  It happens that I wrote my patch before I saw your submission.  If I had seen yours first, I might have given you a chance to finish it.  Feel free to try another IDLE issue.
msg284065 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2016-12-27 05:44
Not a problem, thank you for the encouragement.
msg284420 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-01-01 06:35
The regular expression can be simplified using local flags:

-    stringprefix = (r"(\br|R|u|U|f|F|fr|Fr|fR|FR|rf|rF|Rf|RF"
-                    "|b|B|br|Br|bR|BR|rb|rB|Rb|RB)?")
+    stringprefix = r"(?i:\br|u|f|fr|rf|b|br|rb)?"
msg284439 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-01-02 02:22
New changeset 62d3c0336df6 by Terry Jan Reedy in branch '3.6':
Issue #29071: Use local flags for IDLE colorizer string prefix matcher.
msg284440 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-01-02 02:24
Thank you for the new feature (I presume) and its application.  I disliked both writing and reading all the near duplication.  I am posting this to python-list as an example of what the new feature is good for.
msg284472 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-01-02 07:06
Thank you for advertising  the new feature. Would you like to improve the 
documentation? It always was the hardest part to me.
msg284479 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-01-02 12:34
The doc appears to be carefully accurate, but the second sentence especially is a bit awkward.  I will open a new issue.
msg291284 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-04-07 18:30
#29287 is about syntax highlighting the code within f-strings as code rather than as part of the string.
Date User Action Args
2022-04-11 14:58:41adminsetgithub: 73257
2017-04-07 18:30:17terry.reedysetmessages: + msg291284
2017-01-02 12:34:52terry.reedysetmessages: + msg284479
2017-01-02 07:06:47serhiy.storchakasetmessages: + msg284472
2017-01-02 02:24:52terry.reedysetmessages: + msg284440
2017-01-02 02:22:10python-devsetmessages: + msg284439
2017-01-01 06:35:59serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg284420
2016-12-27 05:44:40ammar2setmessages: + msg284065
2016-12-27 05:20:10terry.reedysetstatus: open -> closed
resolution: fixed
messages: + msg284064

stage: patch review -> resolved
2016-12-27 05:05:58python-devsetnosy: + python-dev
messages: + msg284062
2016-12-26 23:38:36ammar2setfiles: + idle-f-string-highlight.diff

nosy: + ammar2
messages: + msg284051

keywords: + patch
stage: test needed -> patch review
2016-12-26 07:15:00terry.reedysetstage: test needed
versions: + Python 3.7
2016-12-26 01:16:18Kenzie Togamicreate