Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd3e362

Browse files
committed
make assigning to a bytes literal a syntax error (closes #11506)
1 parent 3780542 commit bd3e362

3 files changed

Lines changed: 8 additions & 0 deletions

File tree

Lib/test/test_syntax.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
Traceback (most recent call last):
6868
SyntaxError: can't assign to literal
6969
70+
>>> b"" = 1
71+
Traceback (most recent call last):
72+
SyntaxError: can't assign to literal
73+
7074
>>> `1` = 1
7175
Traceback (most recent call last):
7276
SyntaxError: invalid syntax

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ Core and Builtins
4545
- Issue #5587: add a repr to dict_proxy objects. Patch by David Stanek and
4646
Daniel Urban.
4747

48+
- Issue #11506: Trying to assign to a bytes literal should result in a
49+
SyntaxError.
50+
4851
Library
4952
-------
5053

Python/ast.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n)
469469
case Set_kind:
470470
case Num_kind:
471471
case Str_kind:
472+
case Bytes_kind:
472473
expr_name = "literal";
473474
break;
474475
case Ellipsis_kind:

0 commit comments

Comments
 (0)