-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add overload to unwrap_or_raise to raise the exception itself #192
base: main
Are you sure you want to change the base?
Conversation
596c871
to
e57b7f3
Compare
lacking a clear motivation for this change (hint hint), i'm not convinced how this is useful looking at the diff only. is the intention to make some context:
for >>> import result
>>> err = result.Err(ValueError("oops"))
>>> try:
... err.unwrap()
... except result.UnwrapError as exc:
... print(repr(exc))
... print(repr(exc.__cause__))
...
UnwrapError("Called `Result.unwrap()` on an `Err` value: ValueError('oops')")
ValueError('oops') |
I just want the Without this PR, I can only use |
this PR is strictly an API addition that is backwards compatible. before, the argument was required: def unwrap_or_raise(self, e: Type[TBE]) -> NoReturn: after, the argument is optional: def unwrap_or_raise(self, e: Optional[Type[TBE]] = None) -> NoReturn: the behaviour when passing an exception type (which was required before this PR) stays the same. so i don't think this needs a new method at all. in fact, with the new info and reasoning, i think this change is fine as-is. wdyt @francium? |
fwiw, though the mentioned work-around may work, it's not type safe:
… b/c that lambda is not an exception type. |
add overload to unwrap_or_raise to raise the exception itself