Skip to content

Commit

Permalink
Final renames and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Sep 24, 2023
1 parent f6bd51c commit 9d49cd4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
6 changes: 3 additions & 3 deletions param/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
17 changes: 12 additions & 5 deletions param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -3951,6 +3957,7 @@ def __init__(
self,
parameters_state=None,
disable_instance_params=False,
explicit_no_refs=None,
renamed=False,
params=None,
):
Expand All @@ -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__}
Expand Down
14 changes: 7 additions & 7 deletions param/reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

0 comments on commit 9d49cd4

Please sign in to comment.