This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author barry
Recipients barry, ben11kehoe
Date 2022-01-09.03:28:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <F00EC0B6-AAE6-43E4-87EA-DCC948401BF2@python.org>
In-reply-to <1641696678.53.0.726743058591.issue46307@roundup.psfhosted.org>
Content
I think you’re right that the iterator API isn’t very helpful.  I also agree that you probably really want to answer the “why identifiers are in this template?” question.  As for repeats, there’s two ways to think about it.  You could return all the identifiers in the order in which they’re found in the template (and you can unique-ify them if you want by passing that list to set()).  But maybe you don’t really need that either.

get_identifiers() works for me!

On Jan 8, 2022, at 18:51, Ben Kehoe <report@bugs.python.org> wrote:
> 
> Ben Kehoe <ben@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.
History
Date User Action Args
2022-01-09 03:28:17barrysetrecipients: + barry, ben11kehoe
2022-01-09 03:28:16barrylinkissue46307 messages
2022-01-09 03:28:16barrycreate