-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Better error when calling len() on a reactive expression #1033
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1033 +/- ##
==========================================
+ Coverage 87.27% 87.28% +0.01%
==========================================
Files 9 9
Lines 4928 4932 +4
==========================================
+ Hits 4301 4305 +4
Misses 627 627 ☔ 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.
Looks good! This seems like excellent feedback to a user, telling them precisely what they need to know ("hey -- this isn't going to work! Did you mean a, or b, both of which would work, but they're different"). Nice!
Can we be similarly helpful for the other unimplementable bits of the rx space?
I'm not sure to be honest and none comes to mind from my experience of using rx, that is in fact quite limited. |
The only thing we could realistically do is error on |
Yes I thought about |
Closes #954
The suggestion in the issue was:
I am not in favor of emitting a warning and returning the non-reactive length as this sets a bit of a weird precedent (we could do the same for other parts of the Python data model we can't proxy). Instead with this PR a
TypeError
is raised with a more explicit message. Note that if in the future we decide to warn and return the non-reactive length, that PR makes it still possible.After implementing that, this test started to fail:
It turns out that:
assert l.rx.value == 2
.l == 2
returns a reactive expression that is truthy__bool__
first and__len__
second. Sincerx
did not implement__bool__
and this PR added__len__
with a TypeError, callingbool(<rx_obj>)
(orif <rx_obj>: ...
) started to emit an error.This PR resolves that by:
rx.__bool__
that always returnsTrue
like it used to before the PR.