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: SyntaxError when using dict key in fstring
Type: crash Stage: resolved
Components: Interpreter Core Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Samisafool, eric.smith, sobolevn
Priority: normal Keywords:

Created on 2022-01-08 07:54 by Samisafool, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test.py Samisafool, 2022-01-08 07:54
Messages (5)
msg410079 - (view) Author: Samisafool (Samisafool) Date: 2022-01-08 07:54
SyntaxError when using dict key in fstring

Attached is a python file where this bug is visible.
The error is different on CPython 3.8 and 3.9/3.10, interestingly.
Occurs on CPython 3.8-10 and PyPy 3.8 7.3.7

Not sure which component to select, never filed a python bug report before. Hopefully this is correct.
msg410081 - (view) Author: Nikita Sobolev (sobolevn) * (Python triager) Date: 2022-01-08 08:39
Can you please try this:

```
dict1 = {
        "key1": "test"
        }

print(dict1["key1"])

print(f"key1 is {dict1['key1']}!")
```

The problem with your code is that `dict1["key1"]` used the same quotes as `f""`.
msg410082 - (view) Author: Samisafool (Samisafool) Date: 2022-01-08 08:42
Is that intended behaviour? It works though.
msg410084 - (view) Author: Samisafool (Samisafool) Date: 2022-01-08 08:55
Huh, it does seem to be intentional.
msg410105 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-01-08 19:09
Yes, the behavior is intentional. It might be relaxed in the future.
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90463
2022-01-08 19:09:43eric.smithsetnosy: + eric.smith
messages: + msg410105
2022-01-08 08:55:38Samisafoolsetstatus: open -> closed
resolution: not a bug
messages: + msg410084

stage: resolved
2022-01-08 08:42:22Samisafoolsetmessages: + msg410082
2022-01-08 08:39:36sobolevnsetnosy: + sobolevn
messages: + msg410081
2022-01-08 07:54:07Samisafoolcreate