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: fstring with quotation marks conflict
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: Seaky Lone, eric.smith
Priority: normal Keywords:

Created on 2019-08-22 01:02 by Seaky Lone, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg350147 - (view) Author: Seaky Lone (Seaky Lone) Date: 2019-08-22 01:02
For example, I have the following code:

something = 'some thing'
string = f'some text {something.split(' ')}'

The second expression is thought to be invalid because it is regarded as two strings ['some text {something.split(', ')}']. I have to change either pair of '' to "" in order to make things work.
I think this should not be an invalid expression because the ' ' or any other expressions inside the {} should be independent of the outer ''.
msg350150 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2019-08-22 01:11
The lexer sees an f-string:
f'some text {something.split('
next to a normal string:
')}'

The first of those is not a valid f-string because of the unmatched left brace, so it's an error.

I'm contemplating making the f-string parser smarter to be able to detect this, but it's a long way off.

For an explanation of why it works the way it does currently, see https://mail.python.org/archives/list/python-dev@python.org/message/BDZCXGRW5KTUOGMRT6OHH6S3UD4BV5ZV/ . This post also has an example similar to yours.
History
Date User Action Args
2022-04-11 14:59:19adminsetgithub: 82093
2019-08-22 01:11:12eric.smithsetstatus: open -> closed

type: behavior
assignee: eric.smith

nosy: + eric.smith
messages: + msg350150
resolution: not a bug
stage: resolved
2019-08-22 01:02:04Seaky Lonecreate