bpo-30858: Improve error location for expressions with assignments (GH-23753)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 1bdd3f2..e752ab7 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -252,7 +252,7 @@ def baz():
check('from __future__ import doesnt_exist', 1, 1)
check('from __future__ import braces', 1, 1)
check('x=1\nfrom __future__ import division', 2, 1)
- check('foo(1=2)', 1, 5)
+ check('foo(1=2)', 1, 6)
check('def f():\n x, y: int', 2, 3)
check('[*x for x in xs]', 1, 2)
check('foo(x for x in range(10), 100)', 1, 5)
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index 91ca1db..d825560 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -802,6 +802,13 @@ def _check_error(self, code, errtext,
else:
self.fail("compile() did not raise SyntaxError")
+ def test_expression_with_assignment(self):
+ self._check_error(
+ "print(end1 + end2 = ' ')",
+ 'expression cannot contain assignment, perhaps you meant "=="?',
+ offset=19
+ )
+
def test_curly_brace_after_primary_raises_immediately(self):
self._check_error("f{", "invalid syntax", mode="single")