GeezerVison is showing github.com — bpo-45716: Improve the error message when using True/False/None as ke… · python/cpython@e2d6563
File tree
Expand file treeCollapse file tree
Open diff view settings
Misc/NEWS.d/next/Core and Builtins
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: Grammar/python.gram +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1062,6 +1062,8 @@ invalid_arguments: |
1062 | 1062 | RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, asdl_seq_GET(b, b->size-1)->target, "Generator expression must be parenthesized") } |
1063 | 1063 | | a=args ',' args { _PyPegen_arguments_parsing_error(p, a) } |
1064 | 1064 | invalid_kwarg: |
| 1065 | + | a[Token*]=('True'|'False'|'None') b='=' { |
| 1066 | + RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot assign to %s", PyBytes_AS_STRING(a->bytes)) } |
1065 | 1067 | | a=NAME b='=' expression for_if_clauses { |
1066 | 1068 | RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '==' or ':=' instead of '='?")} |
1067 | 1069 | | !(NAME '=') a=expression b='=' { |
|
Collapse file
Copy file name to clipboardExpand all lines: Lib/test/test_syntax.py +8-2Lines changed: 8 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
524 | 524 | >>> f((x)=2) |
525 | 525 | Traceback (most recent call last): |
526 | 526 | SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
527 | | ->>> f(True=2) |
| 527 | +>>> f(True=1) |
528 | 528 | Traceback (most recent call last): |
529 | | -SyntaxError: expression cannot contain assignment, perhaps you meant "=="? |
| 529 | +SyntaxError: cannot assign to True |
| 530 | +>>> f(False=1) |
| 531 | +Traceback (most recent call last): |
| 532 | +SyntaxError: cannot assign to False |
| 533 | +>>> f(None=1) |
| 534 | +Traceback (most recent call last): |
| 535 | +SyntaxError: cannot assign to None |
530 | 536 | >>> f(__debug__=1) |
531 | 537 | Traceback (most recent call last): |
532 | 538 | SyntaxError: cannot assign to __debug__ |
|
Collapse file
Copy file name to clipboard +2Lines changed: 2 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +Improve the :exc:`SyntaxError` message when using ``True``, ``None`` or |
| 2 | +``False`` as keywords in a function call. Patch by Pablo Galindo. |