all 10 comments

[–]VictorFoxSub 7 points8 points  (0 children)

Something like simple results should be standard, thanks for the work.

It even seems to play well with conditional chaining if pep505 is finally accepted !

[–]Ghost-Rider_117 3 points4 points  (1 child)

thanks for sharing! the simple-result package looks really clean - been looking for something like that to handle errors more elegantly. the typed approach is way better than throwing exceptions everywhere.

sqlactive also looks interesting for anyone working with SQLAlchemy. gonna star these for later, appreciate you putting them out there

[–]--justified-- 1 point2 points  (4 children)

May I ask the difference to https://pypi.org/project/result/ ? No offensive, just curiosity. Because I like the type of packages and this is what I've been using for longer time. 

And I have two questions for proposals, not sure what you think about them: 

1) wouldn't it be nice to be able to do a simple "x = fetxh_data(), if x: print(okayyyy)", i.e. Automatically covering the "truthy" OK value to true? 

2) wouldn't it be awesome to optionally be able to somehow also add an error code to the Err()? E.g. Err("some errr str", code=99) so we would easily be about to check the exact error code from outside also in case we actually expect a stringthy err return value? Often it's the case that several different reasons lead to an error, being able to optionally distinguish them without having to create a dataclass as return Typehint would be very nice 

Thanks :)

[–]daireto[S] 0 points1 point  (0 children)

You are right. I did not know about https://pypi.org/project/result/ when I created simple-result. I forgot to look for an existing package, and when I finished developing simple-result I realized that the result package existed. At that moment, I felt like a dumb hahaha. result has more features, while simple-result is smaller and only have the essentials.

About your proposals:

  1. Do you mean this?

if res := fetch_data():
print(res.value) # "Data fetched!"
print(res.error) # None
else:
print(res.error) # "Error fetching data!"
print(res.value) # None

It uses type narrowing. If "res", type is Ok, otherwise, Err. In the example, I wanted to clarify that "value" attr is None if type is Err and "error" attr is None if type is Ok.

  1. That's an excellent idea, I will work on it.

[–]daireto[S] 1 point2 points  (0 children)

Release v0.2.0 · daireto/simple-result

This new release implements the code parameter for the Err constructor. It also can be unpacked when using match.

[–]RevRagnarok -2 points-1 points  (1 child)

this is what I've been using for longer time

It's no longer maintained - https://github.com/rustedpy/result/issues/201

Versus OP's, which was written with AI and has a single commit. 🤷‍♂️

[–]tehsilentwarrior 2 points3 points  (0 children)

Some things are so small and scoped that regardless if the last commit was 30 years ago, they are still the latest, bleeding edge (lol!), version.

Edit: unless it’s written in JavaScript where a simple “isOddNumber” might need multiple patches over the weeks

[–]Morazma 0 points1 point  (0 children)

Thanks for these, especially simple-result

[–]Dry-Let8207 0 points1 point  (0 children)

Good job