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

Make Param._mapping public #3173

Merged
merged 2 commits into from
Feb 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions panel/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from .layout import Column, Panel, Row, Spacer, Tabs
from .pane.base import PaneBase, ReplacementPane
from .util import (
abbreviated_repr, full_groupby, get_method_owner, is_parameterized,
param_name, recursive_parameterized
abbreviated_repr, classproperty, full_groupby, get_method_owner,
is_parameterized, param_name, recursive_parameterized
)
from .reactive import Reactive
from .viewable import Layoutable, Viewable
Expand Down Expand Up @@ -150,11 +150,7 @@ class Param(PaneBase):
Dictionary of widget overrides, mapping from parameter name
to widget class.""")

priority = 0.1

_unpack = True

_mapping = {
mapping = {
param.Action: Button,
param.Boolean: Checkbox,
param.CalendarDate: DatePicker,
Expand All @@ -180,7 +176,11 @@ class Param(PaneBase):
}

if hasattr(param, 'Event'):
_mapping[param.Event] = Button
mapping[param.Event] = Button

priority = 0.1

_unpack = True

_rerender_params = []

Expand Down Expand Up @@ -227,6 +227,14 @@ def __init__(self, object=None, **params):
'hide_constant'])
self._update_widgets()

@classproperty
def _mapping(cls):
cls.param.warning(
"Param._mapping is now deprecated in favor of the public "
"Param.mapping attribute. Update your code accordingly."
)
return cls.mapping

def __repr__(self, depth=0):
cls = type(self).__name__
obj_cls = type(self.object).__name__
Expand Down Expand Up @@ -422,7 +430,7 @@ def widget(self, p_name):
if bounds[1] is not None:
kw['end'] = bounds[1]
if ('start' not in kw or 'end' not in kw):
# Do not change widget class if _mapping was overridden
# Do not change widget class if mapping was overridden
if not widget_class_overridden:
if (isinstance(p_obj, param.Number) and
not isinstance(p_obj, (param.Date, param.CalendarDate))):
Expand Down Expand Up @@ -657,10 +665,12 @@ def applies(cls, obj):
def widget_type(cls, pobj):
ptype = type(pobj)
for t in classlist(ptype)[::-1]:
if t in cls._mapping:
if isinstance(cls._mapping[t], types.FunctionType):
return cls._mapping[t](pobj)
return cls._mapping[t]
if t not in cls.mapping:
continue
wtype = cls.mapping[t]
if isinstance(wtype, types.FunctionType):
return wtype(pobj)
return wtype

def select(self, selector=None):
"""
Expand Down