You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Libraries like Pydantic, attrs, Traitlets and the built-in dataclasses all offer a way to attach metadata to their field/attributes with some more or less convenient API to retrieve them. Parameters in Param doesn't have a similar slot.
From experience I know I've needed that a few times and I've definitely abused the precedence slot to attach some data to Parameters.
Another motivation to add a metadata slot is related to Panel. The Param Pane offered by Panel is very practical to turn a Parameterized class into a viewable component, Panel maintaining a mapping between Parameter types and its widget types. However, sometimes one needs to configure a widget just a bit more and in this case Panel offers two approaches shown below: (1) pass additional widget configs to pn.Param or (2) use <WidgetClass>.from_param(<parameter>, ...) to instantiate a widget manually.
I tend to use option (2) as there's often something custom I need to do (e.g. adding some text in between widgets, laying them out in a special way) that isn't made possible by (1), or at least not in a straightforward way. This makes the code quite verbose. Instead Panel could leverage the metadata slot to automatically pass widget kwargs collected from a special namespace (e.g. panel_kwargs) to .from_param() (that I believe is used in the implementation of pn.Param):
Libraries like Pydantic, attrs, Traitlets and the built-in dataclasses all offer a way to attach metadata to their field/attributes with some more or less convenient API to retrieve them.
Parameter
s in Param doesn't have a similar slot.From experience I know I've needed that a few times and I've definitely abused the
precedence
slot to attach some data to Parameters.Another motivation to add a
metadata
slot is related to Panel. TheParam
Pane offered by Panel is very practical to turn a Parameterized class into a viewable component, Panel maintaining a mapping between Parameter types and its widget types. However, sometimes one needs to configure a widget just a bit more and in this case Panel offers two approaches shown below: (1) pass additional widget configs topn.Param
or (2) use<WidgetClass>.from_param(<parameter>, ...)
to instantiate a widget manually.I tend to use option (2) as there's often something custom I need to do (e.g. adding some text in between widgets, laying them out in a special way) that isn't made possible by (1), or at least not in a straightforward way. This makes the code quite verbose. Instead Panel could leverage the
metadata
slot to automatically pass widget kwargs collected from a special namespace (e.g.panel_kwargs
) to.from_param()
(that I believe is used in the implementation ofpn.Param
):This was recently discussed in holoviz/panel#5856.
metadata attribute in dataclasses, attrs, pydantic and traitlets:
Code
The text was updated successfully, but these errors were encountered: