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

Remove Param _param_watchers compatibility code #7527

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions panel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from .__version import __version__
from .io.logging import panel_log_handler
from .io.state import state
from .util import param_watchers

_LOCAL_DEV_VERSION = (
any(v in __version__ for v in ('post', 'dirty'))
Expand Down Expand Up @@ -407,7 +406,7 @@ def __setattr__(self, attr, value):
if state.curdoc not in self._session_config:
self._session_config[state.curdoc] = {}
self._session_config[state.curdoc][attr] = value
watchers = param_watchers(self).get(attr, {}).get('value', [])
watchers = self.param.watchers.get(attr, {}).get('value', [])
for w in watchers:
w.fn()
elif f'_{attr}' in _config._parameter_set and hasattr(self, f'_{attr}_'):
Expand Down
5 changes: 2 additions & 3 deletions panel/io/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from bokeh.models import CustomJS

from ..config import config
from ..util import param_watchers
from .loading import LOADING_INDICATOR_CSS_CLASS
from .model import monkeypatch_events # noqa: F401 API import
from .state import curdoc_locked, state
Expand Down Expand Up @@ -120,10 +119,10 @@ def _cleanup_doc(doc, destroy=True):
pane._hooks = []
for p in pane.select():
p._hooks = []
param_watchers(p, {})
p.param.watchers = {}
p._documents = {}
p._internal_callbacks = {}
param_watchers(pane, {})
pane.param.watchers = {}
pane._documents = {}
pane._internal_callbacks = {}
else:
Expand Down
5 changes: 2 additions & 3 deletions panel/io/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from bokeh.models import CustomJS
from param.parameterized import Watcher

from ..util import param_watchers
from .model import add_to_doc, diff
from .state import state

Expand Down Expand Up @@ -82,7 +81,7 @@ def save_dict(state, key=(), depth=0, max_depth=None, save_path='', load_path=No


def get_watchers(reactive):
return [w for pwatchers in param_watchers(reactive).values()
return [w for pwatchers in reactive.param.watchers.values()
for awatchers in pwatchers.values() for w in awatchers]


Expand Down Expand Up @@ -158,7 +157,7 @@ def links_to_jslinks(model, widget):

mappings = []
for pname, tgt_spec in link.links.items():
if Watcher(*link[:-4]) in param_watchers(widget)[pname]['value']:
if Watcher(*link[:-4]) in widget.param.watchers[pname]['value']:
mappings.append((pname, tgt_spec))

if mappings:
Expand Down
4 changes: 2 additions & 2 deletions panel/layout/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from ..io.resources import CDN_DIST
from ..models import Column as PnColumn
from ..reactive import Reactive
from ..util import param_name, param_reprs, param_watchers
from ..util import param_name, param_reprs
from ..viewable import Children

if TYPE_CHECKING:
Expand Down Expand Up @@ -570,7 +570,7 @@ def __init__(self, *items: list[Any | tuple[str, Any]], **params: Any):
self.param.watch(self._update_names, 'objects')
# ALERT: Ensure that name update happens first, should be
# replaced by watch precedence support in param
param_watchers(self)['objects']['value'].reverse()
self.param.watchers['objects']['value'].reverse()

def _to_object_and_name(self, item):
from ..pane import panel
Expand Down
4 changes: 2 additions & 2 deletions panel/pane/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from ..links import Link
from ..models import ReactiveHTML as _BkReactiveHTML
from ..reactive import Reactive
from ..util import param_reprs, param_watchers
from ..util import param_reprs
from ..util.checks import is_dataframe, is_series
from ..util.parameters import get_params_to_inherit
from ..viewable import (
Expand Down Expand Up @@ -702,7 +702,7 @@ def _update_from_object(cls, object: Any, old_object: Any, was_internal: bool, i
custom_watchers = []
if isinstance(object, Reactive):
watchers = [
w for pwatchers in param_watchers(object).values()
w for pwatchers in object.param.watchers.values()
for awatchers in pwatchers.values() for w in awatchers
]
custom_watchers = [
Expand Down
3 changes: 1 addition & 2 deletions panel/tests/pane/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
Param, ParamFunction, ParamMethod, ParamRef, ReactiveExpr,
)
from panel.tests.util import check_layoutable_properties
from panel.util import param_watchers

SKIP_PANES = (
Bokeh, ChatMessage, HoloViews, Interactive, IPyWidget, Param,
Expand Down Expand Up @@ -90,7 +89,7 @@ def test_pane_untracked_watchers(pane, document, comm):
except ImportError:
pytest.skip("Dependent library could not be imported.")
watchers = [
w for pwatchers in param_watchers(p).values()
w for pwatchers in p.param.watchers.values()
for awatchers in pwatchers.values() for w in awatchers
]
assert len([wfn for wfn in watchers if wfn not in p._internal_callbacks and not hasattr(wfn.fn, '_watcher_name')]) == 0
Expand Down
3 changes: 1 addition & 2 deletions panel/tests/widgets/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from panel.layout import Row
from panel.links import CallbackGenerator
from panel.tests.util import check_layoutable_properties
from panel.util import param_watchers
from panel.widgets import (
CompositeWidget, Dial, FileDownload, FloatSlider, LinearGauge,
LoadingSpinner, Terminal, TextInput, ToggleGroup, Tqdm, Widget,
Expand Down Expand Up @@ -38,7 +37,7 @@ def test_widget_untracked_watchers(widget, document, comm):
except ImportError:
pytest.skip("Dependent library could not be imported.")
watchers = [
w for pwatchers in param_watchers(widg).values()
w for pwatchers in widg.param.watchers.values()
for awatchers in pwatchers.values() for w in awatchers
]
assert len([wfn for wfn in watchers if wfn not in widg._internal_callbacks and not hasattr(wfn.fn, '_watcher_name')]) == 0
Expand Down
2 changes: 1 addition & 1 deletion panel/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
is_series, isdatetime, isfile, isIn, isurl,
)
from .parameters import ( # noqa
edit_readonly, extract_dependencies, get_method_owner, param_watchers,
edit_readonly, extract_dependencies, get_method_owner,
recursive_parameterized,
)

Expand Down
17 changes: 0 additions & 17 deletions panel/util/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

import param

from packaging.version import Version

_unset = object()


def should_inherit(parameterized: param.Parameterized, p: str, v: Any) -> Any:
pobj = parameterized.param[p]
Expand Down Expand Up @@ -85,19 +81,6 @@ def extract_dependencies(function):
return params


def param_watchers(parameterized: param.Parameterized, value=_unset):
if Version(param.__version__) <= Version('2.0.0a2'):
if value is not _unset:
parameterized._param_watchers = value
else:
return parameterized._param_watchers
else:
if value is not _unset:
parameterized.param.watchers = value
else:
return parameterized.param.watchers


def recursive_parameterized(parameterized: param.Parameterized, objects=None) -> list[param.Parameterized]:
"""
Recursively searches a Parameterized object for other Parmeterized
Expand Down
Loading