diff --git a/param/depends.py b/param/depends.py index 2943224ec..7b16889d4 100644 --- a/param/depends.py +++ b/param/depends.py @@ -4,7 +4,7 @@ from functools import wraps from .parameterized import ( - Parameter, Parameterized, ParameterizedMetaclass, transform_dependency, + Parameter, Parameterized, ParameterizedMetaclass, transform_reference, ) from ._utils import accept_arguments, iscoroutinefunction @@ -48,8 +48,8 @@ def depends(func, *dependencies, watch=False, on_init=False, **kw): by default False """ dependencies, kw = ( - tuple(transform_dependency(arg) for arg in dependencies), - {key: transform_dependency(arg) for key, arg in kw.items()} + tuple(transform_reference(arg) for arg in dependencies), + {key: transform_reference(arg) for key, arg in kw.items()} ) if iscoroutinefunction(func): diff --git a/param/parameterized.py b/param/parameterized.py index 11c496219..dd93b57fd 100644 --- a/param/parameterized.py +++ b/param/parameterized.py @@ -1951,7 +1951,7 @@ def _setup_params(self_, **params): ref = None if ref: warnings.warn( - f"Parameter {name!r} is being given a valid parameter " + f"Parameter {name!r} on {pobj.owner} is being given a valid parameter " f"reference {val} but is implicitly allow_refs=False. " "In future allow_refs will be enabled by default and " f"the reference {val} will be resolved to its underlying " @@ -3288,7 +3288,14 @@ def __init__(mcs, name, bases, dict_): """ type.__init__(mcs, name, bases, dict_) - _param__private = _ClassPrivate() + # Compute which parameters explicitly do not support references + # This can be removed when Parameter.allow_refs=True by default. + explicit_no_refs = set() + for base in bases: + if issubclass(base, Parameterized): + explicit_no_refs |= set(base._param__private.explicit_no_refs) + + _param__private = _ClassPrivate(explicit_no_refs=list(explicit_no_refs)) mcs._param__private = _param__private mcs.__set_name(name, dict_) mcs._param__parameters = Parameters(mcs) @@ -3374,8 +3381,7 @@ def __class_docstring(mcs): description = param_pager(mcs) mcs.__doc__ = class_docstr + '\n' + description - - def _initialize_parameter(mcs,param_name,param): + def _initialize_parameter(mcs, param_name, param): # A Parameter has no way to find out the name a # Parameterized class has for it param._set_names(param_name) @@ -3951,6 +3957,7 @@ def __init__( self, parameters_state=None, disable_instance_params=False, + explicit_no_refs=None, renamed=False, params=None, ): @@ -3967,7 +3974,7 @@ def __init__( self.params = {} if params is None else params self.initialized = False self.signature = None - self.explicit_no_refs = [] + self.explicit_no_refs = [] if explicit_no_refs is None else explicit_no_refs def __getstate__(self): return {slot: getattr(self, slot) for slot in self.__slots__} diff --git a/param/reactive.py b/param/reactive.py index 15c03f647..429c679ef 100644 --- a/param/reactive.py +++ b/param/reactive.py @@ -95,7 +95,7 @@ ) from .parameterized import ( Parameter, Parameterized, eval_function_with_deps, get_method_owner, - register_depends_transform, resolve_ref, resolve_value, transform_dependency + register_reference_transform, resolve_ref, resolve_value, transform_reference ) from ._utils import iscoroutinefunction, full_groupby @@ -314,13 +314,13 @@ def bind(function, *args, watch=False, **kwargs): annotated with all dependencies. """ args, kwargs = ( - tuple(transform_dependency(arg) for arg in args), - {key: transform_dependency(arg) for key, arg in kwargs.items()} + tuple(transform_reference(arg) for arg in args), + {key: transform_reference(arg) for key, arg in kwargs.items()} ) dependencies = {} # If the wrapped function has a dependency add it - fn_dep = transform_dependency(function) + fn_dep = transform_reference(function) if isinstance(fn_dep, Parameter) or hasattr(fn_dep, '_dinfo'): dependencies['__fn'] = fn_dep @@ -375,7 +375,7 @@ def eval_fn(): if callable(function): fn = function else: - p = transform_dependency(function) + p = transform_reference(function) if isinstance(p, Parameter): fn = getattr(p.owner, p.name) else: @@ -494,7 +494,7 @@ def register_method_handler(cls, method, handler): def __new__(cls, obj, **kwargs): wrapper = None - obj = transform_dependency(obj) + obj = transform_reference(obj) if kwargs.get('fn'): fn = kwargs.pop('fn') wrapper = kwargs.pop('_wrapper', None) @@ -978,4 +978,4 @@ def _reactive_transform(obj): return obj return bind(lambda *_: obj.rx.resolve(), *obj._params) -register_depends_transform(_reactive_transform) +register_reference_transform(_reactive_transform)