gh-104658: Fix location of unclosed quote error for multiline f-strings (#104660)

This commit is contained in:
Pablo Galindo Salgado 2023-05-20 14:07:05 +01:00 committed by GitHub
parent 663c049ff7
commit ff7f731632
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View file

@ -1558,7 +1558,21 @@ x = (
self.assertAllRaise(SyntaxError, "unterminated f-string literal", ['f"', "f'"])
self.assertAllRaise(SyntaxError, "unterminated triple-quoted f-string literal",
['f"""', "f'''"])
# Ensure that the errors are reported at the correct line number.
data = '''\
x = 1 + 1
y = 2 + 2
z = f"""
sdfjnsdfjsdf
sdfsdfs{1+
2} dfigdf {3+
4}sdufsd""
'''
try:
compile(data, "?", "exec")
except SyntaxError as e:
self.assertEqual(e.text, 'z = f"""')
self.assertEqual(e.lineno, 3)
def test_syntax_error_after_debug(self):
self.assertAllRaise(SyntaxError, "f-string: expecting a valid expression after '{'",
[