@@ -251,6 +251,8 @@ def _check_match(self, e: BaseException) -> bool:
251
251
self ._fail_reason += "\n Did you mean to `re.escape()` the regex?"
252
252
return False
253
253
254
+ # TODO: when transitioning to pytest, harmonize Matcher and RaisesGroup
255
+ # signatures. One names the parameter `exc_val` and the other `exception`
254
256
@abstractmethod
255
257
def matches (
256
258
self : AbstractMatcher [BaseExcT_1 ], exc_val : BaseException
@@ -282,7 +284,7 @@ class Matcher(AbstractMatcher[MatchE]):
282
284
# At least one of the three parameters must be passed.
283
285
@overload
284
286
def __init__ (
285
- self : Matcher [ MatchE ] ,
287
+ self ,
286
288
exception_type : type [MatchE ],
287
289
match : str | Pattern [str ] = ...,
288
290
check : Callable [[MatchE ], bool ] = ...,
@@ -616,20 +618,20 @@ def __enter__(self) -> ExceptionInfo[BaseExceptionGroup[BaseException]]:
616
618
return self .excinfo
617
619
618
620
def __repr__ (self ) -> str :
619
- reqs = [
621
+ parameters = [
620
622
e .__name__ if isinstance (e , type ) else repr (e )
621
623
for e in self .expected_exceptions
622
624
]
623
625
if self .allow_unwrapped :
624
- reqs .append (f"allow_unwrapped={ self .allow_unwrapped } " )
626
+ parameters .append (f"allow_unwrapped={ self .allow_unwrapped } " )
625
627
if self .flatten_subgroups :
626
- reqs .append (f"flatten_subgroups={ self .flatten_subgroups } " )
628
+ parameters .append (f"flatten_subgroups={ self .flatten_subgroups } " )
627
629
if self .match is not None :
628
630
# If no flags were specified, discard the redundant re.compile() here.
629
- reqs .append (f"match={ _match_pattern (self .match )!r} " )
631
+ parameters .append (f"match={ _match_pattern (self .match )!r} " )
630
632
if self .check is not None :
631
- reqs .append (f"check={ repr_callable (self .check )} " )
632
- return f"RaisesGroup({ ', ' .join (reqs )} )"
633
+ parameters .append (f"check={ repr_callable (self .check )} " )
634
+ return f"RaisesGroup({ ', ' .join (parameters )} )"
633
635
634
636
def _unroll_exceptions (
635
637
self ,
@@ -982,9 +984,9 @@ def set_result(self, expected: int, actual: int, result: str | None) -> None:
982
984
983
985
def get_result (self , expected : int , actual : int ) -> str | None :
984
986
res = self .results [actual ][expected ]
985
- assert res is not NotChecked
986
- # why doesn't mypy pick up on the above assert?
987
- return res # type: ignore[return-value]
987
+ # mypy doesn't support ` assert res is not NotChecked`
988
+ assert not isinstance ( res , type )
989
+ return res
988
990
989
991
def has_result (self , expected : int , actual : int ) -> bool :
990
992
return self .results [actual ][expected ] is not NotChecked
0 commit comments