Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deal/_runtime/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ def raises(
"""Decorator listing the exceptions which the function can raise.

Implements [exception] contract.
If the function raises an exception not listed in the decorator,
If the function raises an exception not a subclass of the ones listed in the decorator,
`RaisesContractError` will be raised.

:param exceptions: exceptions which the function can raise.
:param exceptions: exceptions which the function can raise, including their subclasses.
:param message: error message for the exception raised on contract violation.
No error message by default.
:param exception: exception type to raise on the contract violation.
Expand Down
5 changes: 3 additions & 2 deletions deal/_runtime/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,9 @@ def _init(self, args: Args, kwargs: Kwargs, exc=None) -> None:
def _validate(self, args: Args, kwargs: Kwargs, exc: Exception | None = None) -> None:
assert exc is not None
exc_type = type(exc)
if exc_type in self.exceptions:
return
for exception in self.exceptions:
if issubclass(exc_type, exception):
return
raise self._exception() from exc_type


Expand Down