Thanks for the comments on our proposal. I’m going to respond specifically to comments by @erictraut , @godlygeek , @barry , and @ncoghlan , although I’m sure I’m missing some of this discussion, and see how we can improve this proposed PEP:
- Tag functions are called with a
TemplateConcreteobject, which is builtin, with a runtime-checkable protocolTemplateprovided fromtyping.Templateprovidesargs(as now) andsource(original string passed into the tag string) as attributes. One nice thing about thesourceattribute is that it can be used as a memoization key, and of course requires no additional computation. Hopefully it can also be used for i18n purposes. - Tag functions can be decorated with
@tag_evaluation('eager' | 'choice' | 'deferred'); useLiteralfor these choices; this decorator is available fromtyping. This decorator sets a dunder method,__tag_evaluation__.eageris the usual evaluation order, and the tag function guarantees it does this upon entry.'choice'means that the tag function chooses which interpolations to evaluate, if any, in any order, before returning, but it does not retain the interpolation after it returns.deferredallows for the interpolations to be seen outside the scope of the tag function. Hopefully this decorator can support typing needs. - No short prefix names, however if dotted names are added, there’s no such restriction for a dotted name. So
lazy.fis a valid tag name. - It might be desirable to have a
tprefix, which simply returns aTemplate. I assume this will have eager evaluation semantics. (There are additional aspects discussed, but these seem to require additional enhancements to the interpolation syntax; that can be discussed separately.)