Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit84914ad

Browse files
authored
gh-133999: Fixexcept parsing regression in 3.14 (#134035)
1 parent7a9d462 commit84914ad

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

‎Grammar/python.gram

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,15 +1418,15 @@ invalid_except_stmt:
14181418
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized when using 'as'") }
14191419
| a='except' expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
14201420
| a='except' NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
1421-
| 'except' expression 'as' a=expression {
1421+
| 'except' expression 'as' a=expression':' block{
14221422
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
14231423
a, "cannot use except statement with %s", _PyPegen_get_expr_name(a)) }
14241424
invalid_except_star_stmt:
14251425
| 'except' '*' a=expression ',' expressions 'as' NAME ':' {
14261426
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized when using 'as'") }
14271427
| a='except' '*' expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
14281428
| a='except' '*' (NEWLINE | ':') { RAISE_SYNTAX_ERROR("expected one or more exception types") }
1429-
| 'except' '*' expression 'as' a=expression {
1429+
| 'except' '*' expression 'as' a=expression':' block{
14301430
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
14311431
a, "cannot use except* statement with %s", _PyPegen_get_expr_name(a)) }
14321432
invalid_finally_stmt:

‎Lib/test/test_syntax.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,23 @@
14311431
Traceback (most recent call last):
14321432
SyntaxError: cannot use except* statement with literal
14331433
1434+
Regression tests for gh-133999:
1435+
1436+
>>> try: pass
1437+
... except TypeError as name: raise from None
1438+
Traceback (most recent call last):
1439+
SyntaxError: invalid syntax
1440+
1441+
>>> try: pass
1442+
... except* TypeError as name: raise from None
1443+
Traceback (most recent call last):
1444+
SyntaxError: invalid syntax
1445+
1446+
>>> match 1:
1447+
... case 1 | 2 as abc: raise from None
1448+
Traceback (most recent call last):
1449+
SyntaxError: invalid syntax
1450+
14341451
Ensure that early = are not matched by the parser as invalid comparisons
14351452
>>> f(2, 4, x=34); 1 $ 2
14361453
Traceback (most recent call last):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix:exc:`SyntaxError` regression in:keyword:`except` parsing after
2+
:gh:`123440`.

‎Parser/parser.c

Lines changed: 22 additions & 10 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp