mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-41681: Fix for f-string/str.format
error description when using 2 ,
in format specifier (GH-22036) (GH-22041)
* Fixed `f-string/str.format` error description when using two `,` in format specifier.
Co-authored-by: millefalcon <hanish0019@hmail.com>
(cherry picked from commit 0d6aa7f0ee
)
Co-authored-by: han-solo <hanish0019@gmail.com>
Co-authored-by: han-solo <hanish0019@gmail.com>
This commit is contained in:
parent
ca55ecbf9a
commit
c16a2a1b64
4 changed files with 46 additions and 2 deletions
|
@ -9,6 +9,7 @@
|
|||
|
||||
import ast
|
||||
import os
|
||||
import re
|
||||
import types
|
||||
import decimal
|
||||
import unittest
|
||||
|
@ -1208,6 +1209,25 @@ non-important content
|
|||
with self.assertRaisesRegex(SyntaxError, err_msg):
|
||||
compile("f'{a $ b}'", "?", "exec")
|
||||
|
||||
def test_with_two_commas_in_format_specifier(self):
|
||||
error_msg = re.escape("Cannot specify ',' with ','.")
|
||||
with self.assertRaisesRegex(ValueError, error_msg):
|
||||
f'{1:,,}'
|
||||
|
||||
def test_with_two_underscore_in_format_specifier(self):
|
||||
error_msg = re.escape("Cannot specify '_' with '_'.")
|
||||
with self.assertRaisesRegex(ValueError, error_msg):
|
||||
f'{1:__}'
|
||||
|
||||
def test_with_a_commas_and_an_underscore_in_format_specifier(self):
|
||||
error_msg = re.escape("Cannot specify both ',' and '_'.")
|
||||
with self.assertRaisesRegex(ValueError, error_msg):
|
||||
f'{1:,_}'
|
||||
|
||||
def test_with_an_underscore_and_a_comma_in_format_specifier(self):
|
||||
error_msg = re.escape("Cannot specify both ',' and '_'.")
|
||||
with self.assertRaisesRegex(ValueError, error_msg):
|
||||
f'{1:,_}'
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue