@@ -35,6 +35,18 @@ def test_formatting(self):
3535 string_tests .MixinStrUnicodeUserStringTest .test_formatting (self )
3636 self .assertRaises (OverflowError , '%c' .__mod__ , 0x1234 )
3737
38+ @test_support .cpython_only
39+ def test_formatting_huge_precision (self ):
40+ from _testcapi import INT_MAX
41+ format_string = "%.{}f" .format (INT_MAX + 1 )
42+ with self .assertRaises (ValueError ):
43+ result = format_string % 2.34
44+
45+ def test_formatting_huge_width (self ):
46+ format_string = "%{}f" .format (sys .maxsize + 1 )
47+ with self .assertRaises (ValueError ):
48+ result = format_string % 2.34
49+
3850 def test_conversion (self ):
3951 # Make sure __str__() behaves properly
4052 class Foo0 :
@@ -371,6 +383,21 @@ def __format__(self, format_spec):
371383 self .assertRaises (ValueError , format , "" , "-" )
372384 self .assertRaises (ValueError , "{0:=s}" .format , '' )
373385
386+ def test_format_huge_precision (self ):
387+ format_string = ".{}f" .format (sys .maxsize + 1 )
388+ with self .assertRaises (ValueError ):
389+ result = format (2.34 , format_string )
390+
391+ def test_format_huge_width (self ):
392+ format_string = "{}f" .format (sys .maxsize + 1 )
393+ with self .assertRaises (ValueError ):
394+ result = format (2.34 , format_string )
395+
396+ def test_format_huge_item_number (self ):
397+ format_string = "{{{}:.6f}}" .format (sys .maxsize + 1 )
398+ with self .assertRaises (ValueError ):
399+ result = format_string .format (2.34 )
400+
374401 def test_format_auto_numbering (self ):
375402 class C :
376403 def __init__ (self , x = 100 ):
0 commit comments