Return `True` if a `BaseExceptionGroup` contains a matching exception.
(
self,
exc_group: BaseExceptionGroup[BaseException],
expected_exception: EXCEPTION_OR_MORE,
match: str | re.Pattern[str] | None,
target_depth: int | None = None,
current_depth: int = 1,
)
| 793 | return True |
| 794 | |
| 795 | def _group_contains( |
| 796 | self, |
| 797 | exc_group: BaseExceptionGroup[BaseException], |
| 798 | expected_exception: EXCEPTION_OR_MORE, |
| 799 | match: str | re.Pattern[str] | None, |
| 800 | target_depth: int | None = None, |
| 801 | current_depth: int = 1, |
| 802 | ) -> bool: |
| 803 | """Return `True` if a `BaseExceptionGroup` contains a matching exception.""" |
| 804 | if (target_depth is not None) and (current_depth > target_depth): |
| 805 | # already descended past the target depth |
| 806 | return False |
| 807 | for exc in exc_group.exceptions: |
| 808 | if isinstance(exc, BaseExceptionGroup): |
| 809 | if self._group_contains( |
| 810 | exc, expected_exception, match, target_depth, current_depth + 1 |
| 811 | ): |
| 812 | return True |
| 813 | if (target_depth is not None) and (current_depth != target_depth): |
| 814 | # not at the target depth, no match |
| 815 | continue |
| 816 | if not isinstance(exc, expected_exception): |
| 817 | continue |
| 818 | if match is not None: |
| 819 | value = stringify_exception(exc) |
| 820 | if not re.search(match, value): |
| 821 | continue |
| 822 | return True |
| 823 | return False |
| 824 | |
| 825 | def group_contains( |
| 826 | self, |
no test coverage detected