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

Better error message from rx for len #954

Open
jbednar opened this issue Jul 14, 2024 · 0 comments
Open

Better error message from rx for len #954

jbednar opened this issue Jul 14, 2024 · 0 comments
Labels
type-feature Feature request
Milestone

Comments

@jbednar
Copy link
Member

jbednar commented Jul 14, 2024

Right now, len(x) on a reactive expression gives an error even on objects that do have a length:

from param import rx
l = rx([1,2,3])
print(l.rx.len())
len(l)
TypeError: object of type 'rx' has no len()

I believe we can't implement __len__ reactively, but can't we provide a better error message in this case? E.g. it seems like we could print a warning saying that the value returned won't be reactive (and what to do instead (.rx.len()), and then return the non-reactive length.

I'm not sure if there are any other such methods where we can similarly help guide the rx user towards correct code with less pain.

@jbednar jbednar added type-feature Feature request TRIAGE User-submitted issue that hasn't been triaged yet. labels Jul 14, 2024
@philippjfr philippjfr removed the TRIAGE User-submitted issue that hasn't been triaged yet. label Jul 27, 2024
@philippjfr philippjfr added this to the v2.2.0 milestone Jul 27, 2024
@maximlt maximlt modified the milestones: v2.2.0, v2.x Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature Feature request
Projects
None yet
Development

No branches or pull requests

3 participants