File tree 2 files changed +9
-17
lines changed 2 files changed +9
-17
lines changed Original file line number Diff line number Diff line change @@ -593,26 +593,18 @@ def exconly(self, tryshort: bool = False) -> str:
593
593
def _get_single_subexc (
594
594
eg : BaseExceptionGroup [BaseException ],
595
595
) -> BaseException | None :
596
- res : BaseException | None = None
597
- for subexc in eg .exceptions :
598
- if res is not None :
599
- return None
600
-
601
- if isinstance (subexc , BaseExceptionGroup ):
602
- res = _get_single_subexc (subexc )
603
- if res is None :
604
- # there were multiple exceptions in the subgroup
605
- return None
606
- else :
607
- res = subexc
608
- return res
596
+ if len (eg .exceptions ) != 1 :
597
+ return None
598
+ if isinstance (e := eg .exceptions [0 ], BaseExceptionGroup ):
599
+ return _get_single_subexc (e )
600
+ return e
609
601
610
602
if (
611
603
tryshort
612
604
and isinstance (self .value , BaseExceptionGroup )
613
605
and (subexc := _get_single_subexc (self .value )) is not None
614
606
):
615
- return f"[ in { type (self .value ).__name__ } ] { subexc !r } "
607
+ return f"{ subexc !r } [single exception in { type (self .value ).__name__ } ]"
616
608
617
609
lines = format_exception_only (self .type , self .value )
618
610
text = "" .join (lines )
Original file line number Diff line number Diff line change @@ -1757,15 +1757,15 @@ def test_nested_multiple() -> None:
1757
1757
"*= short test summary info =*" ,
1758
1758
(
1759
1759
"FAILED test_exceptiongroup_short_summary_info.py::test_base - "
1760
- "[in BaseExceptionGroup] SystemExit('aaaaaaaaaa')"
1760
+ "SystemExit('aaaaaaaaaa') [single exception in BaseExceptionGroup] "
1761
1761
),
1762
1762
(
1763
1763
"FAILED test_exceptiongroup_short_summary_info.py::test_nonbase - "
1764
- "[in ExceptionGroup] ValueError('aaaaaaaaaa')"
1764
+ "ValueError('aaaaaaaaaa') [single exception in ExceptionGroup] "
1765
1765
),
1766
1766
(
1767
1767
"FAILED test_exceptiongroup_short_summary_info.py::test_nested - "
1768
- "[in ExceptionGroup] ValueError('aaaaaaaaaa')"
1768
+ "ValueError('aaaaaaaaaa') [single exception in ExceptionGroup] "
1769
1769
),
1770
1770
(
1771
1771
"FAILED test_exceptiongroup_short_summary_info.py::test_multiple - "
You can’t perform that action at this time.
0 commit comments