From 561660bfcf480cf7d3984abdbc98f2e5f09fe121 Mon Sep 17 00:00:00 2001
From: jakkdl
Date: Mon, 13 Jan 2025 17:07:53 +0100
Subject: [PATCH] add docstring to AbstractMatcher.matches to satisfy pyright
--verifytypes
---
src/trio/testing/_raises_group.py | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/trio/testing/_raises_group.py b/src/trio/testing/_raises_group.py
index f11e997d3..9f2072d56 100644
--- a/src/trio/testing/_raises_group.py
+++ b/src/trio/testing/_raises_group.py
@@ -252,7 +252,10 @@ def _check_match(self, e: BaseException) -> bool:
@abstractmethod
def matches(
self: AbstractMatcher[BaseExcT_1], exc_val: BaseException
- ) -> TypeGuard[BaseExcT_1]: ...
+ ) -> TypeGuard[BaseExcT_1]:
+ """Check if an exception matches the requirements of this AbstractMatcher.
+ If it fails, `AbstractMatcher.fail_reason` should be set.
+ """
@final
@@ -572,16 +575,13 @@ def __init__(
self.is_baseexceptiongroup |= exc.is_baseexceptiongroup
exc._nested = True
elif isinstance(exc, Matcher):
+ if exc.exception_type is not None:
+ # Matcher __init__ assures it's a subclass of BaseException
+ self.is_baseexceptiongroup |= not issubclass(
+ exc.exception_type,
+ Exception,
+ )
exc._nested = True
- # The Matcher could match BaseExceptions through the other arguments
- # but `self.is_baseexceptiongroup` is only used for printing.
- if exc.exception_type is None:
- continue
- # Matcher __init__ assures it's a subclass of BaseException
- self.is_baseexceptiongroup |= not issubclass(
- exc.exception_type,
- Exception,
- )
elif isinstance(exc, type) and issubclass(exc, BaseException):
self.is_baseexceptiongroup |= not issubclass(exc, Exception)
else: