summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorBen Kehoe <bkehoe@irobot.com>2022-01-11 19:15:42 (GMT)
committerGitHub <noreply@github.com>2022-01-11 19:15:42 (GMT)
commitdce642f24418c58e67fa31a686575c980c31dd37 (patch)
tree90e9eb86f921027c33819c29490de8be68990b56 /Doc
parentcf496d657a1a82eaf9ebfb47d721676fef6effa5 (diff)
downloadcpython-dce642f24418c58e67fa31a686575c980c31dd37.zip
cpython-dce642f24418c58e67fa31a686575c980c31dd37.tar.gz
cpython-dce642f24418c58e67fa31a686575c980c31dd37.tar.bz2
bpo-46307: Add string.Template.get_identifiers() method (GH-30493)
Add `string.Template.get_identifiers()` method that returns the identifiers within the template. By default, raises an error if it encounters an invalid identifier (like `substitute()`). The keyword-only argument `raise_on_invalid` can be set to `False` to ignore invalid identifiers (like `safe_substitute()`). Automerge-Triggered-By: GH:warsaw
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/string.rst19
1 files changed, 19 insertions, 0 deletions
diff --git a/Doc/library/string.rst b/Doc/library/string.rst
index b27782f..9bc703e 100644
--- a/Doc/library/string.rst
+++ b/Doc/library/string.rst
@@ -783,6 +783,22 @@ these rules. The methods of :class:`Template` are:
templates containing dangling delimiters, unmatched braces, or
placeholders that are not valid Python identifiers.
+
+ .. method:: is_valid()
+
+ Returns false if the template has invalid placeholders that will cause
+ :meth:`substitute` to raise :exc:`ValueError`.
+
+ .. versionadded:: 3.11
+
+
+ .. method:: get_identifiers()
+
+ Returns a list of the valid identifiers in the template, in the order
+ they first appear, ignoring any invalid identifiers.
+
+ .. versionadded:: 3.11
+
:class:`Template` instances also provide one public data attribute:
.. attribute:: template
@@ -869,6 +885,9 @@ rule:
* *invalid* -- This group matches any other delimiter pattern (usually a single
delimiter), and it should appear last in the regular expression.
+The methods on this class will raise :exc:`ValueError` if the pattern matches
+the template without one of these named groups matching.
+
Helper functions
----------------