|
100 | 100 | This test just checks a couple of cases rather than enumerating all of
|
101 | 101 | them.
|
102 | 102 |
|
103 |
| -# All of the following also produce different error messages with pegen |
104 |
| -# >>> (a, "b", c) = (1, 2, 3) |
105 |
| -# Traceback (most recent call last): |
106 |
| -# SyntaxError: cannot assign to literal |
| 103 | +>>> (a, "b", c) = (1, 2, 3) |
| 104 | +Traceback (most recent call last): |
| 105 | +SyntaxError: cannot assign to literal |
107 | 106 |
|
108 |
| -# >>> (a, True, c) = (1, 2, 3) |
109 |
| -# Traceback (most recent call last): |
110 |
| -# SyntaxError: cannot assign to True |
| 107 | +>>> (a, True, c) = (1, 2, 3) |
| 108 | +Traceback (most recent call last): |
| 109 | +SyntaxError: cannot assign to True |
111 | 110 |
|
112 | 111 | >>> (a, __debug__, c) = (1, 2, 3)
|
113 | 112 | Traceback (most recent call last):
|
114 | 113 | SyntaxError: cannot assign to __debug__
|
115 | 114 |
|
116 |
| -# >>> (a, *True, c) = (1, 2, 3) |
117 |
| -# Traceback (most recent call last): |
118 |
| -# SyntaxError: cannot assign to True |
| 115 | +>>> (a, *True, c) = (1, 2, 3) |
| 116 | +Traceback (most recent call last): |
| 117 | +SyntaxError: cannot assign to True |
119 | 118 |
|
120 | 119 | >>> (a, *__debug__, c) = (1, 2, 3)
|
121 | 120 | Traceback (most recent call last):
|
122 | 121 | SyntaxError: cannot assign to __debug__
|
123 | 122 |
|
124 |
| -# >>> [a, b, c + 1] = [1, 2, 3] |
125 |
| -# Traceback (most recent call last): |
126 |
| -# SyntaxError: cannot assign to operator |
| 123 | +>>> [a, b, c + 1] = [1, 2, 3] |
| 124 | +Traceback (most recent call last): |
| 125 | +SyntaxError: cannot assign to operator |
| 126 | +
|
| 127 | +>>> [a, b[1], c + 1] = [1, 2, 3] |
| 128 | +Traceback (most recent call last): |
| 129 | +SyntaxError: cannot assign to operator |
| 130 | +
|
| 131 | +>>> [a, b.c.d, c + 1] = [1, 2, 3] |
| 132 | +Traceback (most recent call last): |
| 133 | +SyntaxError: cannot assign to operator |
127 | 134 |
|
128 | 135 | >>> a if 1 else b = 1
|
129 | 136 | Traceback (most recent call last):
|
130 | 137 | SyntaxError: cannot assign to conditional expression
|
131 | 138 |
|
132 | 139 | >>> a, b += 1, 2
|
133 | 140 | Traceback (most recent call last):
|
134 |
| -SyntaxError: invalid syntax |
| 141 | +SyntaxError: 'tuple' is an illegal expression for augmented assignment |
135 | 142 |
|
136 | 143 | >>> (a, b) += 1, 2
|
137 | 144 | Traceback (most recent call last):
|
138 |
| -SyntaxError: cannot assign to tuple |
| 145 | +SyntaxError: 'tuple' is an illegal expression for augmented assignment |
139 | 146 |
|
140 | 147 | >>> [a, b] += 1, 2
|
141 | 148 | Traceback (most recent call last):
|
142 |
| -SyntaxError: cannot assign to list |
| 149 | +SyntaxError: 'list' is an illegal expression for augmented assignment |
143 | 150 |
|
144 | 151 | From compiler_complex_args():
|
145 | 152 |
|
|
346 | 353 |
|
347 | 354 | >>> (x for x in x) += 1
|
348 | 355 | Traceback (most recent call last):
|
349 |
| -SyntaxError: cannot assign to generator expression |
| 356 | +SyntaxError: 'generator expression' is an illegal expression for augmented assignment |
350 | 357 | >>> None += 1
|
351 | 358 | Traceback (most recent call last):
|
352 |
| -SyntaxError: cannot assign to None |
| 359 | +SyntaxError: 'None' is an illegal expression for augmented assignment |
353 | 360 | >>> __debug__ += 1
|
354 | 361 | Traceback (most recent call last):
|
355 | 362 | SyntaxError: cannot assign to __debug__
|
356 | 363 | >>> f() += 1
|
357 | 364 | Traceback (most recent call last):
|
358 |
| -SyntaxError: cannot assign to function call |
| 365 | +SyntaxError: 'function call' is an illegal expression for augmented assignment |
359 | 366 |
|
360 | 367 |
|
361 | 368 | Test continue in finally in weird combinations.
|
@@ -688,6 +695,7 @@ def _check_error(self, code, errtext,
|
688 | 695 | def test_assign_call(self):
|
689 | 696 | self._check_error("f() = 1", "assign")
|
690 | 697 |
|
| 698 | + @unittest.skipIf(support.use_old_parser(), "The old parser cannot generate these error messages") |
691 | 699 | def test_assign_del(self):
|
692 | 700 | self._check_error("del (,)", "invalid syntax")
|
693 | 701 | self._check_error("del 1", "delete literal")
|
|
0 commit comments