Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address Lysandros's feedback
  • Loading branch information
pablogsal committed May 15, 2020
commit c74ecceea9c9673ff0f04d4d92c6b52170e67cf6
7 changes: 5 additions & 2 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,12 @@ invalid_assignment:
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
_PyPegen_get_invalid_target(a),
"cannot assign to %s", _PyPegen_get_expr_name(_PyPegen_get_invalid_target(a))) }
| a=expression augassign (yield_expr | star_expressions) { _PyPegen_raise_syntax_error_for_augassign(p, a) }
| a=star_expressions augassign (yield_expr | star_expressions) {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "illegal expression for augmented assignment") }
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
a,
"%s is an illegal expression for augmented assignment",
_PyPegen_get_expr_name(a)
)}

invalid_block:
| NEWLINE !INDENT { RAISE_INDENTATION_ERROR("expected an indented block") }
Expand Down
13 changes: 7 additions & 6 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@

>>> a, b += 1, 2
Traceback (most recent call last):
SyntaxError: illegal expression for augmented assignment
SyntaxError: tuple is an illegal expression for augmented assignment

>>> (a, b) += 1, 2
Traceback (most recent call last):
SyntaxError: illegal expression for augmented assignment
SyntaxError: tuple is an illegal expression for augmented assignment

>>> [a, b] += 1, 2
Traceback (most recent call last):
SyntaxError: illegal expression for augmented assignment
SyntaxError: list is an illegal expression for augmented assignment

From compiler_complex_args():

Expand Down Expand Up @@ -353,16 +353,16 @@

>>> (x for x in x) += 1
Traceback (most recent call last):
SyntaxError: cannot assign to generator expression
SyntaxError: generator expression is an illegal expression for augmented assignment
>>> None += 1
Traceback (most recent call last):
SyntaxError: cannot assign to None
SyntaxError: None is an illegal expression for augmented assignment
>>> __debug__ += 1
Traceback (most recent call last):
SyntaxError: cannot assign to __debug__
>>> f() += 1
Traceback (most recent call last):
SyntaxError: cannot assign to function call
SyntaxError: function call is an illegal expression for augmented assignment


Test continue in finally in weird combinations.
Expand Down Expand Up @@ -695,6 +695,7 @@ def _check_error(self, code, errtext,
def test_assign_call(self):
self._check_error("f() = 1", "assign")

@unittest.skipIf(support.use_old_parser(), "The old parser cannot generate these error messages")
def test_assign_del(self):
self._check_error("del (,)", "invalid syntax")
self._check_error("del 1", "delete literal")
Expand Down
Loading