[3.13] gh-121804: always show error location for SyntaxError's in basic repl (GH-123202) (#123631)

gh-121804: always show error location for SyntaxError's in basic repl (GH-123202)
(cherry picked from commit 6822cb23c6)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-09-03 15:06:31 +02:00 committed by GitHub
parent d655c65561
commit 48941399e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 46 additions and 0 deletions

View file

@ -187,6 +187,19 @@ class TestInteractiveInterpreter(unittest.TestCase):
]
self.assertEqual(traceback_lines, expected_lines)
def test_runsource_show_syntax_error_location(self):
user_input = dedent("""def f(x, x): ...
""")
p = spawn_repl()
p.stdin.write(user_input)
output = kill_python(p)
expected_lines = [
' def f(x, x): ...',
' ^',
"SyntaxError: duplicate argument 'x' in function definition"
]
self.assertEqual(output.splitlines()[4:-1], expected_lines)
def test_interactive_source_is_in_linecache(self):
user_input = dedent("""
def foo(x):