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:
Serhiy Storchaka 2017-08-03 11:45:23 +03:00 committed by GitHub
parent 25e4f779d7
commit 5075416b8f
4 changed files with 20 additions and 7 deletions

View file

@ -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):