-
-
Notifications
You must be signed in to change notification settings - Fork 177
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
Rewriting within f-strings #572
Comments
the first hard blocker is the ast does not accurately indicate positions inside f-strings inside the current versions supported so it's difficult to even start approaching this problem (as such I haven't even attempted it) an idea though, since we have a format string parser already, is to identify the f-strings during a tokenize pass and rewrite each of their format chunks separately? it may work (and potentially avoids the incorrect offsets) |
Yeah that was what I poorly explained as "recursively invoke rewriting". I will look at trying it in django-upgrade first. |
I believe https://peps.python.org/pep-0701/ Syntactic formalization of f-strings |
Seems no one is working on the new tokenizer. The tokenizer in Python will still emit the old tokens. (sometimes buggy with new grammar) |
This is not correct, we are indeed working on changes to the python tokenizer and we plan to emit the new tokens there |
Thanks Python 3.12! |
This issue also affects django-upgrade: adamchainz/django-upgrade#97
pyupgrade rewrites some names, so we might expect it to do so inside f-strings:
Unfortunately it fails to do so. This is because there's no tokens for the contents of the f-string. Whilst the AST includes the f-strings, the tokenizer leaves the f-string as a single
STRING
. It's later tokenized insideast.parse
:Perhaps a fix would be to recursively invoke rewriting on f-string nodes.
The text was updated successfully, but these errors were encountered: