param 2.4.1rc0__tar.gz → 2.4.2rc0__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.4.1rc0 → param-2.4.2rc0}/PKG-INFO +2 -2
- {param-2.4.1rc0 → param-2.4.2rc0}/param/_utils.py +3 -3
- {param-2.4.1rc0 → param-2.4.2rc0}/param/_version.py +2 -2
- {param-2.4.1rc0 → param-2.4.2rc0}/param/parameterized.py +45 -10
- {param-2.4.1rc0 → param-2.4.2rc0}/param/parameters.py +3 -3
- {param-2.4.1rc0 → param-2.4.2rc0}/param/reactive.py +48 -2
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testfiledeserialization.py +1 -1
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testlist.py +8 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testparameterizedobject.py +106 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testreactive.py +27 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testutils.py +15 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/.gitignore +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/LICENSE.txt +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/README.md +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/numbergen/__init__.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/param/__init__.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/param/depends.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/param/display.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/param/ipython.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/param/mypy_plugin.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/param/py.typed +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/param/serializer.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/param/version.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/pyproject.toml +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/__init__.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/assert_types.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/conftest.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/pyrightconfig-bare.json +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testaddparameter.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testbind.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testbooleanparam.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testbytesparam.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testcalendardateparam.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testcalendardaterangeparam.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testcallable.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testclassselector.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testcolorparameter.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testcomparator.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testcompositeparams.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testcustomparam.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testdateparam.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testdaterangeparam.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testdefaultfactory.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testdefaults.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testdeprecations.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testdynamicparams.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testfileselector.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testimports.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testipythonmagic.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testjsonserialization.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testlistselector.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testmultifileselector.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testnumbergen.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testnumberparameter.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testnumpy.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testobjectselector.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testpandas.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testparamdepends.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testparameter.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testparameterizedrepr.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testparamoutput.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testparamunion.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testpathparam.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testpickle.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testrangeparameter.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testrefs.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testreprhtml.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testselector.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testsignatures.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/teststringparam.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testtimedependent.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testtupleparam.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testversion.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/testwatch.py +0 -0
- {param-2.4.1rc0 → param-2.4.2rc0}/tests/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: param
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.2rc0
|
|
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
|
|
@@ -544,10 +544,10 @@ def _abbreviate_paths(pathspec,named_paths):
|
|
|
544
544
|
Given a dict of (pathname,path) pairs, removes any prefix shared by all pathnames.
|
|
545
545
|
Helps keep menu items short yet unambiguous.
|
|
546
546
|
"""
|
|
547
|
-
from os.path import
|
|
547
|
+
from os.path import commonpath, dirname, sep
|
|
548
548
|
|
|
549
|
-
prefix =
|
|
550
|
-
return OrderedDict([(name[len(prefix):],path) for name,path in named_paths.items()])
|
|
549
|
+
prefix = commonpath([dirname(name)+sep for name in named_paths.keys()]+[pathspec])
|
|
550
|
+
return OrderedDict([(name[len(prefix)+1:],path) for name,path in named_paths.items()])
|
|
551
551
|
|
|
552
552
|
|
|
553
553
|
def _to_datetime(x):
|
|
@@ -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.4.
|
|
22
|
-
__version_tuple__ = version_tuple = (2, 4,
|
|
21
|
+
__version__ = version = '2.4.2rc0'
|
|
22
|
+
__version_tuple__ = version_tuple = (2, 4, 2, 'rc0')
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -1855,7 +1855,7 @@ class Parameter(_ParameterBase, t.Generic[_T]):
|
|
|
1855
1855
|
pass
|
|
1856
1856
|
|
|
1857
1857
|
super().__setattr__(attribute, value)
|
|
1858
|
-
if is_slot and attribute in _PARAMETER_CACHE_ATTRS:
|
|
1858
|
+
if is_slot and attribute in _PARAMETER_CACHE_ATTRS and value is not old:
|
|
1859
1859
|
self._invalidate_init_cache()
|
|
1860
1860
|
if has_watcher and old is not NotImplemented:
|
|
1861
1861
|
self._trigger_event(attribute, old, value)
|
|
@@ -2411,6 +2411,21 @@ class _ParametersRestorer:
|
|
|
2411
2411
|
self._restore = {}
|
|
2412
2412
|
|
|
2413
2413
|
|
|
2414
|
+
def _find_descriptor(cls: type, attr: str) -> t.Any:
|
|
2415
|
+
"""
|
|
2416
|
+
Return the descriptor implementing ``attr`` on ``cls``, or None.
|
|
2417
|
+
|
|
2418
|
+
Used to invoke a descriptor without going through attribute lookup on the
|
|
2419
|
+
object, since an AttributeError raised inside a descriptor is
|
|
2420
|
+
indistinguishable from a missing attribute to the attribute machinery,
|
|
2421
|
+
which clears it and dispatches to ``__getattr__``.
|
|
2422
|
+
"""
|
|
2423
|
+
for klass in cls.__mro__:
|
|
2424
|
+
if attr in klass.__dict__:
|
|
2425
|
+
return klass.__dict__[attr]
|
|
2426
|
+
return None
|
|
2427
|
+
|
|
2428
|
+
|
|
2414
2429
|
class Parameters:
|
|
2415
2430
|
"""
|
|
2416
2431
|
Object that holds the ``.param`` namespace and implementation of
|
|
@@ -2562,9 +2577,26 @@ class Parameters:
|
|
|
2562
2577
|
if cls is None: # Class not initialized
|
|
2563
2578
|
raise AttributeError
|
|
2564
2579
|
|
|
2565
|
-
|
|
2580
|
+
ns_type = type(self_)
|
|
2581
|
+
|
|
2582
|
+
# The cached parameters are read from _param__private directly rather
|
|
2583
|
+
# than via the _cls_parameters property. If that property raised an
|
|
2584
|
+
# AttributeError we would be called to handle it and recurse, so it is
|
|
2585
|
+
# only invoked as a descriptor, i.e. without attribute lookup on self_.
|
|
2586
|
+
params = cls._param__private.params
|
|
2587
|
+
if not params:
|
|
2588
|
+
params = _find_descriptor(ns_type, '_cls_parameters').__get__(self_, ns_type)
|
|
2589
|
+
if attr in params:
|
|
2566
2590
|
return self_.__getitem__(attr)
|
|
2567
|
-
|
|
2591
|
+
|
|
2592
|
+
# attr is not a Parameter, so if it does exist on this class the
|
|
2593
|
+
# AttributeError we are handling was raised inside its descriptor.
|
|
2594
|
+
# Invoking it again surfaces that error instead of masking it.
|
|
2595
|
+
descriptor = _find_descriptor(ns_type, attr)
|
|
2596
|
+
if descriptor is not None:
|
|
2597
|
+
return descriptor.__get__(self_, ns_type)
|
|
2598
|
+
|
|
2599
|
+
if self_.self is None:
|
|
2568
2600
|
raise AttributeError(f"type object '{self_.cls.__name__}.param' has no attribute {attr!r}")
|
|
2569
2601
|
else:
|
|
2570
2602
|
raise AttributeError(f"'{self_.cls.__name__}.param' object has no attribute {attr!r}")
|
|
@@ -3140,18 +3172,21 @@ class Parameters:
|
|
|
3140
3172
|
pdict = private.params
|
|
3141
3173
|
if pdict:
|
|
3142
3174
|
if private.params_to_deepcopy is None or private.params_to_ref is None or private.params_with_default_factory is None:
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3175
|
+
to_deepcopy = []
|
|
3176
|
+
to_ref = []
|
|
3177
|
+
with_default_factory = []
|
|
3146
3178
|
for pname, pobj in pdict.items():
|
|
3147
3179
|
if pname == 'name':
|
|
3148
3180
|
continue
|
|
3149
3181
|
if pobj.default_factory is not None:
|
|
3150
|
-
|
|
3182
|
+
with_default_factory.append((pname, pobj))
|
|
3151
3183
|
elif pobj.instantiate:
|
|
3152
|
-
|
|
3184
|
+
to_deepcopy.append(pobj)
|
|
3153
3185
|
elif pobj.constant:
|
|
3154
|
-
|
|
3186
|
+
to_ref.append(pobj)
|
|
3187
|
+
private.params_to_deepcopy = to_deepcopy
|
|
3188
|
+
private.params_to_ref = to_ref
|
|
3189
|
+
private.params_with_default_factory = with_default_factory
|
|
3155
3190
|
return pdict
|
|
3156
3191
|
|
|
3157
3192
|
paramdict = {}
|
|
@@ -6320,7 +6355,7 @@ class ParameterizedFunction(Parameterized, t.Generic[_P, _R]):
|
|
|
6320
6355
|
params.pop('name')
|
|
6321
6356
|
cls = self_or_cls.__class__
|
|
6322
6357
|
|
|
6323
|
-
inst = Parameterized.__new__(cls)
|
|
6358
|
+
inst = Parameterized.__new__(cls) # pyrefly: ignore[bad-argument-type]
|
|
6324
6359
|
Parameterized.__init__(inst, **params)
|
|
6325
6360
|
if 'name' in params:
|
|
6326
6361
|
setattr(inst, "__name__", params['name'])
|
|
@@ -2647,7 +2647,7 @@ class Selector(SelectorBase, _SignatureSelector[_T]):
|
|
|
2647
2647
|
object.__setattr__(self, 'check_on_set', check_on_set)
|
|
2648
2648
|
|
|
2649
2649
|
instantiate = params.pop("instantiate", Undefined)
|
|
2650
|
-
params["instantiate"] = False if instantiate is Undefined else instantiate # pyrefly: ignore[bad-
|
|
2650
|
+
params["instantiate"] = False if instantiate is Undefined else instantiate # pyrefly: ignore[bad-assignment]
|
|
2651
2651
|
super().__init__(default=default, **params)
|
|
2652
2652
|
# Required as Parameter sets allow_None=True if default is None
|
|
2653
2653
|
if allow_None is Undefined:
|
|
@@ -2846,7 +2846,7 @@ class FileSelector(Selector[_T]):
|
|
|
2846
2846
|
self.default = self.objects[0] if self.objects else None
|
|
2847
2847
|
|
|
2848
2848
|
def get_range(self) -> dict[str, str | PathLike]:
|
|
2849
|
-
return _abbreviate_paths(self.path,super().get_range())
|
|
2849
|
+
return _abbreviate_paths(self.path, super().get_range())
|
|
2850
2850
|
|
|
2851
2851
|
|
|
2852
2852
|
class ListSelector(Selector):
|
|
@@ -3731,7 +3731,7 @@ class List(Parameter[_T]):
|
|
|
3731
3731
|
if is_instance and not isinstance(v, item_type):
|
|
3732
3732
|
err_kind = "instances"
|
|
3733
3733
|
obj_display = lambda v: type(v)
|
|
3734
|
-
elif not is_instance and (
|
|
3734
|
+
elif not is_instance and (not isinstance(v, type) or not issubclass(v, item_type)):
|
|
3735
3735
|
err_kind = "subclasses"
|
|
3736
3736
|
if err_kind:
|
|
3737
3737
|
raise TypeError(
|
|
@@ -94,6 +94,7 @@ import math
|
|
|
94
94
|
import operator
|
|
95
95
|
import typing as t
|
|
96
96
|
import warnings
|
|
97
|
+
import weakref
|
|
97
98
|
|
|
98
99
|
from collections.abc import (
|
|
99
100
|
AsyncGenerator, Callable, Coroutine, Generator, Iterable, Iterator, Sized
|
|
@@ -1359,6 +1360,39 @@ def bind(
|
|
|
1359
1360
|
setattr(wrapped, name, t.cast('Callable', accessor)(wrapped))
|
|
1360
1361
|
return wrapped
|
|
1361
1362
|
|
|
1363
|
+
class _WeakInvalidator:
|
|
1364
|
+
"""
|
|
1365
|
+
A weakly-bound invalidation callback for an ``rx`` pipeline node.
|
|
1366
|
+
|
|
1367
|
+
``rx`` nodes register invalidation callbacks on their *source* parameters.
|
|
1368
|
+
If those callbacks were strong bound-method references the source (which is
|
|
1369
|
+
typically long-lived) would keep every derived node — and anything it
|
|
1370
|
+
captured, such as large arrays — alive indefinitely. Wrapping the bound
|
|
1371
|
+
method in a :class:`weakref.WeakMethod` lets the derived node be garbage
|
|
1372
|
+
collected as soon as nothing else references it; once collected the call
|
|
1373
|
+
becomes a no-op and the now-dead watcher is removed by a finalizer (see
|
|
1374
|
+
``rx._watch_invalidation``).
|
|
1375
|
+
"""
|
|
1376
|
+
|
|
1377
|
+
__slots__ = ('_ref', '__weakref__')
|
|
1378
|
+
|
|
1379
|
+
def __init__(self, method):
|
|
1380
|
+
self._ref = weakref.WeakMethod(method)
|
|
1381
|
+
|
|
1382
|
+
def __call__(self, *events):
|
|
1383
|
+
method = self._ref()
|
|
1384
|
+
if method is not None:
|
|
1385
|
+
return method(*events)
|
|
1386
|
+
|
|
1387
|
+
|
|
1388
|
+
def _remove_watcher(owner, watcher):
|
|
1389
|
+
"""Unwatch ``watcher`` from ``owner``, ignoring if it is already gone."""
|
|
1390
|
+
try:
|
|
1391
|
+
owner.param.unwatch(watcher)
|
|
1392
|
+
except Exception:
|
|
1393
|
+
pass
|
|
1394
|
+
|
|
1395
|
+
|
|
1362
1396
|
# When we only support python >= 3.11 we should exchange 'rx' with Self type annotation below.
|
|
1363
1397
|
# See https://peps.python.org/pep-0673/
|
|
1364
1398
|
|
|
@@ -1712,9 +1746,21 @@ class rx:
|
|
|
1712
1746
|
for _, params in full_groupby(self._fn_params, lambda x: id(x.owner)):
|
|
1713
1747
|
fps = [p.name for p in params if p in self._root._fn_params]
|
|
1714
1748
|
if fps:
|
|
1715
|
-
params[0].owner
|
|
1749
|
+
self._watch_invalidation(params[0].owner, self._invalidate_obj, fps)
|
|
1716
1750
|
for _, params in full_groupby(self._internal_params, lambda x: id(x.owner)):
|
|
1717
|
-
params[0].owner
|
|
1751
|
+
self._watch_invalidation(params[0].owner, self._invalidate_current, [p.name for p in params])
|
|
1752
|
+
|
|
1753
|
+
def _watch_invalidation(self, owner, method, names):
|
|
1754
|
+
"""
|
|
1755
|
+
Register a *weak* invalidation watcher on a source parameter.
|
|
1756
|
+
|
|
1757
|
+
The callback only holds a weak reference to this node, so a long-lived
|
|
1758
|
+
source does not pin the (potentially short-lived) derived node alive.
|
|
1759
|
+
A finalizer removes the watcher automatically once this node is garbage
|
|
1760
|
+
collected, keeping the source's watcher list from growing without bound.
|
|
1761
|
+
"""
|
|
1762
|
+
watcher = owner.param._watch(_WeakInvalidator(method), names, precedence=-1)
|
|
1763
|
+
weakref.finalize(self, _remove_watcher, owner, watcher)
|
|
1718
1764
|
|
|
1719
1765
|
def _invalidate_current(self, *events):
|
|
1720
1766
|
if all(event.obj is self._trigger for event in events):
|
|
@@ -174,7 +174,6 @@ class TestFileDeserialization(unittest.TestCase):
|
|
|
174
174
|
|
|
175
175
|
@pd_skip
|
|
176
176
|
@ods_skip
|
|
177
|
-
@skipIf(sys.version_info[0] < 3, "py2k pandas does not support 'ods'")
|
|
178
177
|
def test_data_frame_ods(self):
|
|
179
178
|
path = '{}/val.ods'.format(self.temp_dir)
|
|
180
179
|
P.data_frame.to_excel(path, index=False)
|
|
@@ -182,6 +181,7 @@ class TestFileDeserialization(unittest.TestCase):
|
|
|
182
181
|
|
|
183
182
|
@pd_skip
|
|
184
183
|
@feather_skip
|
|
184
|
+
@skipIf(sys.version_info[:2] == (3, 10), "mismatch of pyarrow and pandas version")
|
|
185
185
|
def test_data_frame_feather(self):
|
|
186
186
|
path = '{}/val.feather'.format(self.temp_dir)
|
|
187
187
|
P.data_frame.to_feather(path)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import abc
|
|
1
2
|
import re
|
|
2
3
|
import unittest
|
|
3
4
|
|
|
@@ -16,6 +17,7 @@ class Obj: pass
|
|
|
16
17
|
class SubObj1(Obj): pass
|
|
17
18
|
class SubObj2(Obj): pass
|
|
18
19
|
class DiffObj: pass
|
|
20
|
+
class SubObjMeta(Obj, metaclass=abc.ABCMeta): pass
|
|
19
21
|
|
|
20
22
|
class TestListParameters(unittest.TestCase):
|
|
21
23
|
|
|
@@ -109,6 +111,12 @@ class TestListParameters(unittest.TestCase):
|
|
|
109
111
|
):
|
|
110
112
|
p.o = [DiffObj]
|
|
111
113
|
|
|
114
|
+
def test_set_object_subclass_custom_metaclass(self):
|
|
115
|
+
# A subclass defined with a custom metaclass should be accepted.
|
|
116
|
+
p = self.P()
|
|
117
|
+
p.o = [SubObjMeta]
|
|
118
|
+
assert p.o == [SubObjMeta]
|
|
119
|
+
|
|
112
120
|
def test_set_object_wrong_type(self):
|
|
113
121
|
p = self.P()
|
|
114
122
|
with pytest.raises(
|
|
@@ -3,6 +3,7 @@ import abc
|
|
|
3
3
|
import inspect
|
|
4
4
|
import re
|
|
5
5
|
import sys
|
|
6
|
+
import threading
|
|
6
7
|
import unittest
|
|
7
8
|
import warnings
|
|
8
9
|
import weakref
|
|
@@ -2002,3 +2003,108 @@ def test_no_param_namespace_cycle():
|
|
|
2002
2003
|
|
|
2003
2004
|
del obj
|
|
2004
2005
|
assert freed, "Parameterized instance not freed immediately — likely a reference cycle via .param"
|
|
2006
|
+
|
|
2007
|
+
|
|
2008
|
+
def test_no_op_slot_set_does_not_invalidate_init_cache():
|
|
2009
|
+
class P(param.Parameterized):
|
|
2010
|
+
x = param.Number(1)
|
|
2011
|
+
|
|
2012
|
+
P.param.objects('existing')
|
|
2013
|
+
private = P._param__private
|
|
2014
|
+
assert private.params_to_deepcopy is not None
|
|
2015
|
+
|
|
2016
|
+
P.param.x.constant = P.param.x.constant
|
|
2017
|
+
P.param.x.instantiate = P.param.x.instantiate
|
|
2018
|
+
assert private.params_to_deepcopy is not None
|
|
2019
|
+
|
|
2020
|
+
P.param.x.constant = not P.param.x.constant
|
|
2021
|
+
assert private.params_to_deepcopy is None
|
|
2022
|
+
|
|
2023
|
+
|
|
2024
|
+
def test_cls_parameters_rebuild_survives_concurrent_invalidation():
|
|
2025
|
+
# Setting constant/instantiate/default_factory on a Parameter invalidates
|
|
2026
|
+
# the init caches. If that happens while _cls_parameters is rebuilding
|
|
2027
|
+
# them, the rebuild must not fail (it used to append to None).
|
|
2028
|
+
class Invalidating(param.Parameter):
|
|
2029
|
+
|
|
2030
|
+
def __getattribute__(self, key):
|
|
2031
|
+
if key == 'instantiate':
|
|
2032
|
+
try:
|
|
2033
|
+
owner = object.__getattribute__(self, 'owner')
|
|
2034
|
+
except AttributeError:
|
|
2035
|
+
owner = None
|
|
2036
|
+
if owner is not None:
|
|
2037
|
+
private = owner._param__private
|
|
2038
|
+
private.params_to_deepcopy = None
|
|
2039
|
+
private.params_to_ref = None
|
|
2040
|
+
private.params_with_default_factory = None
|
|
2041
|
+
return super().__getattribute__(key)
|
|
2042
|
+
|
|
2043
|
+
class P(param.Parameterized):
|
|
2044
|
+
a = Invalidating()
|
|
2045
|
+
b = param.String(constant=True)
|
|
2046
|
+
|
|
2047
|
+
assert set(P.param.objects('existing')) == {'name', 'a', 'b'}
|
|
2048
|
+
|
|
2049
|
+
# Only invalidate the init caches, so that the rebuild happens in the
|
|
2050
|
+
# branch that reuses the already cached parameters
|
|
2051
|
+
private = P._param__private
|
|
2052
|
+
assert private.params
|
|
2053
|
+
private.params_to_deepcopy = None
|
|
2054
|
+
private.params_to_ref = None
|
|
2055
|
+
private.params_with_default_factory = None
|
|
2056
|
+
|
|
2057
|
+
assert set(P.param.objects('existing')) == {'name', 'a', 'b'}
|
|
2058
|
+
|
|
2059
|
+
|
|
2060
|
+
def test_cls_parameters_rebuild_is_thread_safe():
|
|
2061
|
+
class P(param.Parameterized):
|
|
2062
|
+
pass
|
|
2063
|
+
|
|
2064
|
+
for i in range(100):
|
|
2065
|
+
P.param.add_parameter(f'p{i}', param.Integer(default=i, constant=bool(i % 2)))
|
|
2066
|
+
|
|
2067
|
+
p = P()
|
|
2068
|
+
errors = []
|
|
2069
|
+
stop = threading.Event()
|
|
2070
|
+
|
|
2071
|
+
def toggle_readonly():
|
|
2072
|
+
# Mimics panel.util.parameters.edit_readonly
|
|
2073
|
+
try:
|
|
2074
|
+
for _ in range(500):
|
|
2075
|
+
if stop.is_set():
|
|
2076
|
+
return
|
|
2077
|
+
params = list(p.param.objects('existing').values())
|
|
2078
|
+
constants = [po.constant for po in params]
|
|
2079
|
+
for po in params:
|
|
2080
|
+
po.constant = False
|
|
2081
|
+
for po, constant in zip(params, constants):
|
|
2082
|
+
po.constant = constant
|
|
2083
|
+
except Exception as e:
|
|
2084
|
+
errors.append(e)
|
|
2085
|
+
stop.set()
|
|
2086
|
+
|
|
2087
|
+
threads = [threading.Thread(target=toggle_readonly) for _ in range(4)]
|
|
2088
|
+
for t in threads:
|
|
2089
|
+
t.start()
|
|
2090
|
+
for t in threads:
|
|
2091
|
+
t.join()
|
|
2092
|
+
|
|
2093
|
+
assert not errors, errors[0]
|
|
2094
|
+
|
|
2095
|
+
|
|
2096
|
+
def test_param_namespace_getattr_does_not_mask_descriptor_errors():
|
|
2097
|
+
class P(param.Parameterized):
|
|
2098
|
+
x = param.Number(1)
|
|
2099
|
+
|
|
2100
|
+
original = parameterized.Parameters._cls_parameters
|
|
2101
|
+
|
|
2102
|
+
def broken(self_):
|
|
2103
|
+
raise AttributeError('the real error')
|
|
2104
|
+
|
|
2105
|
+
try:
|
|
2106
|
+
parameterized.Parameters._cls_parameters = property(broken)
|
|
2107
|
+
with pytest.raises(AttributeError, match='the real error'):
|
|
2108
|
+
P().param.objects('existing')
|
|
2109
|
+
finally:
|
|
2110
|
+
parameterized.Parameters._cls_parameters = original
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
+
import gc
|
|
2
3
|
import math
|
|
3
4
|
import operator
|
|
4
5
|
import re
|
|
5
6
|
import time
|
|
7
|
+
import weakref
|
|
6
8
|
|
|
7
9
|
import param
|
|
8
10
|
import pytest
|
|
@@ -1029,3 +1031,28 @@ async def test_async_shared_rx_only_triggers_once(lazy):
|
|
|
1029
1031
|
assert y_rx.rx.value == 4
|
|
1030
1032
|
|
|
1031
1033
|
assert call_count == 2
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
def test_reactive_derived_node_is_garbage_collected():
|
|
1037
|
+
def watcher_count(source):
|
|
1038
|
+
watchers = source._internal_params[0].owner._param__private.watchers
|
|
1039
|
+
return sum(len(lst) for what in watchers.values() for lst in what.values())
|
|
1040
|
+
|
|
1041
|
+
a = param.rx(1)
|
|
1042
|
+
baseline = watcher_count(a)
|
|
1043
|
+
assert baseline == 2
|
|
1044
|
+
|
|
1045
|
+
b = a + 1
|
|
1046
|
+
assert b.rx.value == 2
|
|
1047
|
+
assert watcher_count(a) > baseline
|
|
1048
|
+
|
|
1049
|
+
ref = weakref.ref(b)
|
|
1050
|
+
del b
|
|
1051
|
+
gc.collect()
|
|
1052
|
+
assert ref() is None
|
|
1053
|
+
assert watcher_count(a) == baseline
|
|
1054
|
+
|
|
1055
|
+
c = a + 10
|
|
1056
|
+
a.rx.value = 5
|
|
1057
|
+
assert c.rx.value == 15
|
|
1058
|
+
assert watcher_count(a) > baseline
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import datetime as dt
|
|
2
2
|
import os
|
|
3
3
|
|
|
4
|
+
from collections import OrderedDict
|
|
4
5
|
from collections.abc import Iterable
|
|
5
6
|
from functools import partial
|
|
7
|
+
from tempfile import TemporaryDirectory
|
|
6
8
|
|
|
7
9
|
import param
|
|
8
10
|
import pytest
|
|
@@ -11,6 +13,7 @@ from param import guess_param_types, resolve_path
|
|
|
11
13
|
from param.parameterized import bothmethod, Parameterized, ParameterizedABC
|
|
12
14
|
from param._utils import (
|
|
13
15
|
# ParamWarning,
|
|
16
|
+
_abbreviate_paths,
|
|
14
17
|
_is_abstract,
|
|
15
18
|
_is_mutable_container,
|
|
16
19
|
concrete_descendents,
|
|
@@ -547,6 +550,18 @@ def test_concrete_descendents():
|
|
|
547
550
|
}
|
|
548
551
|
|
|
549
552
|
|
|
553
|
+
def test_abbreviate_paths():
|
|
554
|
+
ranges = OrderedDict()
|
|
555
|
+
expected = OrderedDict()
|
|
556
|
+
with TemporaryDirectory() as tempdir:
|
|
557
|
+
path = f"{tempdir}/*"
|
|
558
|
+
for filename in ("a.txt", "f.txt"):
|
|
559
|
+
fullpath = f"{tempdir}/{filename}"
|
|
560
|
+
ranges[fullpath] = fullpath
|
|
561
|
+
expected[filename] = fullpath
|
|
562
|
+
assert _abbreviate_paths(path, ranges) == expected
|
|
563
|
+
|
|
564
|
+
|
|
550
565
|
# def test_concrete_descendents_same_name_warns():
|
|
551
566
|
# class X: pass
|
|
552
567
|
# class Y(X): pass
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|