bpo-40618: Disallow invalid targets in augassign and except clauses (GH-20083)

This commit fixes the new parser to disallow invalid targets in the
following scenarios:
- Augmented assignments must only accept a single target (Name,
  Attribute or Subscript), but no tuples or lists.
- `except` clauses should only accept a single `Name` as a target.

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
This commit is contained in:
Lysandros Nikolaou 2020-05-14 23:13:50 +03:00 committed by GitHub
parent bcc3036095
commit ce21cfca7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 82 additions and 46 deletions

View file

@ -129,6 +129,18 @@ SyntaxError: cannot assign to __debug__
Traceback (most recent call last):
SyntaxError: cannot assign to conditional expression
>>> a, b += 1, 2
Traceback (most recent call last):
SyntaxError: invalid syntax
>>> (a, b) += 1, 2
Traceback (most recent call last):
SyntaxError: cannot assign to tuple
>>> [a, b] += 1, 2
Traceback (most recent call last):
SyntaxError: cannot assign to list
From compiler_complex_args():
>>> def f(None=1):