Message410112
Currently, the only thing that can be done with a string.Template instance and a mapping is either attempt to substitute with substitute() and catch a KeyError if some identifier has not been provided in the mapping, or substitute with safe_substitute() and not know whether all identifiers were provided.
I propose adding a method that returns the identifiers in the template. Because the template string and pattern are exposed, this is already possible as a separate function:
def get_identifiers(template):
return list(
set(
filter(
lambda v: v is not None,
(mo.group('named') or mo.group('braced')
for mo in template.pattern.finditer(template.template))
)
)
)
However, this function is not easy for a user of string.Template to construct without learning how the template pattern works (which is documented but intended to be learned only when subclassing or modifying id patterns).
As a method on string.Template, this would enable use cases like more comprehensive error handling (e.g., finding all missing mapping keys at once) or interactive prompting. |
|
Date |
User |
Action |
Args |
2022-01-08 20:12:29 | ben11kehoe | set | recipients:
+ ben11kehoe |
2022-01-08 20:12:29 | ben11kehoe | set | messageid: <1641672749.81.0.761758582979.issue46307@roundup.psfhosted.org> |
2022-01-08 20:12:29 | ben11kehoe | link | issue46307 messages |
2022-01-08 20:12:29 | ben11kehoe | create | |
|