param 2.5.0b4__tar.gz → 2.5.0b5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {param-2.5.0b4 → param-2.5.0b5}/PKG-INFO +5 -1
- {param-2.5.0b4 → param-2.5.0b5}/param/__init__.py +5 -0
- {param-2.5.0b4 → param-2.5.0b5}/param/_utils.py +12 -0
- {param-2.5.0b4 → param-2.5.0b5}/param/_version.py +2 -2
- {param-2.5.0b4 → param-2.5.0b5}/param/parameterized.py +225 -98
- {param-2.5.0b4 → param-2.5.0b5}/param/parameters.py +314 -23
- {param-2.5.0b4 → param-2.5.0b5}/param/reactive.py +9 -1
- param-2.5.0b5/param/typed.py +337 -0
- {param-2.5.0b4 → param-2.5.0b5}/pyproject.toml +2 -0
- param-2.5.0b5/tests/testdataframelike.py +432 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testdefaults.py +4 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testimports.py +1 -1
- param-2.5.0b5/tests/testmodel.py +557 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testparameterizedobject.py +27 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testreactive.py +110 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testrefs.py +95 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testwatch.py +90 -0
- {param-2.5.0b4 → param-2.5.0b5}/.gitignore +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/LICENSE.txt +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/README.md +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/numbergen/__init__.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/param/depends.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/param/display.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/param/ipython.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/param/mypy_plugin.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/param/py.typed +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/param/serializer.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/param/version.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/__init__.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/assert_types.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/conftest.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/pyrightconfig-bare.json +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testaddparameter.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testbind.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testbooleanparam.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testbytesparam.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testcalendardateparam.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testcalendardaterangeparam.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testcallable.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testclassselector.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testcolorparameter.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testcomparator.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testcompositeparams.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testcustomparam.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testdateparam.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testdaterangeparam.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testdefaultfactory.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testdeprecations.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testdynamicparams.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testfiledeserialization.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testfileselector.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testipythonmagic.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testjsonserialization.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testlist.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testlistselector.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testmultifileselector.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testnumbergen.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testnumberparameter.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testnumpy.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testobjectselector.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testpandas.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testparamdepends.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testparameter.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testparameterizedrepr.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testparamoutput.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testparamunion.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testpathparam.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testpickle.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testrangeparameter.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testreprhtml.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testselector.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testsignatures.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/teststringparam.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testtimedependent.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testtupleparam.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testutils.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/testversion.py +0 -0
- {param-2.5.0b4 → param-2.5.0b5}/tests/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: param
|
|
3
|
-
Version: 2.5.
|
|
3
|
+
Version: 2.5.0b5
|
|
4
4
|
Summary: Declarative parameters for robust Python classes and a rich API for reactive programming
|
|
5
5
|
Project-URL: Homepage, https://param.holoviz.org/
|
|
6
6
|
Project-URL: Tracker, https://github.com/holoviz/param/issues
|
|
@@ -33,6 +33,7 @@ Requires-Dist: cloudpickle; extra == 'all'
|
|
|
33
33
|
Requires-Dist: gmpy2; extra == 'all'
|
|
34
34
|
Requires-Dist: ipython; extra == 'all'
|
|
35
35
|
Requires-Dist: jsonschema; extra == 'all'
|
|
36
|
+
Requires-Dist: narwhals; extra == 'all'
|
|
36
37
|
Requires-Dist: nbval; extra == 'all'
|
|
37
38
|
Requires-Dist: nest-asyncio; extra == 'all'
|
|
38
39
|
Requires-Dist: numpy; extra == 'all'
|
|
@@ -40,6 +41,7 @@ Requires-Dist: odfpy; extra == 'all'
|
|
|
40
41
|
Requires-Dist: openpyxl; extra == 'all'
|
|
41
42
|
Requires-Dist: pandas; extra == 'all'
|
|
42
43
|
Requires-Dist: panel; extra == 'all'
|
|
44
|
+
Requires-Dist: polars; extra == 'all'
|
|
43
45
|
Requires-Dist: pyarrow; extra == 'all'
|
|
44
46
|
Requires-Dist: pytest; extra == 'all'
|
|
45
47
|
Requires-Dist: pytest-asyncio; extra == 'all'
|
|
@@ -75,6 +77,7 @@ Requires-Dist: cloudpickle; extra == 'tests-full'
|
|
|
75
77
|
Requires-Dist: gmpy2; extra == 'tests-full'
|
|
76
78
|
Requires-Dist: ipython; extra == 'tests-full'
|
|
77
79
|
Requires-Dist: jsonschema; extra == 'tests-full'
|
|
80
|
+
Requires-Dist: narwhals; extra == 'tests-full'
|
|
78
81
|
Requires-Dist: nbval; extra == 'tests-full'
|
|
79
82
|
Requires-Dist: nest-asyncio; extra == 'tests-full'
|
|
80
83
|
Requires-Dist: numpy; extra == 'tests-full'
|
|
@@ -82,6 +85,7 @@ Requires-Dist: odfpy; extra == 'tests-full'
|
|
|
82
85
|
Requires-Dist: openpyxl; extra == 'tests-full'
|
|
83
86
|
Requires-Dist: pandas; extra == 'tests-full'
|
|
84
87
|
Requires-Dist: panel; extra == 'tests-full'
|
|
88
|
+
Requires-Dist: polars; extra == 'tests-full'
|
|
85
89
|
Requires-Dist: pyarrow; extra == 'tests-full'
|
|
86
90
|
Requires-Dist: pytest; extra == 'tests-full'
|
|
87
91
|
Requires-Dist: pytest-asyncio; extra == 'tests-full'
|
|
@@ -84,6 +84,7 @@ from .parameters import (
|
|
|
84
84
|
Dict,
|
|
85
85
|
Array,
|
|
86
86
|
DataFrame,
|
|
87
|
+
DataFrameLike,
|
|
87
88
|
Series,
|
|
88
89
|
Path,
|
|
89
90
|
Filename,
|
|
@@ -100,6 +101,7 @@ from .parameters import (
|
|
|
100
101
|
Event,
|
|
101
102
|
)
|
|
102
103
|
from .reactive import ReactiveError, bind, collect, current_node, rx
|
|
104
|
+
from .typed import Field, Model
|
|
103
105
|
from ._utils import (
|
|
104
106
|
descendents,
|
|
105
107
|
concrete_descendents,
|
|
@@ -166,6 +168,7 @@ __all__ = (
|
|
|
166
168
|
'Composite',
|
|
167
169
|
'DEBUG',
|
|
168
170
|
'DataFrame',
|
|
171
|
+
'DataFrameLike',
|
|
169
172
|
'Date',
|
|
170
173
|
'DateRange',
|
|
171
174
|
'Dict',
|
|
@@ -173,6 +176,7 @@ __all__ = (
|
|
|
173
176
|
'ERROR',
|
|
174
177
|
'ReactiveError',
|
|
175
178
|
'Event',
|
|
179
|
+
'Field',
|
|
176
180
|
'FileSelector',
|
|
177
181
|
'Filename',
|
|
178
182
|
'Foldername',
|
|
@@ -184,6 +188,7 @@ __all__ = (
|
|
|
184
188
|
'ListProxy',
|
|
185
189
|
'ListSelector',
|
|
186
190
|
'Magnitude',
|
|
191
|
+
'Model',
|
|
187
192
|
'MultiFileSelector',
|
|
188
193
|
'Number',
|
|
189
194
|
'NumericTuple',
|
|
@@ -752,3 +752,15 @@ def _find_stack_level() -> int:
|
|
|
752
752
|
# https://docs.python.org/3/library/inspect.html#inspect.Traceback
|
|
753
753
|
del frame
|
|
754
754
|
return n
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
def _get_narwhals():
|
|
758
|
+
"""Import and return the optional ``narwhals`` stable API."""
|
|
759
|
+
try:
|
|
760
|
+
import narwhals.stable.v2 as narwhals
|
|
761
|
+
except ModuleNotFoundError as e:
|
|
762
|
+
raise ImportError(
|
|
763
|
+
"param.DataFrameLike requires the optional 'narwhals' package. "
|
|
764
|
+
"Install it with: pip install narwhals"
|
|
765
|
+
) from e
|
|
766
|
+
return narwhals
|
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '2.5.
|
|
22
|
-
__version_tuple__ = version_tuple = (2, 5, 0, '
|
|
21
|
+
__version__ = version = '2.5.0b5'
|
|
22
|
+
__version_tuple__ = version_tuple = (2, 5, 0, 'b5')
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -28,7 +28,7 @@ from contextlib import contextmanager, ExitStack
|
|
|
28
28
|
from inspect import getfullargspec
|
|
29
29
|
|
|
30
30
|
from collections import defaultdict, namedtuple, OrderedDict
|
|
31
|
-
from functools import partial, wraps, reduce
|
|
31
|
+
from functools import cached_property, partial, wraps, reduce
|
|
32
32
|
from itertools import chain
|
|
33
33
|
from operator import itemgetter, attrgetter
|
|
34
34
|
from types import FunctionType, MethodType
|
|
@@ -344,8 +344,20 @@ def resolve_value(value: t.Any, recursive: bool = True) -> t.Any:
|
|
|
344
344
|
value = getattr(value.owner, value.name)
|
|
345
345
|
return value
|
|
346
346
|
|
|
347
|
+
# PyPy aliases some of these to the Python function and method types.
|
|
348
|
+
_BUILTIN_CALLABLE_TYPES = frozenset({
|
|
349
|
+
types.BuiltinFunctionType, types.MethodWrapperType,
|
|
350
|
+
types.WrapperDescriptorType, types.MethodDescriptorType,
|
|
351
|
+
}) - {types.FunctionType, types.MethodType}
|
|
352
|
+
|
|
347
353
|
def _is_async_fn(value: t.Any) -> bool:
|
|
348
354
|
"""Whether value is a coroutine or generator function."""
|
|
355
|
+
# The inspect checks are comparatively slow and every function, method
|
|
356
|
+
# or partial they could match is callable. Builtins (e.g. the operator
|
|
357
|
+
# functions rx applies) have neither code flags nor a __dict__ to carry
|
|
358
|
+
# a coroutine marker.
|
|
359
|
+
if not callable(value) or type(value) in _BUILTIN_CALLABLE_TYPES:
|
|
360
|
+
return False
|
|
349
361
|
return iscoroutinefunction(value) or inspect.isgeneratorfunction(value)
|
|
350
362
|
|
|
351
363
|
def _is_bare_async_ref(value: t.Any) -> bool:
|
|
@@ -666,7 +678,14 @@ def _flush_batch(objects):
|
|
|
666
678
|
except Exception as e:
|
|
667
679
|
errors.append(e)
|
|
668
680
|
if errors:
|
|
669
|
-
|
|
681
|
+
# Clear the list on the way out: the raised exception's traceback
|
|
682
|
+
# holds this frame, so a list still referencing it would form a
|
|
683
|
+
# cycle keeping the frame and the event values alive until the
|
|
684
|
+
# cyclic garbage collector runs.
|
|
685
|
+
try:
|
|
686
|
+
raise errors[0]
|
|
687
|
+
finally:
|
|
688
|
+
errors.clear()
|
|
670
689
|
|
|
671
690
|
|
|
672
691
|
@contextmanager
|
|
@@ -741,16 +760,21 @@ def batch() -> Generator[None, None, None]:
|
|
|
741
760
|
flush_error = exc
|
|
742
761
|
current.closed = True
|
|
743
762
|
_param_batch.reset(token)
|
|
744
|
-
|
|
745
|
-
if
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
763
|
+
try:
|
|
764
|
+
if outermost and flush_error is not None:
|
|
765
|
+
if error is None:
|
|
766
|
+
raise flush_error
|
|
767
|
+
# The block already raised; a second error here would only
|
|
768
|
+
# replace it, so report it instead of raising over the top.
|
|
769
|
+
warnings.warn(
|
|
770
|
+
f"batch() failed to notify some watchers while unwinding "
|
|
771
|
+
f"from {error!r}: {flush_error!r}",
|
|
772
|
+
RuntimeWarning, stacklevel=2,
|
|
773
|
+
)
|
|
774
|
+
finally:
|
|
775
|
+
# The propagating exception's traceback holds this frame;
|
|
776
|
+
# drop the references to it (see _flush_batch).
|
|
777
|
+
error = flush_error = None
|
|
754
778
|
|
|
755
779
|
|
|
756
780
|
@contextmanager
|
|
@@ -1412,6 +1436,8 @@ _add_doc(Event,
|
|
|
1412
1436
|
|
|
1413
1437
|
_Watcher = namedtuple("_Watcher", "inst cls fn mode onlychanged parameter_names what queued precedence")
|
|
1414
1438
|
|
|
1439
|
+
_watcher_precedence = attrgetter('precedence')
|
|
1440
|
+
|
|
1415
1441
|
class Watcher(_Watcher):
|
|
1416
1442
|
"""
|
|
1417
1443
|
Object declaring a callback function to invoke when an Event is
|
|
@@ -1498,6 +1524,10 @@ class Watcher(_Watcher):
|
|
|
1498
1524
|
"""
|
|
1499
1525
|
(self.cls if self.inst is None else self.inst).param.unwatch(self)
|
|
1500
1526
|
|
|
1527
|
+
@cached_property
|
|
1528
|
+
def _is_coroutine(self) -> bool:
|
|
1529
|
+
return iscoroutinefunction(self.fn)
|
|
1530
|
+
|
|
1501
1531
|
|
|
1502
1532
|
class ParameterMetaclass(type):
|
|
1503
1533
|
"""Metaclass allowing control over creation of Parameter classes."""
|
|
@@ -2217,8 +2247,7 @@ class Parameter(_ParameterBase, t.Generic[_T]):
|
|
|
2217
2247
|
"An event cannot be triggered for an unbound parameter."
|
|
2218
2248
|
)
|
|
2219
2249
|
event = Event(what=attribute, name=self.name, obj=None, cls=self.owner, old=old, new=new, type=None)
|
|
2220
|
-
|
|
2221
|
-
self.owner.param._call_watcher(watcher, event)
|
|
2250
|
+
self.owner.param._dispatch_event(self.watchers[attribute], event)
|
|
2222
2251
|
if not _is_batched(self.owner):
|
|
2223
2252
|
self.owner.param._batch_call_watchers()
|
|
2224
2253
|
|
|
@@ -2280,19 +2309,20 @@ class Parameter(_ParameterBase, t.Generic[_T]):
|
|
|
2280
2309
|
instance's value, if one has been set - otherwise produce the
|
|
2281
2310
|
class's value (default).
|
|
2282
2311
|
"""
|
|
2283
|
-
|
|
2312
|
+
# Slot reads go through Parameter.__getattribute__, so `name` is
|
|
2313
|
+
# bound to a local rather than read twice.
|
|
2314
|
+
name = self.name
|
|
2315
|
+
if name is None:
|
|
2284
2316
|
raise ValueError("Parameter name is not set")
|
|
2285
2317
|
|
|
2286
2318
|
if obj is None: # e.g. when __get__ called for a Parameterized class
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
result = self.default
|
|
2295
|
-
return result
|
|
2319
|
+
return self.default
|
|
2320
|
+
# Attribute error when .values does not exist (_ClassPrivate)
|
|
2321
|
+
# and KeyError when there's no cached value for this parameter.
|
|
2322
|
+
try:
|
|
2323
|
+
return obj._param__private.values[name]
|
|
2324
|
+
except (AttributeError, KeyError):
|
|
2325
|
+
return self.default
|
|
2296
2326
|
|
|
2297
2327
|
@instance_descriptor
|
|
2298
2328
|
def __set__(self, obj: Parameterized | None, val: _T):
|
|
@@ -2321,11 +2351,13 @@ class Parameter(_ParameterBase, t.Generic[_T]):
|
|
|
2321
2351
|
object stored in a constant or read-only Parameter (e.g. one
|
|
2322
2352
|
item in a list).
|
|
2323
2353
|
"""
|
|
2324
|
-
|
|
2354
|
+
# Slot reads go through Parameter.__getattribute__, so `name` is bound
|
|
2355
|
+
# to a local and reused below rather than re-read from the slot.
|
|
2356
|
+
name = self.name
|
|
2357
|
+
if name is None:
|
|
2325
2358
|
raise RuntimeError(
|
|
2326
2359
|
"A parameter value cannot be set for an unbound parameter."
|
|
2327
2360
|
)
|
|
2328
|
-
name = self.name
|
|
2329
2361
|
ref_changed = settle_changed = False
|
|
2330
2362
|
|
|
2331
2363
|
if obj is not None and self.allow_refs and obj._param__private.initialized:
|
|
@@ -2337,9 +2369,7 @@ class Parameter(_ParameterBase, t.Generic[_T]):
|
|
|
2337
2369
|
ref_changed = True
|
|
2338
2370
|
settle_changed = True
|
|
2339
2371
|
elif name in refs and not syncing and not obj._param__private.parameters_state['TRIGGER']:
|
|
2340
|
-
|
|
2341
|
-
if name in obj._param__private.async_refs:
|
|
2342
|
-
obj._param__private.async_refs.pop(name).cancel()
|
|
2372
|
+
obj.param._remove_ref(name)
|
|
2343
2373
|
ref_changed = True
|
|
2344
2374
|
settle_changed = True
|
|
2345
2375
|
settle_changed |= scheduled
|
|
@@ -2352,17 +2382,18 @@ class Parameter(_ParameterBase, t.Generic[_T]):
|
|
|
2352
2382
|
|
|
2353
2383
|
_old = NotImplemented
|
|
2354
2384
|
# obj can be None if __set__ is called for a Parameterized class
|
|
2355
|
-
|
|
2356
|
-
|
|
2385
|
+
readonly = self.readonly
|
|
2386
|
+
if self.constant or readonly:
|
|
2387
|
+
if readonly:
|
|
2357
2388
|
raise TypeError("Read-only parameter '%s' cannot be modified" % name)
|
|
2358
2389
|
elif obj is None:
|
|
2359
2390
|
_old = self.default
|
|
2360
2391
|
self.default = val
|
|
2361
2392
|
elif not obj._param__private.initialized:
|
|
2362
|
-
_old = obj._param__private.values.get(
|
|
2363
|
-
obj._param__private.values[
|
|
2393
|
+
_old = obj._param__private.values.get(name, self.default)
|
|
2394
|
+
obj._param__private.values[name] = val
|
|
2364
2395
|
else:
|
|
2365
|
-
_old = obj._param__private.values.get(
|
|
2396
|
+
_old = obj._param__private.values.get(name, self.default)
|
|
2366
2397
|
if val is not _old:
|
|
2367
2398
|
raise TypeError("Constant parameter '%s' cannot be modified" % name)
|
|
2368
2399
|
else:
|
|
@@ -2370,10 +2401,11 @@ class Parameter(_ParameterBase, t.Generic[_T]):
|
|
|
2370
2401
|
_old = self.default
|
|
2371
2402
|
self.default = val
|
|
2372
2403
|
else:
|
|
2404
|
+
private = obj._param__private
|
|
2373
2405
|
# When setting a Parameter before calling super.
|
|
2374
|
-
if not isinstance(
|
|
2406
|
+
if not isinstance(private, _InstancePrivate):
|
|
2375
2407
|
warnings.warn(
|
|
2376
|
-
f"Setting the Parameter {
|
|
2408
|
+
f"Setting the Parameter {name!r} to {val!r} before "
|
|
2377
2409
|
f"the Parameterized class {type(obj).__name__!r} is fully "
|
|
2378
2410
|
"instantiated is deprecated and will raise an error in "
|
|
2379
2411
|
"a future version. Ensure the value is set after calling "
|
|
@@ -2381,42 +2413,55 @@ class Parameter(_ParameterBase, t.Generic[_T]):
|
|
|
2381
2413
|
category=_ParamPendingDeprecationWarning,
|
|
2382
2414
|
stacklevel=_find_stack_level(),
|
|
2383
2415
|
)
|
|
2384
|
-
|
|
2416
|
+
private = _InstancePrivate(
|
|
2385
2417
|
explicit_no_refs=type(obj)._param__private.explicit_no_refs
|
|
2386
2418
|
)
|
|
2387
|
-
|
|
2388
|
-
|
|
2419
|
+
obj.__dict__['_param__private'] = private # pyright: ignore[reportIndexIssue]
|
|
2420
|
+
values = private.values
|
|
2421
|
+
# Only fall back to reading the `default` slot when there is no
|
|
2422
|
+
# value stored yet, since that read is not free.
|
|
2423
|
+
try:
|
|
2424
|
+
_old = values[name]
|
|
2425
|
+
except KeyError:
|
|
2426
|
+
_old = self.default
|
|
2427
|
+
values[name] = val
|
|
2389
2428
|
self._post_setter(obj, val)
|
|
2390
2429
|
|
|
2391
2430
|
if obj is None:
|
|
2392
2431
|
self._invalidate_init_cache()
|
|
2393
|
-
|
|
2394
|
-
if obj is not None:
|
|
2395
|
-
if not hasattr(obj, '_param__private') or not getattr(obj._param__private, 'initialized', False):
|
|
2396
|
-
return
|
|
2397
|
-
obj.param._update_deps(name)
|
|
2398
|
-
|
|
2399
|
-
if obj is None:
|
|
2400
2432
|
watchers = self.watchers.get("value")
|
|
2401
|
-
|
|
2402
|
-
watchers = obj._param__private.watchers[name].get('value')
|
|
2403
|
-
if watchers is None:
|
|
2404
|
-
watchers = self.watchers.get("value")
|
|
2433
|
+
obj_param = None
|
|
2405
2434
|
else:
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2435
|
+
instance_private = getattr(obj, '_param__private', None)
|
|
2436
|
+
if instance_private is None or not getattr(instance_private, 'initialized', False):
|
|
2437
|
+
return
|
|
2438
|
+
obj_param = obj.param
|
|
2439
|
+
obj_param._update_deps(name)
|
|
2440
|
+
|
|
2441
|
+
instance_watchers = instance_private.watchers
|
|
2442
|
+
if name in instance_watchers:
|
|
2443
|
+
watchers = instance_watchers[name].get('value')
|
|
2444
|
+
if watchers is None:
|
|
2445
|
+
watchers = self.watchers.get("value")
|
|
2446
|
+
else:
|
|
2447
|
+
watchers = None
|
|
2409
2448
|
|
|
2410
|
-
if
|
|
2449
|
+
if not watchers:
|
|
2411
2450
|
return
|
|
2451
|
+
owner = self.owner
|
|
2452
|
+
if obj is None:
|
|
2453
|
+
if owner is None:
|
|
2454
|
+
return
|
|
2455
|
+
obj = owner
|
|
2412
2456
|
|
|
2413
|
-
event = Event(
|
|
2457
|
+
event = Event('value', name, obj, owner, _old, val, None)
|
|
2414
2458
|
|
|
2415
2459
|
# Copy watchers here since they may be modified inplace during iteration
|
|
2416
|
-
|
|
2417
|
-
obj.param
|
|
2460
|
+
if obj_param is None:
|
|
2461
|
+
obj_param = obj.param
|
|
2462
|
+
obj_param._dispatch_event(sorted(watchers, key=_watcher_precedence), event)
|
|
2418
2463
|
if not _is_batched(obj):
|
|
2419
|
-
|
|
2464
|
+
obj_param._batch_call_watchers()
|
|
2420
2465
|
finally:
|
|
2421
2466
|
if obj is not None:
|
|
2422
2467
|
_notify_ref_changes(obj, name, ref_changed, settle_changed)
|
|
@@ -2681,6 +2726,11 @@ def as_uninitialized(fn):
|
|
|
2681
2726
|
return override_initialization
|
|
2682
2727
|
|
|
2683
2728
|
|
|
2729
|
+
_BUILTIN_VALUE_TYPES = frozenset({
|
|
2730
|
+
int, float, complex, bool, str, bytes, type(None), list, tuple, set, dict,
|
|
2731
|
+
})
|
|
2732
|
+
|
|
2733
|
+
|
|
2684
2734
|
class Comparator:
|
|
2685
2735
|
"""
|
|
2686
2736
|
Comparator defines methods for determining whether two objects
|
|
@@ -2712,10 +2762,19 @@ class Comparator:
|
|
|
2712
2762
|
|
|
2713
2763
|
@classmethod
|
|
2714
2764
|
def is_equal(cls, obj1, obj2):
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2765
|
+
gen_equalities = cls.gen_equalities
|
|
2766
|
+
if (
|
|
2767
|
+
type(obj1) in _BUILTIN_VALUE_TYPES and type(obj2) in _BUILTIN_VALUE_TYPES
|
|
2768
|
+
and len(gen_equalities) == 1 and _dt_types in gen_equalities
|
|
2769
|
+
):
|
|
2770
|
+
# The default generated equalities only cover date and time
|
|
2771
|
+
# types, which can match neither object, so skip expanding them.
|
|
2772
|
+
equals = cls.equalities
|
|
2773
|
+
else:
|
|
2774
|
+
equals = cls.equalities.copy()
|
|
2775
|
+
for gen, op in gen_equalities.items():
|
|
2776
|
+
for v in gen():
|
|
2777
|
+
equals[v] = op
|
|
2719
2778
|
|
|
2720
2779
|
for eq_type, eq in equals.items():
|
|
2721
2780
|
if isinstance(eq_type, type) or (isinstance(eq_type, tuple) and all(isinstance(t, type) for t in eq_type)):
|
|
@@ -3004,15 +3063,16 @@ class Parameters:
|
|
|
3004
3063
|
## keyword arg setting
|
|
3005
3064
|
deps, refs, scheduled = {}, {}, set()
|
|
3006
3065
|
for name, val in params.items():
|
|
3007
|
-
desc = self_.cls.get_param_descriptor(name)[0]
|
|
3008
|
-
if not desc:
|
|
3009
|
-
raise TypeError(
|
|
3010
|
-
f"{self.__class__.__name__}.__init__() got an unexpected "
|
|
3011
|
-
f"keyword argument {name!r}"
|
|
3012
|
-
)
|
|
3013
|
-
|
|
3014
3066
|
pobj = objects.get(name)
|
|
3015
3067
|
if pobj is None:
|
|
3068
|
+
# Only walk the class hierarchy when the cached class
|
|
3069
|
+
# parameters do not already contain the name.
|
|
3070
|
+
desc = self_.cls.get_param_descriptor(name)[0]
|
|
3071
|
+
if not desc:
|
|
3072
|
+
raise TypeError(
|
|
3073
|
+
f"{self.__class__.__name__}.__init__() got an unexpected "
|
|
3074
|
+
f"keyword argument {name!r}"
|
|
3075
|
+
)
|
|
3016
3076
|
setattr(self, name, val)
|
|
3017
3077
|
continue
|
|
3018
3078
|
elif not pobj.allow_refs:
|
|
@@ -3075,16 +3135,27 @@ class Parameters:
|
|
|
3075
3135
|
def _update_ref(self_, name: str, ref: t.Any):
|
|
3076
3136
|
if self_.self is None:
|
|
3077
3137
|
return
|
|
3078
|
-
|
|
3138
|
+
refs = dict(self_.self._param__private.refs, **{name: ref})
|
|
3139
|
+
self_._rewatch_refs(name, refs)
|
|
3140
|
+
|
|
3141
|
+
def _remove_ref(self_, name: str):
|
|
3142
|
+
if self_.self is None:
|
|
3143
|
+
return
|
|
3144
|
+
refs = dict(self_.self._param__private.refs)
|
|
3145
|
+
refs.pop(name, None)
|
|
3146
|
+
self_._rewatch_refs(name, refs)
|
|
3147
|
+
|
|
3148
|
+
def _rewatch_refs(self_, name: str, refs: dict[str, t.Any]):
|
|
3149
|
+
# must be called from `_update_ref` or `_remove_ref`
|
|
3150
|
+
param_private = t.cast("Parameterized", self_.self)._param__private
|
|
3079
3151
|
if name in param_private.async_refs:
|
|
3080
3152
|
param_private.async_refs.pop(name).cancel()
|
|
3081
3153
|
for _, watcher in param_private.ref_watchers:
|
|
3082
3154
|
watcher.remove()
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
deps = {name: resolve_ref(ref, self_[name].nested_refs) for name, ref in refs.items()}
|
|
3155
|
+
param_private.ref_watchers = []
|
|
3156
|
+
deps = {pname: resolve_ref(ref, self_[pname].nested_refs) for pname, ref in refs.items()}
|
|
3086
3157
|
self_._setup_refs(deps)
|
|
3087
|
-
|
|
3158
|
+
param_private.refs = refs
|
|
3088
3159
|
|
|
3089
3160
|
def _sync_refs(self_, *events):
|
|
3090
3161
|
if self_.self is None:
|
|
@@ -3096,7 +3167,7 @@ class Parameters:
|
|
|
3096
3167
|
recursive = self_[pname].nested_refs
|
|
3097
3168
|
deps = resolve_ref(ref, recursive)
|
|
3098
3169
|
is_async = _is_async_fn(ref)
|
|
3099
|
-
if not any((dep.owner is e.obj and dep.name == e.name) for dep in deps for e in events)
|
|
3170
|
+
if not any((dep.owner is e.obj and dep.name == e.name) for dep in deps for e in events):
|
|
3100
3171
|
continue
|
|
3101
3172
|
|
|
3102
3173
|
try:
|
|
@@ -3277,6 +3348,8 @@ class Parameters:
|
|
|
3277
3348
|
class_param = self_.cls.param
|
|
3278
3349
|
init_methods = []
|
|
3279
3350
|
for method, queued, on_init, constant, dynamic in class_param._depends['watch']:
|
|
3351
|
+
if not (init or dynamic):
|
|
3352
|
+
continue
|
|
3280
3353
|
# On initialization set up constant watchers; otherwise
|
|
3281
3354
|
# clean up previous dynamic watchers for the updated attribute
|
|
3282
3355
|
dynamic = [d for d in dynamic if attribute is None or d.spec.split(".")[0] == attribute]
|
|
@@ -3560,8 +3633,13 @@ class Parameters:
|
|
|
3560
3633
|
for tp in trigger_params:
|
|
3561
3634
|
self_[tp]._mode = 'set'
|
|
3562
3635
|
|
|
3563
|
-
values
|
|
3564
|
-
|
|
3636
|
+
# Only the values being replaced are needed, so avoid computing
|
|
3637
|
+
# values() for every parameter.
|
|
3638
|
+
param_objs = self_.objects('existing')
|
|
3639
|
+
restore = {
|
|
3640
|
+
k: self_.get_value_generator(k, param_objs)
|
|
3641
|
+
for k in base if k in param_objs
|
|
3642
|
+
}
|
|
3565
3643
|
|
|
3566
3644
|
for (k, v) in base.items():
|
|
3567
3645
|
if k not in self_:
|
|
@@ -3769,7 +3847,7 @@ class Parameters:
|
|
|
3769
3847
|
event_type = 'triggered'
|
|
3770
3848
|
else:
|
|
3771
3849
|
event_type = 'changed' if watcher.onlychanged else 'set'
|
|
3772
|
-
return event.
|
|
3850
|
+
return type(event)._make((*event[:6], event_type))
|
|
3773
3851
|
|
|
3774
3852
|
def _execute_watcher(self, watcher: Watcher, events: Iterable[Event]):
|
|
3775
3853
|
if watcher.mode == 'args':
|
|
@@ -3777,7 +3855,7 @@ class Parameters:
|
|
|
3777
3855
|
else:
|
|
3778
3856
|
args, kwargs = (), {event.name: event.new for event in events}
|
|
3779
3857
|
|
|
3780
|
-
if iscoroutinefunction(watcher.fn):
|
|
3858
|
+
if watcher._is_coroutine if isinstance(watcher, Watcher) else iscoroutinefunction(watcher.fn):
|
|
3781
3859
|
if async_executor is None:
|
|
3782
3860
|
raise RuntimeError("Could not execute %s coroutine function. "
|
|
3783
3861
|
"Please register a asynchronous executor on "
|
|
@@ -3791,22 +3869,47 @@ class Parameters:
|
|
|
3791
3869
|
except Skip:
|
|
3792
3870
|
pass
|
|
3793
3871
|
|
|
3872
|
+
def _dispatch_event(self_, watchers: Iterable[Watcher], event: Event):
|
|
3873
|
+
"""
|
|
3874
|
+
Call each of ``watchers``, in order, for a single ``event``.
|
|
3875
|
+
|
|
3876
|
+
Whether the value changed is computed at most once per event, the
|
|
3877
|
+
first time an ``onlychanged`` watcher needs it, and reused for the
|
|
3878
|
+
remaining watchers, so a deep comparison of a large value is not
|
|
3879
|
+
repeated per watcher. If an earlier watcher mutates ``event.old``
|
|
3880
|
+
or ``event.new`` in place, later watchers reuse that result rather
|
|
3881
|
+
than comparing again. Unchanged events skip ``onlychanged``
|
|
3882
|
+
watchers unless the event is being triggered.
|
|
3883
|
+
"""
|
|
3884
|
+
changed = None
|
|
3885
|
+
for watcher in watchers:
|
|
3886
|
+
if watcher.onlychanged and not self_._TRIGGER:
|
|
3887
|
+
if changed is None:
|
|
3888
|
+
changed = self_._changed(event)
|
|
3889
|
+
if not changed:
|
|
3890
|
+
continue
|
|
3891
|
+
self_._call_watcher(watcher, event)
|
|
3892
|
+
|
|
3794
3893
|
def _call_watcher(self_, watcher: Watcher, event: Event):
|
|
3795
3894
|
"""Invoke the given watcher appropriately given an Event object."""
|
|
3796
|
-
if self_._TRIGGER:
|
|
3797
|
-
pass
|
|
3798
|
-
elif watcher.onlychanged and (not self_._changed(event)):
|
|
3799
|
-
return
|
|
3800
|
-
|
|
3801
3895
|
fn = watcher.fn
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3896
|
+
self_or_cls = self_.self_or_cls
|
|
3897
|
+
state = self_or_cls._param__private.parameters_state
|
|
3898
|
+
if not (isinstance(fn, _WeakInvalidator) and fn._unbatched) and _is_batched(self_or_cls):
|
|
3899
|
+
state['events'].append(event)
|
|
3900
|
+
state_watchers = state['watchers']
|
|
3901
|
+
if not any(watcher is w for w in state_watchers):
|
|
3902
|
+
state_watchers.append(watcher)
|
|
3806
3903
|
else:
|
|
3807
|
-
event = self_._update_event_type(watcher, event,
|
|
3808
|
-
|
|
3904
|
+
event = self_._update_event_type(watcher, event, state['TRIGGER'])
|
|
3905
|
+
# Inlined _batch_call_watchers(..., run=False), which only
|
|
3906
|
+
# saves and restores the flag.
|
|
3907
|
+
batch_watch = state['BATCH_WATCH']
|
|
3908
|
+
state['BATCH_WATCH'] = watcher.queued or batch_watch
|
|
3909
|
+
try:
|
|
3809
3910
|
self_._execute_watcher(watcher, (event,))
|
|
3911
|
+
finally:
|
|
3912
|
+
self_or_cls._param__private.parameters_state['BATCH_WATCH'] = batch_watch
|
|
3810
3913
|
|
|
3811
3914
|
def _batch_call_watchers(self_):
|
|
3812
3915
|
"""
|
|
@@ -3820,13 +3923,19 @@ class Parameters:
|
|
|
3820
3923
|
self_._events = []
|
|
3821
3924
|
self_._state_watchers = []
|
|
3822
3925
|
|
|
3823
|
-
|
|
3926
|
+
self_or_cls = self_.self_or_cls
|
|
3927
|
+
for watcher in sorted(watchers, key=_watcher_precedence):
|
|
3928
|
+
state = self_or_cls._param__private.parameters_state
|
|
3824
3929
|
events = [self_._update_event_type(watcher, event_dict[(name, watcher.what)],
|
|
3825
|
-
|
|
3930
|
+
state['TRIGGER'])
|
|
3826
3931
|
for name in watcher.parameter_names
|
|
3827
3932
|
if (name, watcher.what) in event_dict]
|
|
3828
|
-
|
|
3933
|
+
batch_watch = state['BATCH_WATCH']
|
|
3934
|
+
state['BATCH_WATCH'] = watcher.queued or batch_watch
|
|
3935
|
+
try:
|
|
3829
3936
|
self_._execute_watcher(watcher, events)
|
|
3937
|
+
finally:
|
|
3938
|
+
self_or_cls._param__private.parameters_state['BATCH_WATCH'] = batch_watch
|
|
3830
3939
|
|
|
3831
3940
|
def set_dynamic_time_fn(self_, time_fn: Callable, sublistattr: str | None = None) -> None:
|
|
3832
3941
|
"""
|
|
@@ -5410,9 +5519,20 @@ class ParameterizedMetaclass(type):
|
|
|
5410
5519
|
|
|
5411
5520
|
if parameter and not isinstance(value,Parameter):
|
|
5412
5521
|
if owning_class != mcs:
|
|
5522
|
+
inherited = parameter
|
|
5413
5523
|
parameter = copy.copy(parameter)
|
|
5414
5524
|
parameter.owner = t.cast("t.Any", mcs)
|
|
5415
5525
|
type.__setattr__(mcs, attribute_name, parameter)
|
|
5526
|
+
# The cached class parameters of mcs and its subclasses may
|
|
5527
|
+
# still point to the inherited Parameter that was just copied,
|
|
5528
|
+
# so swap in the copy and let the derived lists be rebuilt.
|
|
5529
|
+
for cls in descendents(t.cast("type[t.Any]", mcs)):
|
|
5530
|
+
private = cls._param__private
|
|
5531
|
+
if private.params.get(attribute_name) is inherited:
|
|
5532
|
+
private.params[attribute_name] = parameter
|
|
5533
|
+
private.params_to_deepcopy = None
|
|
5534
|
+
private.params_to_ref = None
|
|
5535
|
+
private.params_with_default_factory = None
|
|
5416
5536
|
mcs.__dict__[attribute_name].__set__(None,value)
|
|
5417
5537
|
|
|
5418
5538
|
else:
|
|
@@ -5676,6 +5796,12 @@ def script_repr(
|
|
|
5676
5796
|
- The ``imports`` list may not include all modules required for parameter
|
|
5677
5797
|
values, focusing primarily on the modules needed for the Parameterized
|
|
5678
5798
|
object itself.
|
|
5799
|
+
- By default, only parameter values that differ from their defaults are
|
|
5800
|
+
included. To include every parameter value, set
|
|
5801
|
+
``param.parameterized.script_repr_suppress_defaults = False`` before
|
|
5802
|
+
calling ``script_repr``. See
|
|
5803
|
+
https://param.holoviz.org/user_guide/Serialization_and_Persistence.html#script-repr-limitations-and-workarounds
|
|
5804
|
+
for more details.
|
|
5679
5805
|
|
|
5680
5806
|
References
|
|
5681
5807
|
----------
|
|
@@ -6355,11 +6481,12 @@ class Parameterized(metaclass=ParameterizedMetaclass):
|
|
|
6355
6481
|
self.__dict__['_param__private'] = _InstancePrivate( # pyright: ignore[reportIndexIssue]
|
|
6356
6482
|
explicit_no_refs=type(self)._param__private.explicit_no_refs
|
|
6357
6483
|
)
|
|
6484
|
+
param_ns = self.param
|
|
6358
6485
|
# Skip generating a custom instance name when a class in the hierarchy
|
|
6359
6486
|
# has overridden the default of the `name` Parameter.
|
|
6360
|
-
if
|
|
6361
|
-
|
|
6362
|
-
refs, deps, scheduled =
|
|
6487
|
+
if param_ns.name.default == self.__class__.__name__:
|
|
6488
|
+
param_ns._generate_name()
|
|
6489
|
+
refs, deps, scheduled = param_ns._setup_params(**params)
|
|
6363
6490
|
object_count += 1
|
|
6364
6491
|
|
|
6365
6492
|
self._param__private.initialized = True
|
|
@@ -6385,8 +6512,8 @@ class Parameterized(metaclass=ParameterizedMetaclass):
|
|
|
6385
6512
|
with discard_events(self):
|
|
6386
6513
|
setattr(self, pname, default_val)
|
|
6387
6514
|
|
|
6388
|
-
|
|
6389
|
-
|
|
6515
|
+
param_ns._setup_refs(deps)
|
|
6516
|
+
param_ns._update_deps(init=True)
|
|
6390
6517
|
self._param__private.refs = refs
|
|
6391
6518
|
for pname in scheduled:
|
|
6392
6519
|
_notify_async_ref_settle_change(self, pname)
|