Issue #23671: string.Template now allows to specify the "self" parameter as
keyword argument. string.Formatter now allows to specify the "self" and
the "format_string" parameters as keyword arguments.
diff --git a/Lib/test/test_pep292.py b/Lib/test/test_pep292.py
index 5ff280d..133cab7 100644
--- a/Lib/test/test_pep292.py
+++ b/Lib/test/test_pep292.py
@@ -26,6 +26,7 @@
self.assertEqual(s.substitute(dict(who='tim', what='ham')),
'tim likes to eat a bag of ham worth $100')
self.assertRaises(KeyError, s.substitute, dict(who='tim'))
+ self.assertRaises(TypeError, Template.substitute)
def test_regular_templates_with_braces(self):
s = Template('$who likes ${what} for ${meal}')
@@ -178,6 +179,9 @@
eq(s.substitute(dict(mapping='one'), mapping='two'),
'the mapping is two')
+ s = Template('the self is $self')
+ eq(s.substitute(self='bozo'), 'the self is bozo')
+
def test_keyword_arguments_safe(self):
eq = self.assertEqual
raises = self.assertRaises
@@ -196,6 +200,9 @@
raises(TypeError, s.substitute, d, {})
raises(TypeError, s.safe_substitute, d, {})
+ s = Template('the self is $self')
+ eq(s.safe_substitute(self='bozo'), 'the self is bozo')
+
def test_delimiter_override(self):
eq = self.assertEqual
raises = self.assertRaises