mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
Fix bug in passing tuples to string.Template. All other values (with working
str() or repr()) would work, just not multi-value tuples. Probably not a
backport candidate, since it changes the behaviour of passing a
single-element tuple:
>>> string.Template("$foo").substitute(dict(foo=(1,)))
'(1,)'
versus
'1'
This commit is contained in:
parent
9ba7ca8229
commit
add191118f
3 changed files with 14 additions and 3 deletions
|
|
@ -58,6 +58,13 @@ class TestTemplate(unittest.TestCase):
|
|||
s = Template('tim has eaten ${count} bags of ham today')
|
||||
eq(s.substitute(d), 'tim has eaten 7 bags of ham today')
|
||||
|
||||
def test_tupleargs(self):
|
||||
eq = self.assertEqual
|
||||
s = Template('$who ate ${meal}')
|
||||
d = dict(who=('tim', 'fred'), meal=('ham', 'kung pao'))
|
||||
eq(s.substitute(d), "('tim', 'fred') ate ('ham', 'kung pao')")
|
||||
eq(s.safe_substitute(d), "('tim', 'fred') ate ('ham', 'kung pao')")
|
||||
|
||||
def test_SafeTemplate(self):
|
||||
eq = self.assertEqual
|
||||
s = Template('$who likes ${what} for ${meal}')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue