|
33 | 33 |
|
34 | 34 | >>> None = 1
|
35 | 35 | Traceback (most recent call last):
|
36 |
| -SyntaxError: can't assign to keyword |
| 36 | +SyntaxError: cannot assign to None |
| 37 | +
|
| 38 | +>>> obj.True = 1 |
| 39 | +Traceback (most recent call last): |
| 40 | +SyntaxError: invalid syntax |
| 41 | +
|
| 42 | +>>> True = 1 |
| 43 | +Traceback (most recent call last): |
| 44 | +SyntaxError: cannot assign to True |
| 45 | +
|
| 46 | +>>> obj.__debug__ = 1 |
| 47 | +Traceback (most recent call last): |
| 48 | +SyntaxError: cannot assign to __debug__ |
| 49 | +
|
| 50 | +>>> __debug__ = 1 |
| 51 | +Traceback (most recent call last): |
| 52 | +SyntaxError: cannot assign to __debug__ |
37 | 53 |
|
38 | 54 | >>> f() = 1
|
39 | 55 | Traceback (most recent call last):
|
40 |
| -SyntaxError: can't assign to function call |
| 56 | +SyntaxError: cannot assign to function call |
41 | 57 |
|
42 | 58 | >>> del f()
|
43 | 59 | Traceback (most recent call last):
|
44 |
| -SyntaxError: can't delete function call |
| 60 | +SyntaxError: cannot delete function call |
45 | 61 |
|
46 | 62 | >>> a + 1 = 2
|
47 | 63 | Traceback (most recent call last):
|
48 |
| -SyntaxError: can't assign to operator |
| 64 | +SyntaxError: cannot assign to operator |
49 | 65 |
|
50 | 66 | >>> (x for x in x) = 1
|
51 | 67 | Traceback (most recent call last):
|
52 |
| -SyntaxError: can't assign to generator expression |
| 68 | +SyntaxError: cannot assign to generator expression |
53 | 69 |
|
54 | 70 | >>> 1 = 1
|
55 | 71 | Traceback (most recent call last):
|
56 |
| -SyntaxError: can't assign to literal |
| 72 | +SyntaxError: cannot assign to literal |
57 | 73 |
|
58 | 74 | >>> "abc" = 1
|
59 | 75 | Traceback (most recent call last):
|
60 |
| -SyntaxError: can't assign to literal |
| 76 | +SyntaxError: cannot assign to literal |
61 | 77 |
|
62 | 78 | >>> b"" = 1
|
63 | 79 | Traceback (most recent call last):
|
64 |
| -SyntaxError: can't assign to literal |
| 80 | +SyntaxError: cannot assign to literal |
| 81 | +
|
| 82 | +>>> ... = 1 |
| 83 | +Traceback (most recent call last): |
| 84 | +SyntaxError: cannot assign to Ellipsis |
65 | 85 |
|
66 | 86 | >>> `1` = 1
|
67 | 87 | Traceback (most recent call last):
|
|
74 | 94 |
|
75 | 95 | >>> (a, "b", c) = (1, 2, 3)
|
76 | 96 | Traceback (most recent call last):
|
77 |
| -SyntaxError: can't assign to literal |
| 97 | +SyntaxError: cannot assign to literal |
| 98 | +
|
| 99 | +>>> (a, True, c) = (1, 2, 3) |
| 100 | +Traceback (most recent call last): |
| 101 | +SyntaxError: cannot assign to True |
| 102 | +
|
| 103 | +>>> (a, __debug__, c) = (1, 2, 3) |
| 104 | +Traceback (most recent call last): |
| 105 | +SyntaxError: cannot assign to __debug__ |
| 106 | +
|
| 107 | +>>> (a, *True, c) = (1, 2, 3) |
| 108 | +Traceback (most recent call last): |
| 109 | +SyntaxError: cannot assign to True |
| 110 | +
|
| 111 | +>>> (a, *__debug__, c) = (1, 2, 3) |
| 112 | +Traceback (most recent call last): |
| 113 | +SyntaxError: cannot assign to __debug__ |
78 | 114 |
|
79 | 115 | >>> [a, b, c + 1] = [1, 2, 3]
|
80 | 116 | Traceback (most recent call last):
|
81 |
| -SyntaxError: can't assign to operator |
| 117 | +SyntaxError: cannot assign to operator |
82 | 118 |
|
83 | 119 | >>> a if 1 else b = 1
|
84 | 120 | Traceback (most recent call last):
|
85 |
| -SyntaxError: can't assign to conditional expression |
| 121 | +SyntaxError: cannot assign to conditional expression |
86 | 122 |
|
87 | 123 | From compiler_complex_args():
|
88 | 124 |
|
|
255 | 291 |
|
256 | 292 | >>> f(lambda x: x[0] = 3)
|
257 | 293 | Traceback (most recent call last):
|
258 |
| -SyntaxError: lambda cannot contain assignment |
| 294 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
259 | 295 |
|
260 | 296 | The grammar accepts any test (basically, any expression) in the
|
261 | 297 | keyword slot of a call site. Test a few different options.
|
262 | 298 |
|
263 | 299 | >>> f(x()=2)
|
264 | 300 | Traceback (most recent call last):
|
265 |
| -SyntaxError: keyword can't be an expression |
| 301 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
266 | 302 | >>> f(a or b=1)
|
267 | 303 | Traceback (most recent call last):
|
268 |
| -SyntaxError: keyword can't be an expression |
| 304 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
269 | 305 | >>> f(x.y=1)
|
270 | 306 | Traceback (most recent call last):
|
271 |
| -SyntaxError: keyword can't be an expression |
| 307 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
272 | 308 | >>> f((x)=2)
|
273 | 309 | Traceback (most recent call last):
|
274 |
| -SyntaxError: keyword can't be an expression |
| 310 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
| 311 | +>>> f(True=2) |
| 312 | +Traceback (most recent call last): |
| 313 | +SyntaxError: cannot assign to True |
| 314 | +>>> f(__debug__=1) |
| 315 | +Traceback (most recent call last): |
| 316 | +SyntaxError: cannot assign to __debug__ |
275 | 317 |
|
276 | 318 |
|
277 | 319 | More set_context():
|
278 | 320 |
|
279 | 321 | >>> (x for x in x) += 1
|
280 | 322 | Traceback (most recent call last):
|
281 |
| -SyntaxError: can't assign to generator expression |
| 323 | +SyntaxError: cannot assign to generator expression |
282 | 324 | >>> None += 1
|
283 | 325 | Traceback (most recent call last):
|
284 |
| -SyntaxError: can't assign to keyword |
| 326 | +SyntaxError: cannot assign to None |
| 327 | +>>> __debug__ += 1 |
| 328 | +Traceback (most recent call last): |
| 329 | +SyntaxError: cannot assign to __debug__ |
285 | 330 | >>> f() += 1
|
286 | 331 | Traceback (most recent call last):
|
287 |
| -SyntaxError: can't assign to function call |
| 332 | +SyntaxError: cannot assign to function call |
288 | 333 |
|
289 | 334 |
|
290 | 335 | Test continue in finally in weird combinations.
|
|
481 | 526 | ... pass
|
482 | 527 | Traceback (most recent call last):
|
483 | 528 | ...
|
484 |
| - SyntaxError: can't assign to function call |
| 529 | + SyntaxError: cannot assign to function call |
485 | 530 |
|
486 | 531 | >>> if 1:
|
487 | 532 | ... pass
|
488 | 533 | ... elif 1:
|
489 | 534 | ... x() = 1
|
490 | 535 | Traceback (most recent call last):
|
491 | 536 | ...
|
492 |
| - SyntaxError: can't assign to function call |
| 537 | + SyntaxError: cannot assign to function call |
493 | 538 |
|
494 | 539 | >>> if 1:
|
495 | 540 | ... x() = 1
|
|
499 | 544 | ... pass
|
500 | 545 | Traceback (most recent call last):
|
501 | 546 | ...
|
502 |
| - SyntaxError: can't assign to function call |
| 547 | + SyntaxError: cannot assign to function call |
503 | 548 |
|
504 | 549 | >>> if 1:
|
505 | 550 | ... pass
|
|
509 | 554 | ... pass
|
510 | 555 | Traceback (most recent call last):
|
511 | 556 | ...
|
512 |
| - SyntaxError: can't assign to function call |
| 557 | + SyntaxError: cannot assign to function call |
513 | 558 |
|
514 | 559 | >>> if 1:
|
515 | 560 | ... pass
|
|
519 | 564 | ... x() = 1
|
520 | 565 | Traceback (most recent call last):
|
521 | 566 | ...
|
522 |
| - SyntaxError: can't assign to function call |
| 567 | + SyntaxError: cannot assign to function call |
523 | 568 |
|
524 | 569 | Make sure that the old "raise X, Y[, Z]" form is gone:
|
525 | 570 | >>> raise X, Y
|
|
539 | 584 |
|
540 | 585 | >>> {1, 2, 3} = 42
|
541 | 586 | Traceback (most recent call last):
|
542 |
| -SyntaxError: can't assign to literal |
| 587 | +SyntaxError: cannot assign to set display |
| 588 | +
|
| 589 | +>>> {1: 2, 3: 4} = 42 |
| 590 | +Traceback (most recent call last): |
| 591 | +SyntaxError: cannot assign to dict display |
| 592 | +
|
| 593 | +>>> f'{x}' = 42 |
| 594 | +Traceback (most recent call last): |
| 595 | +SyntaxError: cannot assign to f-string expression |
| 596 | +
|
| 597 | +>>> f'{x}-{y}' = 42 |
| 598 | +Traceback (most recent call last): |
| 599 | +SyntaxError: cannot assign to f-string expression |
543 | 600 |
|
544 | 601 | Corner-cases that used to fail to raise the correct error:
|
545 | 602 |
|
546 | 603 | >>> def f(*, x=lambda __debug__:0): pass
|
547 | 604 | Traceback (most recent call last):
|
548 |
| - SyntaxError: assignment to keyword |
| 605 | + SyntaxError: cannot assign to __debug__ |
549 | 606 |
|
550 | 607 | >>> def f(*args:(lambda __debug__:0)): pass
|
551 | 608 | Traceback (most recent call last):
|
552 |
| - SyntaxError: assignment to keyword |
| 609 | + SyntaxError: cannot assign to __debug__ |
553 | 610 |
|
554 | 611 | >>> def f(**kwargs:(lambda __debug__:0)): pass
|
555 | 612 | Traceback (most recent call last):
|
556 |
| - SyntaxError: assignment to keyword |
| 613 | + SyntaxError: cannot assign to __debug__ |
557 | 614 |
|
558 | 615 | >>> with (lambda *:0): pass
|
559 | 616 | Traceback (most recent call last):
|
|
563 | 620 |
|
564 | 621 | >>> def f(**__debug__): pass
|
565 | 622 | Traceback (most recent call last):
|
566 |
| - SyntaxError: assignment to keyword |
| 623 | + SyntaxError: cannot assign to __debug__ |
567 | 624 |
|
568 | 625 | >>> def f(*xx, __debug__): pass
|
569 | 626 | Traceback (most recent call last):
|
570 |
| - SyntaxError: assignment to keyword |
| 627 | + SyntaxError: cannot assign to __debug__ |
571 | 628 |
|
572 | 629 | """
|
573 | 630 |
|
|
0 commit comments