aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_string/test_templatelib.py
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2025-05-17 12:23:19 -0700
committerGitHub <noreply@github.com>2025-05-17 12:23:19 -0700
commitfc7f4c36664314393bd4c30355e21bd7aeac524d (patch)
treed91d2dfb0b22e8672191d3a201d019f378d5e733 /Lib/test/test_string/test_templatelib.py
parent84914ad0e5f96f0ca7238f3b4bc7fc4e50b1abb3 (diff)
downloadcpython-fc7f4c36664314393bd4c30355e21bd7aeac524d.tar.gz
cpython-fc7f4c36664314393bd4c30355e21bd7aeac524d.zip
gh-134119: Fix crash from calling next() on exhausted template iterator (#134120)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_string/test_templatelib.py')
-rw-r--r--Lib/test/test_string/test_templatelib.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/test/test_string/test_templatelib.py b/Lib/test/test_string/test_templatelib.py
index 5b9490c2be6..85fcff486d6 100644
--- a/Lib/test/test_string/test_templatelib.py
+++ b/Lib/test/test_string/test_templatelib.py
@@ -148,6 +148,13 @@ class TemplateIterTests(unittest.TestCase):
self.assertEqual(res[1].format_spec, '')
self.assertEqual(res[2], ' yz')
+ def test_exhausted(self):
+ # See https://github.com/python/cpython/issues/134119.
+ template_iter = iter(t"{1}")
+ self.assertIsInstance(next(template_iter), Interpolation)
+ self.assertRaises(StopIteration, next, template_iter)
+ self.assertRaises(StopIteration, next, template_iter)
+
if __name__ == '__main__':
unittest.main()