|
405 | 405 | ... 290, 291, 292, 293, 294, 295, 296, 297, 298, 299) # doctest: +ELLIPSIS
|
406 | 406 | (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ..., 297, 298, 299)
|
407 | 407 |
|
408 |
| -# >>> f(lambda x: x[0] = 3) |
409 |
| -# Traceback (most recent call last): |
410 |
| -# SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
| 408 | +>>> f(lambda x: x[0] = 3) |
| 409 | +Traceback (most recent call last): |
| 410 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
| 411 | +
|
| 412 | +# Check that this error doesn't trigger for names: |
| 413 | +>>> f(a={x: for x in {}}) |
| 414 | +Traceback (most recent call last): |
| 415 | +SyntaxError: invalid syntax |
411 | 416 |
|
412 | 417 | The grammar accepts any test (basically, any expression) in the
|
413 | 418 | keyword slot of a call site. Test a few different options.
|
414 | 419 |
|
415 |
| -# >>> f(x()=2) |
416 |
| -# Traceback (most recent call last): |
417 |
| -# SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
418 |
| -# >>> f(a or b=1) |
419 |
| -# Traceback (most recent call last): |
420 |
| -# SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
421 |
| -# >>> f(x.y=1) |
422 |
| -# Traceback (most recent call last): |
423 |
| -# SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
424 |
| -# >>> f((x)=2) |
425 |
| -# Traceback (most recent call last): |
426 |
| -# SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
427 |
| -# >>> f(True=2) |
428 |
| -# Traceback (most recent call last): |
429 |
| -# SyntaxError: cannot assign to True |
| 420 | +>>> f(x()=2) |
| 421 | +Traceback (most recent call last): |
| 422 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
| 423 | +>>> f(a or b=1) |
| 424 | +Traceback (most recent call last): |
| 425 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
| 426 | +>>> f(x.y=1) |
| 427 | +Traceback (most recent call last): |
| 428 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
| 429 | +>>> f((x)=2) |
| 430 | +Traceback (most recent call last): |
| 431 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
| 432 | +>>> f(True=2) |
| 433 | +Traceback (most recent call last): |
| 434 | +SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
430 | 435 | >>> f(__debug__=1)
|
431 | 436 | Traceback (most recent call last):
|
432 | 437 | SyntaxError: cannot assign to __debug__
|
|
0 commit comments