-
Notifications
You must be signed in to change notification settings - Fork 453
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
Add f-string parsing for Python 3.12 (PEP 701) #1027
Conversation
Not sure if y'all want to add 3.12 to the CI yet? |
Thanks. I can confirm that with this patch, the tests pass both on 3.11 and 3.12. |
Codecov Report
@@ Coverage Diff @@
## master #1027 +/- ##
==========================================
- Coverage 90.94% 90.78% -0.17%
==========================================
Files 25 25
Lines 4375 4393 +18
==========================================
+ Hits 3979 3988 +9
- Misses 396 405 +9
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
be26d03
to
1f06b36
Compare
Since Python 3.12, f-strings are tokenized and parsed like the rest of Python's grammar, using the new tokens FSTRING_START, FSTRING_MIDDLE and FSTRING_END. Make the babel message extractor concatenate these three if they're adjacent to each other. If they're not, that means there are dynamic substitutions, so the f-string is ignored.
1f06b36
to
8260a4d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I tested this locally on 3.12 and seems to work great. I took the liberty of fixing the lint fail too.
Working on that in #1028 :) |
how to use? In babel 2.14.0, the code can't be extracted to .pot file:
|
in the code above, extract ok, but not translated by gettext. |
Since Python 3.12, f-strings are tokenized and parsed like the rest of Python's grammar, using the new tokens
FSTRING_START
,FSTRING_MIDDLE
andFSTRING_END
, as described in pep 701 #new-tokens.Make the babel message extractor concatenate these three if they're adjacent to each other. If they're not, that means there are dynamic substitutions, so the f-string is ignored.