mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-19 11:05:45 +00:00
Merge pull request #4531 from charliermarsh/charlie/exception-groups
Implement except* syntax
This commit is contained in:
commit
304f6bc38e
8 changed files with 1468 additions and 0 deletions
|
@ -417,6 +417,37 @@ array[3:5, *idxs_to_select]
|
|||
insta::assert_debug_snapshot!(parse_ast);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_try() {
|
||||
let parse_ast = parse_program(
|
||||
r#"try:
|
||||
raise ValueError(1)
|
||||
except TypeError as e:
|
||||
print(f'caught {type(e)}')
|
||||
except OSError as e:
|
||||
print(f'caught {type(e)}')"#,
|
||||
"<test>",
|
||||
)
|
||||
.unwrap();
|
||||
insta::assert_debug_snapshot!(parse_ast);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_try_star() {
|
||||
let parse_ast = parse_program(
|
||||
r#"try:
|
||||
raise ExceptionGroup("eg",
|
||||
[ValueError(1), TypeError(2), OSError(3), OSError(4)])
|
||||
except* TypeError as e:
|
||||
print(f'caught {type(e)} with nested {e.exceptions}')
|
||||
except* OSError as e:
|
||||
print(f'caught {type(e)} with nested {e.exceptions}')"#,
|
||||
"<test>",
|
||||
)
|
||||
.unwrap();
|
||||
insta::assert_debug_snapshot!(parse_ast);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dict_unpacking() {
|
||||
let parse_ast = parse_expression(r#"{"a": "b", **c, "d": "e"}"#, "<test>").unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue