-
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55afe5d
commit 505928d
Showing
4 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,7 @@ | |
Subscript, | ||
TryExcept, | ||
TryFinally, | ||
TryStar, | ||
Tuple, | ||
UnaryOp, | ||
Unknown, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html | ||
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE | ||
# Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt | ||
import pytest | ||
|
||
from astroid import ExceptHandler, TryExcept, extract_node | ||
from astroid.const import PY311_PLUS | ||
from astroid.nodes import TryStar | ||
|
||
|
||
@pytest.mark.skipif(not PY311_PLUS, reason="Requires Python 3.11 or higher") | ||
def test_group_exceptions() -> None: | ||
node = extract_node( | ||
""" | ||
try: | ||
raise ExceptionGroup("group", [ValueError(654)]) | ||
except ExceptionGroup as eg: | ||
for err in eg.exceptions: | ||
if isinstance(err, ValueError): | ||
print("Handling ValueError") | ||
elif isinstance(err, TypeError): | ||
print("Handling TypeError") | ||
""" | ||
) | ||
assert isinstance(node, TryExcept) | ||
handler = node.handlers[0] | ||
assert isinstance(handler, ExceptHandler) | ||
assert handler.type.name == "ExceptionGroup" | ||
|
||
|
||
@pytest.mark.skipif(not PY311_PLUS, reason="Requires Python 3.11 or higher") | ||
def test_star_exceptions() -> None: | ||
node = extract_node( | ||
""" | ||
try: | ||
raise ExceptionGroup("group", [ValueError(654)]) | ||
except* ValueError: | ||
print("Handling ValueError") | ||
except* TypeError: | ||
print("Handling TypeError") | ||
""" | ||
) | ||
assert isinstance(node, TryStar) | ||
assert node.handlers | ||
handler = node.handlers[0] | ||
assert isinstance(handler, ExceptHandler) | ||
assert handler.type.name == "ExceptionGroup" |