I’m finally back from vacation and have had a chance to read the PEP and this thread. I appreciate the deep thought and effort that went into the PEP and reference implementation, and I’ve been talking with Jim about this idea on and off for a few years, but I have to say with all due respect, that I’m unconvinced this is a good idea.
For background, I pioneered internationalization in one of the first Python applications to support it (GNU Mailman). For that, I wrote string.Template
(and PEP 292) and sys._getframe()
, maintained pygettext
before GNU gettext supported Python, and am the author of the flufl.i18n library for sophisticated i18n support in Python programs.
Early on there were conversations about using i
as a “tag” for translatable strings. This preceded f-strings by several years, and would have been difficult to implement at the time, so for that reason and others, I adopted the C/gettext convention of using the _()
function. Note though that for i18n’d Python programs using flufl.i18n
this is just a convention and not a requirement. Likewise, string.Template
’s convention (and thus default) of using $placeholder
syntax was a deliberate choice for simplicity, as described in PEP 292, and is also customizable by subclassing.
So putting all that together, what I find lacking in PEP 750 is a strong argument explaining why function calls are not sufficient for the use cases this PEP intends to enable.
I have to also admit to cringing at the syntax, and worry deeply about the cognitive load this will add to readability . I think it will also be difficult to reason about such code. I don’t think the PEP addresses this sufficiently in the “How to Teach This” section. And I think history bears out my suspicion that you won’t be able to ignore this new syntax until you need it, because if it’s possible to do, a lot of code will find clever new ways to use it and the syntax will creep into a lot of code we all end up having to read.
From my experience with i18n, I also don’t think you will actually be able to use PEP 750 tag strings for i18n, for the simple reason that string fragments cannot be translated. At least, not for every human language you would want to support. The only way to do that is to translate full sentences, because placeholder positions can change in the translated string, and because there are some languages where sentence fragments simply do not make sense. I could be misunderstanding how tag strings work, but let’s say that you wanted to use this for i18n and actually wrote an i
tag for these, if you had a string like i"The $ordinal test message $name"
, if your translation layer and your human translators didn’t have access to the full source string, but only fragments, the source string would effectively be untranslatable.
I’ll also mention that flufl.i18n supports deferred translations which I think – but am not positive – are equivalent to the PEP’s lazy evaluation proposal.
This post is already probably too long, so I’ll leave it there for now.