mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-30978: str.format_map() now passes key lookup exceptions through. (#2790)
Previously any exception was replaced with a KeyError exception.
This commit is contained in:
parent
25e4f779d7
commit
5075416b8f
4 changed files with 20 additions and 7 deletions
|
@ -1278,6 +1278,13 @@ class UnicodeTest(string_tests.CommonTest,
|
|||
self.assertRaises(ValueError, '{}'.format_map, 'a')
|
||||
self.assertRaises(ValueError, '{a} {}'.format_map, {"a" : 2, "b" : 1})
|
||||
|
||||
class BadMapping:
|
||||
def __getitem__(self, key):
|
||||
return 1/0
|
||||
self.assertRaises(KeyError, '{a}'.format_map, {})
|
||||
self.assertRaises(TypeError, '{a}'.format_map, [])
|
||||
self.assertRaises(ZeroDivisionError, '{a}'.format_map, BadMapping())
|
||||
|
||||
def test_format_huge_precision(self):
|
||||
format_string = ".{}f".format(sys.maxsize + 1)
|
||||
with self.assertRaises(ValueError):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue