-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Self-documenting f-string in conversion specifier throws ValueError #121130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hummm, I think this is a bug in 3.11 or at least some undefined situation. For example, with
|
There is not even an |
@pablogsal I think that's the expected result, note that the self-documenting string is passed to
I don't know when this would be practically useful but I think it's at least consistent behavior. |
Oh, I see! It's certainly surprising but I can see how this happens now much better! Thanks |
CC @lysnikolaou WDYT? |
We can fix this in the lexer, but this violates some assumptions (that only the topmost level can have debug expressions) so the fix is quite involved unless I am missing something. |
I will try to give this a go to see if there is some easy way to handle this |
It's definitely an odd use case, but I think it should work. When testing, I often use datetime, since it's format spec is (mostly) pass-through: >>> import datetime
>>> y = 3
>>> f'{datetime.datetime.now():{y=}}'
'y=3' |
…ressions (pythonGH-121150) (cherry picked from commit c46d64e) Co-authored-by: Pablo Galindo Salgado <[email protected]>
…ressions (pythonGH-121150) (cherry picked from commit c46d64e) Co-authored-by: Pablo Galindo Salgado <[email protected]>
Bug report
Bug description:
Since Python 3.12, the compiler throws a ValueError when compiling a string like
f"{x:{y=}}"
:Note this is a compile-time error; you also see it if you call
compile()
orast.parse()
. I would not expect the compiler to ever throw ValueError.On 3.11, this works as I'd expect:
I don't have a use case for this, but came across it while exploring f-string syntax.
cc @ericvsmith for f-strings and @pablogsal because this feels related to PEP 701
CPython versions tested on:
3.12, CPython main branch
Operating systems tested on:
macOS
Linked PRs
The text was updated successfully, but these errors were encountered: