mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-29104: Fixed parsing backslashes in f-strings. (#490)
This commit is contained in:
parent
d1c3c13fed
commit
0cd7a3f196
3 changed files with 48 additions and 21 deletions
|
@ -361,6 +361,20 @@ f'{a * x()}'"""
|
|||
self.assertEqual(f'2\x203', '2 3')
|
||||
self.assertEqual(f'\x203', ' 3')
|
||||
|
||||
with self.assertWarns(DeprecationWarning): # invalid escape sequence
|
||||
value = eval(r"f'\{6*7}'")
|
||||
self.assertEqual(value, '\\42')
|
||||
self.assertEqual(f'\\{6*7}', '\\42')
|
||||
self.assertEqual(fr'\{6*7}', '\\42')
|
||||
|
||||
AMPERSAND = 'spam'
|
||||
# Get the right unicode character (&), or pick up local variable
|
||||
# depending on the number of backslashes.
|
||||
self.assertEqual(f'\N{AMPERSAND}', '&')
|
||||
self.assertEqual(f'\\N{AMPERSAND}', '\\Nspam')
|
||||
self.assertEqual(fr'\N{AMPERSAND}', '\\Nspam')
|
||||
self.assertEqual(f'\\\N{AMPERSAND}', '\\&')
|
||||
|
||||
def test_misformed_unicode_character_name(self):
|
||||
# These test are needed because unicode names are parsed
|
||||
# differently inside f-strings.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue