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
Prev Previous commit
Next Next commit
Adrress feedback: Go back to previous wording for the error msg
  • Loading branch information
lysnikolaou committed Nov 7, 2022
commit 680c5cb20a9d819f1f355531ad866a3a196c5887
4 changes: 2 additions & 2 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1255,9 +1255,9 @@ invalid_try_stmt:
RAISE_INDENTATION_ERROR("expected an indented block after 'try' statement on line %d", a->lineno) }
| 'try' ':' block !('except' | 'finally') { RAISE_SYNTAX_ERROR("expected 'except' or 'finally' block") }
| 'try' ':' block* except_block+ a='except' b='*' expression ['as' NAME] ':' block* {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot have 'except*' in a 'try' statement with 'except'") }
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot have both 'except' and 'except*' on the same 'try'") }
| 'try' ':' block* except_star_block+ a='except' [expression ['as' NAME]] ':' block* {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot have 'except' in a 'try' statement with 'except*'") }
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot have both 'except' and 'except*' on the same 'try'") }
invalid_except_stmt:
| 'except' '*'? a=expression ',' expressions ['as' NAME ] ':' {
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }
Expand Down
12 changes: 6 additions & 6 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@
... except* ValueError:
... pass
Traceback (most recent call last):
SyntaxError: cannot have 'except*' in a 'try' statement with 'except'
SyntaxError: cannot have both 'except' and 'except*' on the same 'try'

>>> try:
... pass
Expand All @@ -1211,7 +1211,7 @@
... except ValueError:
... pass
Traceback (most recent call last):
SyntaxError: cannot have 'except' in a 'try' statement with 'except*'
SyntaxError: cannot have both 'except' and 'except*' on the same 'try'

>>> try:
... pass
Expand All @@ -1222,7 +1222,7 @@
... except* ValueError:
... pass
Traceback (most recent call last):
SyntaxError: cannot have 'except*' in a 'try' statement with 'except'
SyntaxError: cannot have both 'except' and 'except*' on the same 'try'

>>> try:
... pass
Expand All @@ -1233,7 +1233,7 @@
... except ValueError:
... pass
Traceback (most recent call last):
SyntaxError: cannot have 'except' in a 'try' statement with 'except*'
SyntaxError: cannot have both 'except' and 'except*' on the same 'try'

Ensure that early = are not matched by the parser as invalid comparisons
>>> f(2, 4, x=34); 1 $ 2
Expand Down Expand Up @@ -2016,12 +2016,12 @@ def test_generator_in_function_call(self):

def test_except_then_except_star(self):
self._check_error("try: pass\nexcept ValueError: pass\nexcept* TypeError: pass",
r"cannot have 'except\*' in a 'try' statement with 'except'",
r"cannot have both 'except' and 'except\*' on the same 'try'",
lineno=3, end_lineno=3, offset=1, end_offset=8)

def test_except_star_then_except(self):
self._check_error("try: pass\nexcept* ValueError: pass\nexcept TypeError: pass",
r"cannot have 'except' in a 'try' statement with 'except\*'",
r"cannot have both 'except' and 'except\*' on the same 'try'",
lineno=3, end_lineno=3, offset=1, end_offset=7)

def test_empty_line_after_linecont(self):
Expand Down
4 changes: 2 additions & 2 deletions Parser/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.