Some of the converted strings into fstrings are no longer processed by babel
See original GitHub issueI’m using babel via a custom function _(string,language)
that outputs the translated version.
When running pyupgrade over the source files:
@@ -174,7 +173,7 @@ def irccommands(msgdetail):
)
else:
text = _(
- "Error opping users from chat %s: %s" % (chat_id, result),
+ f"Error opping users from chat {chat_id}: {result}",
language=mylang,
)
It causes babel to segfault as per https://github.com/python-babel/babel/issues/715
I would expect pyupgrade not to touch the code in a way that makes it later fail.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Pybabel should raise an error when it encounters f-strings #715
and Babel fails (as in it crashes with an exception) to extract strings from ... Some of the converted strings into fstrings are...
Read more >Babel Documentation - Read the Docs
While message catalogs allow you to localize any messages in your application, there are a number of strings that are used in many...
Read more >The Flask Mega-Tutorial Part XIII: I18n and L10n
Flask-Babel is initialized like most other Flask extensions: ... The simplest cases are those where literal strings appear in the source ...
Read more >In case you didn't know: Python 3.8 f-strings support = for self ...
Also, the format method is compatible with other libraries that process strings, for example when using Babel with Flask it can come handy....
Read more >Babel Changelog — Babel 2.11.0 documentation
The wheel file is no longer marked as universal, since Babel only supports Python 3. ... in some cases, as some more-or-less internal...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
you’re misusing translation – those strings aren’t being translated. if anything babel should produce an error for accidentally using string formatting inside of a translation function
babel will scan those (incorrectly) as
"Error opping users from chat %s: %s"
– then at runtime it will try and translate"Error opping users from chat whatever1: whatever2"
which will not match any of your translated IDs so you will always end up with english text. (we had a linter when I was at yelp which prevented this sort of translation misuse – but I believe it was proprietary / lost to closed source)Sounds like Babel doesn’t support f-strings, which is a Babel bug, not pyupgrade.
But can you use the pyupgrade
--keep-percent-format
option?