Skip to content

Better error message from rx for len #954

@jbednar

Description

@jbednar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions