My input is a string containing an evaluable expression, a potential
= sign, a potential !s, !a or !r flag, and a format information (which follows
: in f-string syntax).
I want to create an f-string AST node/tree which would compile to the same bytecode that the original f-string would.
The problem is, first, that it’s very hard to understand which AST node type goes where. In particular, AST-ing the string containing the expression and putting it in a FormattedValue node directly, doesn’t work. And also, the format information is itself a JoinedStr node, the same type as the all-encompassing node…
If someone has a clear explanation for how it works
Second, that the equal sign seems to be swallowed by AST internally (since the AST generated from an f-string containing
= will look no different, through any documented attribute access, to the AST of an f-string without the
=). It seems that it relies on an undocumented part of the node which saves it, without exposing it or allowing it to be manually emulated (or added or removed from AST nodes created from a parse). Can someone confirm that ?
Lastly, there seemed to be an additional issue with filenames and line numbers, but I think it stems from my first point of having a dysfunctional AST tree which fix_missing_locations then fails to apply to.