|
458 | 458 | ... 290, 291, 292, 293, 294, 295, 296, 297, 298, 299) # doctest: +ELLIPSIS
|
459 | 459 | (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ..., 297, 298, 299)
|
460 | 460 |
|
461 |
| -# >>> f(lambda x: x[0] = 3) |
462 |
| -# Traceback (most recent call last): |
463 |
| -# SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
| 461 | +>>> f(lambda x: x[0] = 3) |
| 462 | +Traceback (most recent call last): |
| 463 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
| 464 | +
|
| 465 | +# Check that this error doesn't trigger for names: |
| 466 | +>>> f(a={x: for x in {}}) |
| 467 | +Traceback (most recent call last): |
| 468 | +SyntaxError: invalid syntax |
464 | 469 |
|
465 | 470 | The grammar accepts any test (basically, any expression) in the
|
466 | 471 | keyword slot of a call site. Test a few different options.
|
467 | 472 |
|
468 |
| -# >>> f(x()=2) |
469 |
| -# Traceback (most recent call last): |
470 |
| -# SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
471 |
| -# >>> f(a or b=1) |
472 |
| -# Traceback (most recent call last): |
473 |
| -# SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
474 |
| -# >>> f(x.y=1) |
475 |
| -# Traceback (most recent call last): |
476 |
| -# SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
477 |
| -# >>> f((x)=2) |
478 |
| -# Traceback (most recent call last): |
479 |
| -# SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
480 |
| -# >>> f(True=2) |
481 |
| -# Traceback (most recent call last): |
482 |
| -# SyntaxError: cannot assign to True here. Maybe you meant '==' instead of '='? |
| 473 | +>>> f(x()=2) |
| 474 | +Traceback (most recent call last): |
| 475 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
| 476 | +>>> f(a or b=1) |
| 477 | +Traceback (most recent call last): |
| 478 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
| 479 | +>>> f(x.y=1) |
| 480 | +Traceback (most recent call last): |
| 481 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
| 482 | +>>> f((x)=2) |
| 483 | +Traceback (most recent call last): |
| 484 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
| 485 | +>>> f(True=2) |
| 486 | +Traceback (most recent call last): |
| 487 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
483 | 488 | >>> f(__debug__=1)
|
484 | 489 | Traceback (most recent call last):
|
485 | 490 | SyntaxError: cannot assign to __debug__
|
@@ -1422,7 +1427,7 @@ def case(x):
|
1422 | 1427 | case(34)
|
1423 | 1428 | """
|
1424 | 1429 | compile(code, "<string>", "exec")
|
1425 |
| - |
| 1430 | + |
1426 | 1431 | def test_multiline_compiler_error_points_to_the_end(self):
|
1427 | 1432 | self._check_error(
|
1428 | 1433 | "call(\na=1,\na=1\n)",
|
|
0 commit comments