[issue46307] string.Template should allow inspection of identifiers

Ben Kehoe report at bugs.python.org
Sat Jan 8 21:51:18 EST 2022


Ben Kehoe <ben at kehoe.io> added the comment:

Happy to make a PR! In my mind I had been thinking it would be the get_identifiers() method with the implementation above, returning a list.

As for __iter__, I'm less clear on what that would look like:

t = string.Template(...)
for identifier in t:
  # what would I do here?
  # would it include repeats if they appear more than once in the template?

I guess there are two ways to think about it: one is "what identifiers are in this template?" which I think should return a list with no repeats, which I can then iterate over or check if a value is in it. The other is, "what are the contents of the template?" in the style of string.Formatter.parse().

Given that string.Template is supposed to be the "simple, no-frills" thing in comparison to string.Formatter, I see less use for the latter option.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46307>
_______________________________________


More information about the Python-bugs-list mailing list