mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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:
parent
bcc3036095
commit
ce21cfca7b
5 changed files with 82 additions and 46 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue