Skip to content

Commit

Permalink
okay actually for real for real rename reqs->parameters. update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl committed Jan 23, 2025
1 parent dff6377 commit 8cb294f
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/trio/testing/_raises_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ def _check_match(self, e: BaseException) -> bool:
self._fail_reason += "\n Did you mean to `re.escape()` the regex?"
return False

# TODO: when transitioning to pytest, harmonize Matcher and RaisesGroup
# signatures. One names the parameter `exc_val` and the other `exception`
@abstractmethod
def matches(
self: AbstractMatcher[BaseExcT_1], exc_val: BaseException
Expand Down Expand Up @@ -282,7 +284,7 @@ class Matcher(AbstractMatcher[MatchE]):
# At least one of the three parameters must be passed.
@overload
def __init__(
self: Matcher[MatchE],
self,
exception_type: type[MatchE],
match: str | Pattern[str] = ...,
check: Callable[[MatchE], bool] = ...,
Expand Down Expand Up @@ -616,20 +618,20 @@ def __enter__(self) -> ExceptionInfo[BaseExceptionGroup[BaseException]]:
return self.excinfo

def __repr__(self) -> str:
reqs = [
parameters = [
e.__name__ if isinstance(e, type) else repr(e)
for e in self.expected_exceptions
]
if self.allow_unwrapped:
reqs.append(f"allow_unwrapped={self.allow_unwrapped}")
parameters.append(f"allow_unwrapped={self.allow_unwrapped}")
if self.flatten_subgroups:
reqs.append(f"flatten_subgroups={self.flatten_subgroups}")
parameters.append(f"flatten_subgroups={self.flatten_subgroups}")
if self.match is not None:
# If no flags were specified, discard the redundant re.compile() here.
reqs.append(f"match={_match_pattern(self.match)!r}")
parameters.append(f"match={_match_pattern(self.match)!r}")
if self.check is not None:
reqs.append(f"check={repr_callable(self.check)}")
return f"RaisesGroup({', '.join(reqs)})"
parameters.append(f"check={repr_callable(self.check)}")
return f"RaisesGroup({', '.join(parameters)})"

def _unroll_exceptions(
self,
Expand Down Expand Up @@ -982,9 +984,9 @@ def set_result(self, expected: int, actual: int, result: str | None) -> None:

def get_result(self, expected: int, actual: int) -> str | None:
res = self.results[actual][expected]
assert res is not NotChecked
# why doesn't mypy pick up on the above assert?
return res # type: ignore[return-value]
# mypy doesn't support `assert res is not NotChecked`
assert not isinstance(res, type)
return res

def has_result(self, expected: int, actual: int) -> bool:
return self.results[actual][expected] is not NotChecked
Expand Down

0 comments on commit 8cb294f

Please sign in to comment.