aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_cmd_line_script.py
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2021-04-23 14:27:05 +0100
committerGitHub <noreply@github.com>2021-04-23 14:27:05 +0100
commita77aac4fca9723b8fd52a832f3e9df13beb25113 (patch)
treea504aa9fed91cd31849cdda3ecb1dad439a93778 /Lib/test/test_cmd_line_script.py
parent91b69b77cf5f78de6d35dea23098df34b6fd9e53 (diff)
downloadcpython-a77aac4fca9723b8fd52a832f3e9df13beb25113.tar.gz
cpython-a77aac4fca9723b8fd52a832f3e9df13beb25113.zip
bpo-43914: Highlight invalid ranges in SyntaxErrors (#25525)
To improve the user experience understanding what part of the error messages associated with SyntaxErrors is wrong, we can highlight the whole error range and not only place the caret at the first character. In this way: >>> foo(x, z for z in range(10), t, w) File "<stdin>", line 1 foo(x, z for z in range(10), t, w) ^ SyntaxError: Generator expression must be parenthesized becomes >>> foo(x, z for z in range(10), t, w) File "<stdin>", line 1 foo(x, z for z in range(10), t, w) ^^^^^^^^^^^^^^^^^^^^ SyntaxError: Generator expression must be parenthesized
Diffstat (limited to 'Lib/test/test_cmd_line_script.py')
-rw-r--r--Lib/test/test_cmd_line_script.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py
index 2e0b5f72c22..af29c171d42 100644
--- a/Lib/test/test_cmd_line_script.py
+++ b/Lib/test/test_cmd_line_script.py
@@ -601,7 +601,7 @@ class CmdLineTest(unittest.TestCase):
exitcode, stdout, stderr = assert_python_failure(script_name)
text = io.TextIOWrapper(io.BytesIO(stderr), 'ascii').read()
# Confirm that the caret is located under the '=' sign
- self.assertIn("\n 1 + 1 = 2\n ^\n", text)
+ self.assertIn("\n ^^^^^\n", text)
def test_syntaxerror_indented_caret_position(self):
script = textwrap.dedent("""\
@@ -612,8 +612,8 @@ class CmdLineTest(unittest.TestCase):
script_name = _make_test_script(script_dir, 'script', script)
exitcode, stdout, stderr = assert_python_failure(script_name)
text = io.TextIOWrapper(io.BytesIO(stderr), 'ascii').read()
- # Confirm that the caret is located under the first 1 character
- self.assertIn("\n 1 + 1 = 2\n ^\n", text)
+ # Confirm that the caret starts under the first 1 character
+ self.assertIn("\n 1 + 1 = 2\n ^^^^^\n", text)
# Try the same with a form feed at the start of the indented line
script = (
@@ -624,7 +624,7 @@ class CmdLineTest(unittest.TestCase):
exitcode, stdout, stderr = assert_python_failure(script_name)
text = io.TextIOWrapper(io.BytesIO(stderr), "ascii").read()
self.assertNotIn("\f", text)
- self.assertIn("\n 1 + 1 = 2\n ^\n", text)
+ self.assertIn("\n 1 + 1 = 2\n ^^^^^\n", text)
def test_syntaxerror_multi_line_fstring(self):
script = 'foo = f"""{}\nfoo"""\n'
@@ -650,7 +650,7 @@ class CmdLineTest(unittest.TestCase):
self.assertEqual(
stderr.splitlines()[-3:],
[ b' foo = """\\q"""',
- b' ^',
+ b' ^^^^^^^^',
b'SyntaxError: invalid escape sequence \\q'
],
)