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

mo.ui.anywidget doesn't show the api of widgets #2916

Open
metaboulie opened this issue Nov 21, 2024 · 1 comment
Open

mo.ui.anywidget doesn't show the api of widgets #2916

metaboulie opened this issue Nov 21, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@metaboulie
Copy link
Contributor

Describe the bug

Screen.Recording.2024-11-22.at.00.12.08.mov

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)
@metaboulie metaboulie added the bug Something isn't working label Nov 21, 2024
@mscolnick
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants