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: Inaccurate error message for f-string
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: 33306 Superseder:
Assigned To: serhiy.storchaka Nosy List: eric.smith, seblin, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2018-12-14 13:34 by seblin, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11161 merged serhiy.storchaka, 2018-12-14 16:12
Messages (6)
msg331827 - (view) Author: Sebastian Linke (seblin) Date: 2018-12-14 13:34
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> spam = 'spam'
>>> f'{spam[0}'
  File "<stdin>", line 1
SyntaxError: f-string: expecting '}'

The error message seems wrong because a "]" is missing rather than a "}".
msg331828 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-12-14 14:04
I can take this issue if you do not mind.
msg331832 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-12-14 14:36
Go ahead, Serhiy. Thanks!
msg331833 - (view) Author: Sebastian Linke (seblin) Date: 2018-12-14 14:56
The same behavior applies to f'{spam[}' and f'{spam(}'. Also to f'{spam{}', but that might be expected.

This message is more clear:
>>> f'{spam('
  File "<stdin>", line 1
SyntaxError: f-string: mismatched '(', '{', or '['

Perhaps you want to apply that to the above error cases. Then you wouldn't have to catch any type of bracket. :-)
msg331839 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-12-14 16:13
PR 11161 uses an approach similar to issue33306.
msg333521 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-01-12 07:46
New changeset 58159ef856846d0235e0779aeb6013d70499570d by Serhiy Storchaka in branch 'master':
bpo-35494: Improve syntax error messages for unbalanced parentheses in f-string. (GH-11161)
https://github.com/python/cpython/commit/58159ef856846d0235e0779aeb6013d70499570d
History
Date User Action Args
2022-04-11 14:59:09adminsetgithub: 79675
2019-01-12 07:47:17serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-01-12 07:46:52serhiy.storchakasetmessages: + msg333521
2018-12-14 16:14:02serhiy.storchakasettype: enhancement
versions: + Python 3.8, - Python 3.7
2018-12-14 16:13:49serhiy.storchakasetdependencies: + Improving SyntaxError for unmatched parentheses
messages: + msg331839
2018-12-14 16:12:32serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request10397
2018-12-14 14:56:07seblinsetmessages: + msg331833
2018-12-14 14:36:25eric.smithsetassignee: eric.smith -> serhiy.storchaka
messages: + msg331832
2018-12-14 14:04:32serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg331828
2018-12-14 13:40:48eric.smithsetassignee: eric.smith

nosy: + eric.smith
2018-12-14 13:34:17seblincreate