[issue46307] string.Template should allow inspection of identifiers

Ben Kehoe report at bugs.python.org
Sun Jan 9 17:20:41 EST 2022


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

The point is to be able to programmatically determine what is needed for a
successful substitute() call. A basic use case for this is better error
messages; calling substitute() with an incomplete mapping will tell you
only the first missing identifier it encounters; if you know all the
identifiers you can raise an error about all the missing identifiers.
Another error handling use case is checking whether the template is valid,
without needing to provide a complete mapping. A use case unrelated to
error handling that I’ve encountered a few times is interactive prompting
for template values, which you can only do if you can get a list of the
identifiers in the template.

----------

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


More information about the Python-bugs-list mailing list