mirror of
https://github.com/python/cpython.git
synced 2025-11-01 14:11:41 +00:00
[3.13] gh-129958: Properly disallow newlines in format specs in single-quoted f-strings (GH-130063) (GH-132692)
(cherry picked from commit 2f8b08da47)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
parent
ca2e1a1e1c
commit
a37d719d37
4 changed files with 39 additions and 31 deletions
|
|
@ -1784,6 +1784,31 @@ def test_gh129093(self):
|
|||
self.assertEqual(f'{f'{1!=2=}'=}', "f'{1!=2=}'='1!=2=True'")
|
||||
self.assertEqual(f'{f'{1 != 2=}'=}', "f'{1 != 2=}'='1 != 2=True'")
|
||||
|
||||
def test_newlines_in_format_specifiers(self):
|
||||
cases = [
|
||||
"""f'{1:d\n}'""",
|
||||
"""f'__{
|
||||
1:d
|
||||
}__'""",
|
||||
'''f"{value:.
|
||||
{'2f'}}"''',
|
||||
'''f"{value:
|
||||
{'.2f'}f}"''',
|
||||
'''f"{value:
|
||||
#{'x'}}"''',
|
||||
]
|
||||
self.assertAllRaise(SyntaxError, "f-string: newlines are not allowed in format specifiers", cases)
|
||||
|
||||
valid_cases = [
|
||||
"""f'''__{
|
||||
1:d
|
||||
}__'''""",
|
||||
"""f'''{1:d\n}'''""",
|
||||
]
|
||||
|
||||
for case in valid_cases:
|
||||
compile(case, "<string>", "exec")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue