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

Interaction between param.rx and isinstance #953

Open
LecrisUT opened this issue Jul 11, 2024 · 3 comments
Open

Interaction between param.rx and isinstance #953

LecrisUT opened this issue Jul 11, 2024 · 3 comments

Comments

@LecrisUT
Copy link

Is your feature request related to a problem? Please describe.

I couldn't find an relevant information on how to do an isinstance check of the inner object of the param.rx. Right now I have:

            if isinstance(field, param.rx):
                if field.rx.pipe(isinstance, xarray.DataArray):
                    curr_data = field

This could work, but feels a bit clunky. It would be much nicer if isinstance could work without having to check if it's a param.rx and then use pipe, e.g. by creating a dynamic class that inherits the type of the first definition, or any other way to override isinstance checks.

Describe alternatives you've considered

I have of course tried if it already works, but it doesn't seem to

import param
a = param.rx("string")
isinstance(a, str)

but this doesn't work

@jbednar jbednar changed the title Interaction between param.rx and isintance Interaction between param.rx and isinstance Jul 14, 2024
@jbednar
Copy link
Member

jbednar commented Jul 14, 2024

Good question! Would you be happy with a.rx.isinstance(str)? I think that would be the natural approach here, though we'd need to add that method.

@LecrisUT
Copy link
Author

As a clutch, it does help. The preferred interface would be to not have to check for isinstance(_, param.rx). Unfortunately the only method that I know would work is like attrs, but it is quite a redactor for that.

I'm still getting a hang of the .rx interface. I guess neither approach will work with if.

@maximlt
Copy link
Member

maximlt commented Jul 15, 2024

I'd prefer if isinstance resolved to the underlying value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants