mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-136616: Improve assert syntax error messages (#136653)
This commit is contained in:
parent
66ef16105a
commit
6bc65c30ff
4 changed files with 594 additions and 400 deletions
|
|
@ -212,7 +212,9 @@ del_stmt[stmt_ty]:
|
|||
|
||||
yield_stmt[stmt_ty]: y=yield_expr { _PyAST_Expr(y, EXTRA) }
|
||||
|
||||
assert_stmt[stmt_ty]: 'assert' a=expression b=[',' z=expression { z }] { _PyAST_Assert(a, b, EXTRA) }
|
||||
assert_stmt[stmt_ty]:
|
||||
| invalid_assert_stmt
|
||||
| 'assert' a=expression b=[',' z=expression { z }] { _PyAST_Assert(a, b, EXTRA) }
|
||||
|
||||
import_stmt[stmt_ty]:
|
||||
| invalid_import
|
||||
|
|
@ -1302,6 +1304,17 @@ invalid_raise_stmt:
|
|||
invalid_del_stmt:
|
||||
| 'del' a=star_expressions {
|
||||
RAISE_SYNTAX_ERROR_INVALID_TARGET(DEL_TARGETS, a) }
|
||||
invalid_assert_stmt:
|
||||
| 'assert' a=expression '=' b=expression {
|
||||
RAISE_SYNTAX_ERROR_KNOWN_RANGE(
|
||||
a, b,
|
||||
"cannot assign to %s here. Maybe you meant '==' instead of '='?",
|
||||
_PyPegen_get_expr_name(a)) }
|
||||
| 'assert' expression ',' a=expression '=' b=expression {
|
||||
RAISE_SYNTAX_ERROR_KNOWN_RANGE(
|
||||
a, b,
|
||||
"cannot assign to %s here. Maybe you meant '==' instead of '='?",
|
||||
_PyPegen_get_expr_name(a)) }
|
||||
invalid_block:
|
||||
| NEWLINE !INDENT { RAISE_INDENTATION_ERROR("expected an indented block") }
|
||||
invalid_comprehension:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue