Skip to content

Commit 947ce58

Browse files
committed
prevent assignment to set literals
1 parent 5c995c1 commit 947ce58

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

Lib/test/test_syntax.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,12 @@
468468
File "<doctest test.test_syntax[50]>", line 1
469469
SyntaxError: can't delete ()
470470
471+
>>> {1, 2, 3} = 42
472+
Traceback (most recent call last):
473+
...
474+
File "<doctest test.test_syntax[50]>", line 1
475+
SyntaxError: can't assign to literal
476+
471477
"""
472478

473479
import re

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ What's New in Python 2.7?
1212
Core and Builtins
1313
-----------------
1414

15+
- Prevent assignment to set literals.
16+
1517
Library
1618
-------
1719

Python/ast.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n)
440440
expr_name = "dict comprehension";
441441
break;
442442
case Dict_kind:
443+
case Set_kind:
443444
case Num_kind:
444445
case Str_kind:
445446
expr_name = "literal";

0 commit comments

Comments
 (0)