Skip to content
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 unwrap_or_raise_itself() if a value of Err is a BaseException #199

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Colk-tech
Copy link

@Colk-tech Colk-tech commented Oct 28, 2024

This PR enhances #192. If this is merged, Close: #192.

Rather than overriding the existing behavior of unwrap_or_raise(), I added a new method: unwrap_or_raise_itself().

With this addition, users can better determine if an Err value is a BaseException. This option may be helpful in such cases.

The unwrap_or_raise_itself() method is now available in both Ok and Err classes.

Example:

e = Err(RuntimeError("nay"))
e.unwrap_or_raise_itself()
>>> e.unwrap_or_raise_itself()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/colk/Repositories/github.com/Colk-tech/result/src/result/result.py", line 374, in unwrap_or_raise_itself
    raise self._value
RuntimeError: nay

By the way, this is my first time creating a PR for an OSS project, so I’d be grateful for any advice you might have :)

Comment on lines +376 to +379
raise UnwrapError(
self,
f"Called `Result.unwrap_or_raise_itself()` on non-exception value: {self._value}",
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which is preferred to raise, UnwrapError, TypeError or ValueError?

@Colk-tech Colk-tech changed the title feat: add unwrap_or_raise_itself() if the value of Err is a BaseException feat: add unwrap_or_raise_itself() if a value of Err is a BaseException Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant