File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,11 @@ Release date: TBA
87
87
* Improve ``as_string()`` representation for ``TypeVar``, ``ParamSpec`` and ``TypeVarTuple`` nodes, as well as
88
88
type parameter in ``ClassDef``, ``FuncDef`` and ``TypeAlias`` nodes (PEP 695).
89
89
90
+ * Astroid now correctly supports the ``exceptions`` attribute of ``ExceptionGroup``.
91
+
92
+ Closes pylint-dev/pylint#8985
93
+ Closes pylint-dev/pylint#10558
94
+
90
95
91
96
What's New in astroid 3.3.11?
92
97
=============================
Original file line number Diff line number Diff line change @@ -770,6 +770,12 @@ def attr_text(self):
770
770
return node_classes .Const ("" )
771
771
772
772
773
+ class GroupExceptionInstanceModel (ExceptionInstanceModel ):
774
+ @property
775
+ def attr_exceptions (self ) -> nodes .Tuple :
776
+ return node_classes .Tuple (parent = self ._instance )
777
+
778
+
773
779
class OSErrorInstanceModel (ExceptionInstanceModel ):
774
780
@property
775
781
def attr_filename (self ):
@@ -804,6 +810,7 @@ def attr_object(self):
804
810
805
811
BUILTIN_EXCEPTIONS = {
806
812
"builtins.SyntaxError" : SyntaxErrorInstanceModel ,
813
+ "builtins.ExceptionGroup" : GroupExceptionInstanceModel ,
807
814
"builtins.ImportError" : ImportErrorInstanceModel ,
808
815
"builtins.UnicodeDecodeError" : UnicodeDecodeErrorInstanceModel ,
809
816
# These are all similar to OSError in terms of attributes
Original file line number Diff line number Diff line change 12
12
List ,
13
13
Name ,
14
14
Try ,
15
+ Tuple ,
15
16
Uninferable ,
16
17
bases ,
17
18
extract_node ,
21
22
from astroid .nodes import Expr , Raise , TryStar
22
23
23
24
25
+ @pytest .mark .skipif (not PY311_PLUS , reason = "Exception group introduced in Python 3.11" )
26
+ def test_group_exceptions_exceptions () -> None :
27
+ node = extract_node (
28
+ textwrap .dedent (
29
+ """
30
+ try:
31
+ raise ExceptionGroup('', [TypeError(), TypeError()])
32
+ except ExceptionGroup as eg:
33
+ eg.exceptions #@"""
34
+ )
35
+ )
36
+
37
+ inferred = node .inferred ()[0 ]
38
+ assert isinstance (inferred , Tuple )
39
+
40
+
24
41
@pytest .mark .skipif (not PY311_PLUS , reason = "Requires Python 3.11 or higher" )
25
42
def test_group_exceptions () -> None :
26
43
node = extract_node (
You can’t perform that action at this time.
0 commit comments