Eric V. Smith <[email protected]> added the comment:
For what it's worth, here's how f-strings with the "=" feature work:
I remember the char* pointer where the expression starts, then I parse the
expression into an AST, then I note the char* pointer where the expression
ended. The text between those is what's output before the equal sign []. This
is how I preserve all of the whitespace inside the expression.
In my case I keep the AST to use when the expression gets evaluated, but in the
string annotation case you'd throw it away. I don't think it would be very
complicated to make this approach work across newlines.
[] Actually, I keep the equal sign itself and whitespace to the right of it,
which is how f'{ x = }' produces " x = 42", instead of "x=42".
----------
nosy: +eric.smith
resolution: rejected ->
stage: resolved ->
status: closed -> open
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41967>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com