bpo-41076: Pre-feed the parser with the f-string expression location#21054
Conversation
This PR changes the parsing of f-string expressions with the new parser. The parser gets pre-fed with the location of the expression itself (not the f-string, which was what we were doing before). This allows us to completely skip the shifting of the AST nodes after the parsing is completed.
|
Wow, this is an excellent insight and looks fantastic! I can try to review it later tomorrow but I have an initial question: Since we are storing the offset in fstring_col_offset, what happens with nested f-strings? Every parser instance has its own 'fstring_col_offset' and therefore they will not collide or there is something to consider on the propagation of these values? |
Nested f-strings should be handled correctly already. I checked
Nested f-strings are no problem because Does this make sense? |
|
Although is not caused by this PR, I noticed that we have some inconsistency with the old parser regarding f-strings. For instance: |
|
Oh, this is a bug that needs to be fixed. I think I know what's causing it. |
|
I realised that there was a bug in my implementation, in case the fstring wasn't starting at offset 0 (when we compute the offset of the caret in the error text, we also need to account for all the characters before the f-string, in case it's not at offset 0). The fix also fixes the bug @pablogsal mentioned above, so that's a win-win. |
|
Closing and reopening to trigger the CI again |
|
Thanks @lysnikolaou for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
|
Sorry, @lysnikolaou and @pablogsal, I could not cleanly backport this to |
…ation (pythonGH-21054) This commit changes the parsing of f-string expressions with the new parser. The parser gets pre-fed with the location of the expression itself (not the f-string, which was what we were doing before). This allows us to completely skip the shifting of the AST nodes after the parsing is completed.. (cherry picked from commit 1f0f4ab) Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
|
GH-21190 is a backport of this pull request to the 3.9 branch. |
…ation (GH-21054) (GH-21190) This commit changes the parsing of f-string expressions with the new parser. The parser gets pre-fed with the location of the expression itself (not the f-string, which was what we were doing before). This allows us to completely skip the shifting of the AST nodes after the parsing is completed.. (cherry picked from commit 1f0f4ab)
|
🎉 🎉 I feel like this is one of the most major improvements we've had lately. Thanks for the review @pablogsal! |
Yeah, me too! This was a very good insight and a great job. Well done! |
…ythonGH-21054) This commit changes the parsing of f-string expressions with the new parser. The parser gets pre-fed with the location of the expression itself (not the f-string, which was what we were doing before). This allows us to completely skip the shifting of the AST nodes after the parsing is completed.
This PR changes the parsing of f-string expressions with the new
parser. The parser gets pre-fed with the location of the expression
itself (not the f-string, which was what we were doing before). This
allows us to completely skip the shifting of the AST nodes after
the parsing is completed.
https://bugs.python.org/issue41076