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

print reactive expression: TypeError: __str__ returned non-string (type rx) #1010

Open
MarcSkovMadsen opened this issue Dec 26, 2024 · 2 comments
Labels
type-bug Bug report

Comments

@MarcSkovMadsen
Copy link
Collaborator

I'm on the latest main branch of param. When trying to print a reactive expression it raises an exception

import param
rx_value = param.rx(10)
print(rx_value)
Traceback (most recent call last):
  File "/home/jovyan/repos/private/param/script.py", line 3, in <module>
    print(rx_value)
TypeError: __str__ returned non-string (type rx)

The workaround is to print rx_value.rx.value instead. But this would be confusing to a lot of users. Please fix.

@philippjfr philippjfr transferred this issue from holoviz/panel Jan 17, 2025
@jbednar
Copy link
Member

jbednar commented Jan 17, 2025

Hmm. I think it's important that casting an rx expression to a string still returns an rx expression, so that e.g. displaying some result as text or a label in a dashboard can be reactive. So I guess the issue is that the system print function isn't reactive aware? I don't know of a clean way to do it, though maybe mucking around with __builtin__.print could work.

If that's not feasible or too dirty, I guess we could add an .rx.print() method to https://param.holoviz.org/user_guide/Reactive_Expressions.html#special-methods-on-rx , but I'm not sure that would help much, because people then need to figure out to use it.

Any solution I'm missing here?

@maximlt
Copy link
Member

maximlt commented Feb 11, 2025

Duplicate of #939 which I'm closing in favor of this issue as Jim answered here.

@maximlt maximlt added the type-bug Bug report label Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Bug report
Projects
None yet
Development

No branches or pull requests

3 participants