Replies: 4 comments
-
Alternatively, imports are fine and I shouldn't worry about this :) |
Beta Was this translation helpful? Give feedback.
-
yep, it's possible, and I do something similar in magicgui's you'll note there, however, all of the extra |
Beta Was this translation helpful? Give feedback.
-
Thanks for the hint :) BTW, is it possible to propagate the type annotations for EDIT: just seeing https://psygnal.readthedocs.io/en/latest/dataclasses/#type-annotating-evented-dataclasses |
Beta Was this translation helpful? Give feedback.
-
Second, I'm wondering about how we could annotate fields for custom serialization/deserialization? Would this be something like from anywidget.experimental import dataclass
import ipywidgets
from typing import Annotated
@dataclass(esm="index.js")
class LayoutWidget:
children: Annotated[list[ipywidgets.Widget], ipywidgets.widget_serialization] Or somehow overload |
Beta Was this translation helpful? Give feedback.
-
We added in
widget
decorator in #126.This is still a little clunky to use as it adds several imports:
It would be nice if
widget
could be smarter and reduced to something like:but the point of the descriptor API to to allow flexibility for modeling/serializing data and emitting events, so I'm not sure I want this to be too magical/opinionated.
I guess the use case I am really interested in is prototyping and avoiding imports. I'd like to have one import and get away with type-hints only if possible. Some prior art, but maybe we can just add a
dataclass
API of our own like pydantic.Not sure if you have any thoughts @tlambert03
Beta Was this translation helpful? Give feedback.
All reactions