Repository navigation
⚖️ Substitution
A substitution of parties puts someone new in the case without disturbing it. The claim is the same, the record is the same, only the name on it changes. @probatio can now do that with the error it raises.
A library has its own exception hierarchy, and its callers expect one except to cover it. Put the decorator on a public method and an invalid argument raises MultipleInvalid instead, so the library ends up wrapping every decorated method to translate it. That is the same few lines in every library using the decorator.
class ClientValueError(ClientError, ValueError):
"""The caller passed an invalid argument."""
@probatio(error=ClientValueError)
async def stations(self, *, limit: Annotated[int, Range(min=0)] = 100) -> list[Station]: ...error takes an exception class, or any callable that receives the Invalid. What it returns is raised from the original, so the path and the sub errors stay reachable as __cause__. Substituted, not discharged.
Only argument validation is translated. A result failing returns still raises MultipleInvalid, because that is the function's mistake and not the caller's. A malformed call still raises the TypeError Python gives it. Whatever the body raises is left alone, so a rule spanning several arguments stays the library's own error and nothing of someone else's is quietly rewritten.
Leave error out and the wrapper is never added, so the default path costs nothing. An error that cannot be called is refused with a SchemaError while decorating, rather than at the first bad argument.
pip install probatio📚 Docs: https://probatio.frenck.dev
Put your data to the proof. ⚖️
../Frenck
Blogging my personal ramblings at frenck.dev
What's changed
✨ New features
⬆️ Dependency updates
- ⬆️ Update dependency @astrojs/starlight to v0.42.5 @renovate[bot] (#432)
- ⬆️ Update release-drafter/release-drafter action to v7.8.0 @renovate[bot] (#434)
- ⬆️ Update dependency ruff to v0.16.10 @renovate[bot] (#433)
- ⬆️ Update dependency mypy to v2.4.0 @renovate[bot] (#435)
- ⬆️ Update release-drafter/release-drafter action to v7.9.0 @renovate[bot] (#436)