param icon indicating copy to clipboard operation
param copied to clipboard

Better error message from rx for `len`

Open jbednar opened this issue 1 year ago • 0 comments

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 avatar Jul 14 '24 22:07 jbednar