summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2020-05-07 10:37:51 (GMT)
committerGitHub <noreply@github.com>2020-05-07 10:37:51 (GMT)
commit2f37c355ab0e9ec9c1753985d27c41fa0bd719b9 (patch)
tree2295b4c14a0d54f6db7d9248e17924c267e31700 /Lib
parent3466922320d54a922cfe6d6d44e89e1cea4023ef (diff)
downloadcpython-2f37c355ab0e9ec9c1753985d27c41fa0bd719b9.zip
cpython-2f37c355ab0e9ec9c1753985d27c41fa0bd719b9.tar.gz
cpython-2f37c355ab0e9ec9c1753985d27c41fa0bd719b9.tar.bz2
bpo-40334: Fix error location upon parsing an invalid string literal (GH-19962)
When parsing a string with an invalid escape, the old parser used to point to the beginning of the invalid string. This commit changes the new parser to match that behaviour, since it's currently pointing to the end of the string (or to be more precise, to the beginning of the next token).
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_cmd_line_script.py2
-rw-r--r--Lib/test/test_string_literals.py7
2 files changed, 4 insertions, 5 deletions
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py
index 1fc9500..1713405 100644
--- a/Lib/test/test_cmd_line_script.py
+++ b/Lib/test/test_cmd_line_script.py
@@ -648,7 +648,7 @@ class CmdLineTest(unittest.TestCase):
self.assertEqual(
stderr.splitlines()[-3:],
[ b' foo = """\\q"""',
- b' ^',
+ b' ^',
b'SyntaxError: invalid escape sequence \\q'
],
)
diff --git a/Lib/test/test_string_literals.py b/Lib/test/test_string_literals.py
index 5b5477d..9565ee2 100644
--- a/Lib/test/test_string_literals.py
+++ b/Lib/test/test_string_literals.py
@@ -118,8 +118,7 @@ class TestLiterals(unittest.TestCase):
eval("'''\n\\z'''")
self.assertEqual(len(w), 1)
self.assertEqual(w[0].filename, '<string>')
- if use_old_parser():
- self.assertEqual(w[0].lineno, 1)
+ self.assertEqual(w[0].lineno, 1)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('error', category=DeprecationWarning)
@@ -128,8 +127,8 @@ class TestLiterals(unittest.TestCase):
exc = cm.exception
self.assertEqual(w, [])
self.assertEqual(exc.filename, '<string>')
- if use_old_parser():
- self.assertEqual(exc.lineno, 1)
+ self.assertEqual(exc.lineno, 1)
+ self.assertEqual(exc.offset, 1)
def test_eval_str_raw(self):
self.assertEqual(eval(""" r'x' """), 'x')