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

Commit152a437

Browse files
authored
[3.11]gh-99211: Point to except/except* on syntax errors when mixing them (GH-99215) (GH-99622)
gh-99211: Point to except/except* on syntax errors when mixing them (GH-99215)(cherry picked from commit9c4232a)
1 parent56a517e commit152a437

File tree

3 files changed

+718
-674
lines changed

3 files changed

+718
-674
lines changed

‎Grammar/python.gram

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,9 @@ invalid_try_stmt:
12471247
| a='try' ':' NEWLINE !INDENT {
12481248
RAISE_INDENTATION_ERROR("expected an indented block after 'try' statement on line %d", a->lineno) }
12491249
| 'try' ':' block !('except' | 'finally') { RAISE_SYNTAX_ERROR("expected 'except' or 'finally' block") }
1250-
| a='try' ':' block* ((except_block+ except_star_block) | (except_star_block+ except_block)) block* {
1250+
| 'try' ':' block* except_block+ a='except' b='*' expression ['as' NAME] ':' {
1251+
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot have both 'except' and 'except*' on the same 'try'") }
1252+
| 'try' ':' block* except_star_block+ a='except' [expression ['as' NAME]] ':' {
12511253
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot have both 'except' and 'except*' on the same 'try'") }
12521254
invalid_except_stmt:
12531255
| 'except' '*'? a=expression ',' expressions ['as' NAME ] ':' {

‎Lib/test/test_syntax.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,12 +1988,12 @@ def test_generator_in_function_call(self):
19881988
deftest_except_then_except_star(self):
19891989
self._check_error("try: pass\nexcept ValueError: pass\nexcept* TypeError: pass",
19901990
r"cannot have both 'except' and 'except\*' on the same 'try'",
1991-
lineno=1,end_lineno=1,offset=1,end_offset=4)
1991+
lineno=3,end_lineno=3,offset=1,end_offset=8)
19921992

19931993
deftest_except_star_then_except(self):
19941994
self._check_error("try: pass\nexcept* ValueError: pass\nexcept TypeError: pass",
19951995
r"cannot have both 'except' and 'except\*' on the same 'try'",
1996-
lineno=1,end_lineno=1,offset=1,end_offset=4)
1996+
lineno=3,end_lineno=3,offset=1,end_offset=7)
19971997

19981998
deftest_empty_line_after_linecont(self):
19991999
# See issue-40847

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp