marimo
marimo copied to clipboard
mo.ui.anywidget doesn't show the api of widgets
Describe the bug
https://github.com/user-attachments/assets/d9e96a18-4078-46d4-8ddf-92e9edab87c6
Environment
{
"marimo": "0.9.20",
"OS": "Darwin",
"OS Version": "24.0.0",
"Processor": "arm",
"Python Version": "3.12.7",
"Binaries": {
"Browser": "--",
"Node": "v23.2.0"
},
"Dependencies": {
"click": "8.1.7",
"docutils": "0.21.2",
"itsdangerous": "2.2.0",
"jedi": "0.19.2",
"markdown": "3.7",
"narwhals": "1.13.3",
"packaging": "24.2",
"psutil": "6.1.0",
"pygments": "2.18.0",
"pymdown-extensions": "10.12",
"pyyaml": "6.0.2",
"ruff": "0.7.3",
"starlette": "0.41.2",
"tomlkit": "0.13.2",
"typing-extensions": "4.12.2",
"uvicorn": "0.32.0",
"websockets": "12.0"
},
"Optional Dependencies": {
"anywidget": "0.9.13"
}
}
Code to reproduce
import marimo as mo
import anywidget
import traitlets
class Foo(anywidget.AnyWidget):
_esm = ""
_css = ""
def foo(self, arg_1, arg_2):
"""A dummy method."""
return arg_1 + arg_2
mo_widget = mo.ui.anywidget(Foo())
widget = Foo()
mo_widget.foo(1, 2)
widget.foo(1, 2)
In case anyone else has ideas, I tried adding this code to class anywidget's __init__:
# Copy annotations
self.__annotations__ = getattr(widget.__class__, "__annotations__", {})
# Add runtime-discovered attributes to annotations
for name in dir(widget):
if not name.startswith("_"):
attr = getattr(widget, name)
self.__annotations__[name] = type(attr)
but it did not end up working