33
33
34
34
>>> None = 1
35
35
Traceback (most recent call last):
36
- SyntaxError: cannot assign to None
36
+ SyntaxError: cannot assign to None. Maybe you meant '==' instead of '='?
37
37
38
38
>>> obj.True = 1
39
39
Traceback (most recent call last):
40
40
SyntaxError: invalid syntax
41
41
42
42
>>> True = 1
43
43
Traceback (most recent call last):
44
- SyntaxError: cannot assign to True
44
+ SyntaxError: cannot assign to True. Maybe you meant '==' instead of '='?
45
45
46
46
>>> (True := 1)
47
47
Traceback (most recent call last):
61
61
62
62
>>> f() = 1
63
63
Traceback (most recent call last):
64
- SyntaxError: cannot assign to function call
64
+ SyntaxError: cannot assign to function call. Maybe you meant '==' instead of '='?
65
65
66
66
>>> yield = 1
67
67
Traceback (most recent call last):
73
73
74
74
>>> a + 1 = 2
75
75
Traceback (most recent call last):
76
- SyntaxError: cannot assign to operator
76
+ SyntaxError: cannot assign to expression. Maybe you meant '==' instead of '='?
77
77
78
78
>>> (x for x in x) = 1
79
79
Traceback (most recent call last):
80
- SyntaxError: cannot assign to generator expression
80
+ SyntaxError: cannot assign to generator expression. Maybe you meant '==' instead of '='?
81
81
82
82
>>> 1 = 1
83
83
Traceback (most recent call last):
84
- SyntaxError: cannot assign to literal
84
+ SyntaxError: cannot assign to literal. Maybe you meant '==' instead of '='?
85
85
86
86
>>> "abc" = 1
87
87
Traceback (most recent call last):
88
- SyntaxError: cannot assign to literal
88
+ SyntaxError: cannot assign to literal. Maybe you meant '==' instead of '='?
89
89
90
90
>>> b"" = 1
91
91
Traceback (most recent call last):
92
- SyntaxError: cannot assign to literal
92
+ SyntaxError: cannot assign to literal. Maybe you meant '==' instead of '='?
93
93
94
94
>>> ... = 1
95
95
Traceback (most recent call last):
96
- SyntaxError: cannot assign to Ellipsis
96
+ SyntaxError: cannot assign to Ellipsis. Maybe you meant '==' instead of '='?
97
97
98
98
>>> `1` = 1
99
99
Traceback (most recent call last):
126
126
127
127
>>> [a, b, c + 1] = [1, 2, 3]
128
128
Traceback (most recent call last):
129
- SyntaxError: cannot assign to operator
129
+ SyntaxError: cannot assign to expression
130
130
131
131
>>> [a, b[1], c + 1] = [1, 2, 3]
132
132
Traceback (most recent call last):
133
- SyntaxError: cannot assign to operator
133
+ SyntaxError: cannot assign to expression
134
134
135
135
>>> [a, b.c.d, c + 1] = [1, 2, 3]
136
136
Traceback (most recent call last):
137
- SyntaxError: cannot assign to operator
137
+ SyntaxError: cannot assign to expression
138
138
139
139
>>> a if 1 else b = 1
140
140
Traceback (most recent call last):
181
181
182
182
>>> for (*a, b, c+1) in b: pass
183
183
Traceback (most recent call last):
184
- SyntaxError: cannot assign to operator
184
+ SyntaxError: cannot assign to expression
185
185
186
186
>>> for (x, *(y, z.d())) in b: pass
187
187
Traceback (most recent call last):
193
193
194
194
>>> for a, b, (c + 1, d()): pass
195
195
Traceback (most recent call last):
196
- SyntaxError: cannot assign to operator
196
+ SyntaxError: cannot assign to expression
197
197
198
198
>>> for i < (): pass
199
199
Traceback (most recent call last):
217
217
218
218
>>> with a as (*b, c, d+1): pass
219
219
Traceback (most recent call last):
220
- SyntaxError: cannot assign to operator
220
+ SyntaxError: cannot assign to expression
221
221
222
222
>>> with a as (x, *(y, z.d())): pass
223
223
Traceback (most recent call last):
465
465
# SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
466
466
# >>> f(True=2)
467
467
# Traceback (most recent call last):
468
- # SyntaxError: cannot assign to True
468
+ # SyntaxError: cannot assign to True. Maybe you meant '==' instead of '='?
469
469
>>> f(__debug__=1)
470
470
Traceback (most recent call last):
471
471
SyntaxError: cannot assign to __debug__
684
684
... pass
685
685
Traceback (most recent call last):
686
686
...
687
- SyntaxError: cannot assign to function call
687
+ SyntaxError: cannot assign to function call. Maybe you meant '==' instead of '='?
688
688
689
689
>>> if 1:
690
690
... pass
691
691
... elif 1:
692
692
... x() = 1
693
693
Traceback (most recent call last):
694
694
...
695
- SyntaxError: cannot assign to function call
695
+ SyntaxError: cannot assign to function call. Maybe you meant '==' instead of '='?
696
696
697
697
>>> if 1:
698
698
... x() = 1
702
702
... pass
703
703
Traceback (most recent call last):
704
704
...
705
- SyntaxError: cannot assign to function call
705
+ SyntaxError: cannot assign to function call. Maybe you meant '==' instead of '='?
706
706
707
707
>>> if 1:
708
708
... pass
712
712
... pass
713
713
Traceback (most recent call last):
714
714
...
715
- SyntaxError: cannot assign to function call
715
+ SyntaxError: cannot assign to function call. Maybe you meant '==' instead of '='?
716
716
717
717
>>> if 1:
718
718
... pass
722
722
... x() = 1
723
723
Traceback (most recent call last):
724
724
...
725
- SyntaxError: cannot assign to function call
725
+ SyntaxError: cannot assign to function call. Maybe you meant '==' instead of '='?
726
726
727
727
Missing ':' before suites:
728
728
894
894
895
895
>>> {1, 2, 3} = 42
896
896
Traceback (most recent call last):
897
- SyntaxError: cannot assign to set display
897
+ SyntaxError: cannot assign to set display. Maybe you meant '==' instead of '='?
898
898
899
899
>>> {1: 2, 3: 4} = 42
900
900
Traceback (most recent call last):
901
- SyntaxError: cannot assign to dict display
901
+ SyntaxError: cannot assign to dict display. Maybe you meant '==' instead of '='?
902
902
903
903
>>> f'{x}' = 42
904
904
Traceback (most recent call last):
905
- SyntaxError: cannot assign to f-string expression
905
+ SyntaxError: cannot assign to f-string expression. Maybe you meant '==' instead of '='?
906
906
907
907
>>> f'{x}-{y}' = 42
908
908
Traceback (most recent call last):
909
- SyntaxError: cannot assign to f-string expression
909
+ SyntaxError: cannot assign to f-string expression. Maybe you meant '==' instead of '='?
910
910
911
911
>>> from t import x,
912
912
Traceback (most recent call last):
@@ -988,7 +988,7 @@ def _check_error(self, code, errtext,
988
988
def test_expression_with_assignment (self ):
989
989
self ._check_error (
990
990
"print(end1 + end2 = ' ')" ,
991
- 'expression cannot contain assignment, perhaps you meant "=="?' ,
991
+ " cannot assign to expression. Maybe you meant '==' instead of '='?" ,
992
992
offset = 19
993
993
)
994
994
@@ -1015,15 +1015,15 @@ def test_assign_del(self):
1015
1015
self ._check_error ("del f(), x" , "delete function call" )
1016
1016
self ._check_error ("del [a, b, ((c), (d,), e.f())]" , "delete function call" )
1017
1017
self ._check_error ("del (a if True else b)" , "delete conditional" )
1018
- self ._check_error ("del +a" , "delete operator " )
1019
- self ._check_error ("del a, +b" , "delete operator " )
1020
- self ._check_error ("del a + b" , "delete operator " )
1021
- self ._check_error ("del (a + b, c)" , "delete operator " )
1022
- self ._check_error ("del (c[0], a + b)" , "delete operator " )
1023
- self ._check_error ("del a.b.c + 2" , "delete operator " )
1024
- self ._check_error ("del a.b.c[0] + 2" , "delete operator " )
1025
- self ._check_error ("del (a, b, (c, d.e.f + 2))" , "delete operator " )
1026
- self ._check_error ("del [a, b, (c, d.e.f[0] + 2)]" , "delete operator " )
1018
+ self ._check_error ("del +a" , "delete expression " )
1019
+ self ._check_error ("del a, +b" , "delete expression " )
1020
+ self ._check_error ("del a + b" , "delete expression " )
1021
+ self ._check_error ("del (a + b, c)" , "delete expression " )
1022
+ self ._check_error ("del (c[0], a + b)" , "delete expression " )
1023
+ self ._check_error ("del a.b.c + 2" , "delete expression " )
1024
+ self ._check_error ("del a.b.c[0] + 2" , "delete expression " )
1025
+ self ._check_error ("del (a, b, (c, d.e.f + 2))" , "delete expression " )
1026
+ self ._check_error ("del [a, b, (c, d.e.f[0] + 2)]" , "delete expression " )
1027
1027
self ._check_error ("del (a := 5)" , "delete named expression" )
1028
1028
# We don't have a special message for this, but make sure we don't
1029
1029
# report "cannot delete name"
0 commit comments