-
-
Notifications
You must be signed in to change notification settings - Fork 119
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
Bind composite errors #1975
base: master
Are you sure you want to change the base?
Bind composite errors #1975
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about this feature :)
As I told you in the chat.
But, anyway - thanks a lot for working on it!
Do you see any alternatives?
@@ -119,9 +119,9 @@ def bind( | |||
self, | |||
function: Callable[ | |||
[_ValueType], | |||
Kind2['Result', _NewValueType, _ErrorType], | |||
Kind2['Result', _NewValueType, _ErrorType | _NewErrorType], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this approach is that it works with Exception
subtypes, but it does not work if you have Result[int, int]
and Result[int, str]
How would you compose these two objects? Result[int, int | str]
might not make any sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you compose these two objects?
Result[int, int | str]
might not make any sense.
Thank you for the review! I see your point, but isn’t int | str
better than dealing with Any
? At least with int | str
, we can use pattern matching to handle each case explicitly.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1975 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 80 81 +1
Lines 2485 2601 +116
Branches 437 44 -393
==========================================
+ Hits 2485 2601 +116 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I tested this out. Right now I kinda agree that this makes a lot of inference better.
But, in case we are adopting it - we need to make sure that all ResultLike
behave the same way. Can you please address this?
I have made things!
Checklist
CHANGELOG.md
Related issues
This pull request fixes the issue of error types not composing in chains by using Union, improving clarity and type safety. However,
Any
can still appear in some cases. SettingSuccess
andFailure
to use_Nothing
orNoReturn
instead ofAny
helps with type inference but breaks many existing tests. I’m not an expert in type theory, but personally, I’d find it very useful to see fully composed error types withoutAny