Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,24 @@ except OSError as e:
insta::assert_debug_snapshot!(parse_ast);
}

#[test]
fn test_try_unparenthesized_except_group() {
let parse_ast = ast::Suite::parse(
r#"try:
raise ValueError(1)
except TypeError, OSError:
print('caught')

try:
raise ExceptionGroup('eg', [KeyError()])
except* KeyError, IndexError:
print('caught')"#,
"<test>",
)
.unwrap();
insta::assert_debug_snapshot!(parse_ast);
}

#[test]
fn test_try_star() {
let parse_ast = ast::Suite::parse(
Expand Down
9 changes: 7 additions & 2 deletions parser/src/python.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,8 @@ TryStatement: ast::Stmt = {
};

ExceptStarClause: ast::ExceptHandler = {
<location:@L> "except" "*" <typ:Test<"all">> ":" <body:Suite> => {
// PEP 758 covers `except*` too.
<location:@L> "except" "*" <typ:GenericList<Test<"all">>> ":" <body:Suite> => {
let end_location = body.last().unwrap().end();
ast::ExceptHandler::ExceptHandler(
ast::ExceptHandlerExceptHandler {
Expand All @@ -904,7 +905,11 @@ ExceptStarClause: ast::ExceptHandler = {


ExceptClause: ast::ExceptHandler = {
<location:@L> "except" <typ:Test<"all">?> ":" <body:Suite> => {
// PEP 758: several exception types without parentheses, as long as there
// is no `as` clause. `GenericList` already collapses a single element to
// itself and wraps the rest in a tuple, which is exactly the shape CPython
// produces for `except A, B:`.
<location:@L> "except" <typ:GenericList<Test<"all">>?> ":" <body:Suite> => {
let end_location = body.last().unwrap().end();
ast::ExceptHandler::ExceptHandler(
ast::ExceptHandlerExceptHandler {
Expand Down
Loading
Loading