Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,13 @@ except_block[excepthandler_ty]:
_PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
| 'except' ':' b=block { _PyAST_ExceptHandler(NULL, NULL, b, EXTRA) }
| invalid_except_stmt
| invalid_except_as_expr
except_star_block[excepthandler_ty]:
| invalid_except_star_stmt_indent
| 'except' '*' e=expression t=['as' z=NAME { z }] ':' b=block {
_PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
| invalid_except_stmt
| invalid_except_star_as_expr
finally_block[asdl_stmt_seq*]:
| invalid_finally_stmt
| 'finally' &&':' a=block { a }
Expand Down Expand Up @@ -1345,6 +1347,14 @@ invalid_except_stmt:
| a='except' '*'? expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
| a='except' NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
| a='except' '*' (NEWLINE | ':') { RAISE_SYNTAX_ERROR("expected one or more exception types") }
invalid_except_as_expr:
| 'except' expression 'as' a=expression {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
a, "cannot use except statement with %s", _PyPegen_get_expr_name(a)) }
invalid_except_star_as_expr:
| 'except' '*' expression 'as' a=expression {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
a, "cannot use except* statement with %s", _PyPegen_get_expr_name(a)) }
Comment thread
sobolevn marked this conversation as resolved.
Resolved
invalid_finally_stmt:
| a='finally' ':' NEWLINE !INDENT {
RAISE_INDENTATION_ERROR("expected an indented block after 'finally' statement on line %d", a->lineno) }
Expand Down
30 changes: 30 additions & 0 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,36 @@
Traceback (most recent call last):
SyntaxError: cannot have both 'except' and 'except*' on the same 'try'

Better error message for using `except as` with not a name:

>>> try:
... pass
... except TypeError as obj.attr:
... pass
Traceback (most recent call last):
SyntaxError: cannot use except statement with attribute
Comment thread
sobolevn marked this conversation as resolved.
Resolved

>>> try:
... pass
... except TypeError as obj[1]:
... pass
Traceback (most recent call last):
SyntaxError: cannot use except statement with subscript

>>> try:
... pass
... except* TypeError as (obj, name):
... pass
Traceback (most recent call last):
SyntaxError: cannot use except* statement with tuple

>>> try:
... pass
... except* TypeError as 1:
... pass
Traceback (most recent call last):
SyntaxError: cannot use except* statement with literal

Ensure that early = are not matched by the parser as invalid comparisons
>>> f(2, 4, x=34); 1 $ 2
Traceback (most recent call last):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve :exc:`SyntaxError` message for using ``except as`` with not a name.
Loading