-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
Description
Feature or enhancement
Proposal:
Internally, you store strings and interpolations as separate attributes. However the constructor to Template requires them to be passed as a long tuple of positional arguments (which then gets manually separated out).
For the likely Cython implementation it (probably) also makes sense to generate the strings and templates separately. For CPython modules it's possible to get _PyTemplate_Build out of the internal headers and use that. However that doesn't help for the Limited API.
In this case we have to go go through the Python constructor of Template - that's reasonable except that we have to do a lot of work zipping strings and interpolations into a single tuple so that the constructor of Template can then undo all the work putting them back.
It would be useful to have an interface to construct a Template from two iterables of strings and interpolations. I'd be happy with this being a Python API (rather than a C API). My initial proposal would be to define Template.__new__ as Template.__new__(cls, *args, strings=None, interpolations=None) and make it an error to pass both args and the keyword arguments in the same call.
Obviously there's multiple ways to implement Template and in future you might prefer not to separate the two. In this case the API I'm proposing would still work but no longer be the most efficient way to build it - I don't think this is a problem.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response