param 2.4.1rc1__tar.gz → 2.4.2rc1__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.
Files changed (75) hide show
  1. {param-2.4.1rc1 → param-2.4.2rc1}/PKG-INFO +2 -2
  2. {param-2.4.1rc1 → param-2.4.2rc1}/param/_utils.py +3 -3
  3. {param-2.4.1rc1 → param-2.4.2rc1}/param/_version.py +2 -2
  4. {param-2.4.1rc1 → param-2.4.2rc1}/param/parameterized.py +111 -20
  5. {param-2.4.1rc1 → param-2.4.2rc1}/param/parameters.py +3 -3
  6. {param-2.4.1rc1 → param-2.4.2rc1}/param/reactive.py +139 -18
  7. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testfiledeserialization.py +1 -1
  8. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testlist.py +8 -0
  9. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testparameterizedobject.py +106 -0
  10. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testreactive.py +281 -0
  11. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testrefs.py +49 -0
  12. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testutils.py +15 -0
  13. {param-2.4.1rc1 → param-2.4.2rc1}/.gitignore +0 -0
  14. {param-2.4.1rc1 → param-2.4.2rc1}/LICENSE.txt +0 -0
  15. {param-2.4.1rc1 → param-2.4.2rc1}/README.md +0 -0
  16. {param-2.4.1rc1 → param-2.4.2rc1}/numbergen/__init__.py +0 -0
  17. {param-2.4.1rc1 → param-2.4.2rc1}/param/__init__.py +0 -0
  18. {param-2.4.1rc1 → param-2.4.2rc1}/param/depends.py +0 -0
  19. {param-2.4.1rc1 → param-2.4.2rc1}/param/display.py +0 -0
  20. {param-2.4.1rc1 → param-2.4.2rc1}/param/ipython.py +0 -0
  21. {param-2.4.1rc1 → param-2.4.2rc1}/param/mypy_plugin.py +0 -0
  22. {param-2.4.1rc1 → param-2.4.2rc1}/param/py.typed +0 -0
  23. {param-2.4.1rc1 → param-2.4.2rc1}/param/serializer.py +0 -0
  24. {param-2.4.1rc1 → param-2.4.2rc1}/param/version.py +0 -0
  25. {param-2.4.1rc1 → param-2.4.2rc1}/pyproject.toml +0 -0
  26. {param-2.4.1rc1 → param-2.4.2rc1}/tests/__init__.py +0 -0
  27. {param-2.4.1rc1 → param-2.4.2rc1}/tests/assert_types.py +0 -0
  28. {param-2.4.1rc1 → param-2.4.2rc1}/tests/conftest.py +0 -0
  29. {param-2.4.1rc1 → param-2.4.2rc1}/tests/pyrightconfig-bare.json +0 -0
  30. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testaddparameter.py +0 -0
  31. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testbind.py +0 -0
  32. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testbooleanparam.py +0 -0
  33. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testbytesparam.py +0 -0
  34. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testcalendardateparam.py +0 -0
  35. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testcalendardaterangeparam.py +0 -0
  36. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testcallable.py +0 -0
  37. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testclassselector.py +0 -0
  38. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testcolorparameter.py +0 -0
  39. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testcomparator.py +0 -0
  40. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testcompositeparams.py +0 -0
  41. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testcustomparam.py +0 -0
  42. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testdateparam.py +0 -0
  43. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testdaterangeparam.py +0 -0
  44. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testdefaultfactory.py +0 -0
  45. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testdefaults.py +0 -0
  46. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testdeprecations.py +0 -0
  47. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testdynamicparams.py +0 -0
  48. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testfileselector.py +0 -0
  49. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testimports.py +0 -0
  50. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testipythonmagic.py +0 -0
  51. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testjsonserialization.py +0 -0
  52. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testlistselector.py +0 -0
  53. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testmultifileselector.py +0 -0
  54. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testnumbergen.py +0 -0
  55. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testnumberparameter.py +0 -0
  56. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testnumpy.py +0 -0
  57. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testobjectselector.py +0 -0
  58. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testpandas.py +0 -0
  59. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testparamdepends.py +0 -0
  60. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testparameter.py +0 -0
  61. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testparameterizedrepr.py +0 -0
  62. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testparamoutput.py +0 -0
  63. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testparamunion.py +0 -0
  64. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testpathparam.py +0 -0
  65. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testpickle.py +0 -0
  66. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testrangeparameter.py +0 -0
  67. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testreprhtml.py +0 -0
  68. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testselector.py +0 -0
  69. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testsignatures.py +0 -0
  70. {param-2.4.1rc1 → param-2.4.2rc1}/tests/teststringparam.py +0 -0
  71. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testtimedependent.py +0 -0
  72. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testtupleparam.py +0 -0
  73. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testversion.py +0 -0
  74. {param-2.4.1rc1 → param-2.4.2rc1}/tests/testwatch.py +0 -0
  75. {param-2.4.1rc1 → param-2.4.2rc1}/tests/utils.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: param
3
- Version: 2.4.1rc1
3
+ Version: 2.4.2rc1
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 commonprefix, dirname, sep
547
+ from os.path import commonpath, dirname, sep
548
548
 
549
- prefix = commonprefix([dirname(name)+sep for name in named_paths.keys()]+[pathspec])
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.1rc1'
22
- __version_tuple__ = version_tuple = (2, 4, 1, 'rc1')
21
+ __version__ = version = '2.4.2rc1'
22
+ __version_tuple__ = version_tuple = (2, 4, 2, 'rc1')
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,27 @@ class Parameters:
2562
2577
  if cls is None: # Class not initialized
2563
2578
  raise AttributeError
2564
2579
 
2565
- if attr in self_._cls_parameters:
2580
+ ns_type = type(self_)
2581
+
2582
+ # Read the cached parameters from _param__private rather than from the
2583
+ # _cls_parameters property: an AttributeError raised by that property is
2584
+ # dispatched to this method, so accessing it as an attribute here would
2585
+ # recurse. When the cache is empty the property is invoked directly as a
2586
+ # descriptor instead, which bypasses that dispatch.
2587
+ params = cls._param__private.params
2588
+ if not params:
2589
+ params = _find_descriptor(ns_type, '_cls_parameters').__get__(self_, ns_type)
2590
+ if attr in params:
2566
2591
  return self_.__getitem__(attr)
2567
- elif self_.self is None:
2592
+
2593
+ # attr is not a Parameter, so if it does exist on this class the
2594
+ # AttributeError we are handling was raised inside its descriptor.
2595
+ # Invoking it again surfaces that error instead of masking it.
2596
+ descriptor = _find_descriptor(ns_type, attr)
2597
+ if descriptor is not None:
2598
+ return descriptor.__get__(self_, ns_type)
2599
+
2600
+ if self_.self is None:
2568
2601
  raise AttributeError(f"type object '{self_.cls.__name__}.param' has no attribute {attr!r}")
2569
2602
  else:
2570
2603
  raise AttributeError(f"'{self_.cls.__name__}.param' object has no attribute {attr!r}")
@@ -2710,7 +2743,10 @@ class Parameters:
2710
2743
  if new_val is Skip or new_val is Undefined:
2711
2744
  continue
2712
2745
  elif is_async:
2713
- async_executor(partial(self_._async_ref, pname, t.cast("t.Awaitable[t.Any]", new_val)))
2746
+ generation = self_._schedule_async_ref(pname)
2747
+ async_executor(partial(
2748
+ self_._async_ref, pname, t.cast("t.Awaitable[t.Any]", new_val), generation
2749
+ ))
2714
2750
  continue
2715
2751
 
2716
2752
  updates[pname] = new_val
@@ -2731,39 +2767,85 @@ class Parameters:
2731
2767
  except Skip:
2732
2768
  value = Undefined
2733
2769
  if is_async and pobj.name:
2734
- async_executor(partial(self_._async_ref, pobj.name, t.cast("t.Awaitable[t.Any]", value)))
2770
+ generation = self_._schedule_async_ref(pobj.name)
2771
+ async_executor(partial(
2772
+ self_._async_ref, pobj.name, t.cast("t.Awaitable[t.Any]", value), generation
2773
+ ))
2735
2774
  value = None
2736
2775
  return ref, deps, value, is_async
2737
2776
 
2738
- async def _async_ref(self_, pname: str, awaitable: t.Awaitable[t.Any]):
2777
+ def _schedule_async_ref(self_, pname: str) -> int:
2778
+ """
2779
+ Record that an asynchronous reference resolution is about to be
2780
+ scheduled and return the generation identifying it.
2781
+
2782
+ The generation is bumped synchronously, before the task is handed to
2783
+ the executor, so that the reference reads as unsettled from the moment
2784
+ it is superseded rather than only once the task starts running.
2785
+ """
2786
+ if self_.self is None:
2787
+ return 0
2788
+ private = self_.self._param__private
2789
+ private.async_ref_scheduled[pname] += 1
2790
+ return private.async_ref_scheduled[pname]
2791
+
2792
+ def _settle_async_ref(self_, pname: str, generation: int):
2793
+ """
2794
+ Record that the resolution identified by ``generation`` produced a
2795
+ value, or gave up on producing one.
2796
+
2797
+ A superseded task settling late must not mark the reference settled for
2798
+ the generation that superseded it, so the generation is recorded rather
2799
+ than cleared. Generators settle on every value they yield, so a
2800
+ reference is unsettled only until its next value arrives, not until the
2801
+ generator is exhausted.
2802
+ """
2803
+ if self_.self is None or not generation:
2804
+ return
2805
+ settled = self_.self._param__private.async_ref_settled
2806
+ settled[pname] = max(settled[pname], generation)
2807
+
2808
+ def _awaiting_ref(self_, pname: str) -> bool:
2809
+ """Whether an asynchronous reference has not yet produced a value."""
2810
+ if self_.self is None:
2811
+ return False
2812
+ private = self_.self._param__private
2813
+ return private.async_ref_scheduled[pname] != private.async_ref_settled[pname]
2814
+
2815
+ async def _async_ref(self_, pname: str, awaitable: t.Awaitable[t.Any], generation: int = 0):
2739
2816
  if self_.self is None:
2740
2817
  return
2741
2818
  if not self_.self._param__private.initialized:
2742
- async_executor(partial(self_._async_ref, pname, awaitable))
2819
+ async_executor(partial(self_._async_ref, pname, awaitable, generation))
2743
2820
  return
2744
2821
 
2745
2822
  import asyncio
2746
2823
  current_task = asyncio.current_task()
2747
2824
  running_task = self_.self._param__private.async_refs.get(pname)
2748
- if running_task is None:
2825
+ if running_task is not current_task:
2826
+ if running_task is not None:
2827
+ running_task.cancel()
2749
2828
  self_.self._param__private.async_refs[pname] = current_task
2750
- elif current_task is not running_task:
2751
- self_.self._param__private.async_refs[pname].cancel()
2752
2829
  try:
2753
2830
  if isinstance(awaitable, types.AsyncGeneratorType):
2754
2831
  async for new_obj in awaitable:
2755
2832
  with _syncing(self_.self, (pname,)):
2756
2833
  self_.update({pname: new_obj})
2834
+ self_._settle_async_ref(pname, generation)
2757
2835
  else:
2758
2836
  with _syncing(self_.self, (pname,)):
2759
2837
  try:
2760
2838
  self_.update({pname: await awaitable})
2761
2839
  except Skip:
2762
2840
  pass
2841
+ self_._settle_async_ref(pname, generation)
2763
2842
  finally:
2764
- # Ensure we clean up but only if the task matches the current task
2765
- if self_.self._param__private.async_refs.get(pname) is current_task:
2766
- del self_.self._param__private.async_refs[pname]
2843
+ self_._settle_async_ref(pname, generation)
2844
+ # Ensure we clean up but only if the task matches the current task,
2845
+ # i.e. only the resolution that still owns the reference clears it.
2846
+ async_refs = self_.self._param__private.async_refs
2847
+ if pname in async_refs and async_refs[pname] is current_task:
2848
+ del async_refs[pname]
2767
2849
 
2768
2850
  @classmethod
2769
2851
  def _changed(cls, event):
@@ -3140,18 +3222,21 @@ class Parameters:
3140
3222
  pdict = private.params
3141
3223
  if pdict:
3142
3224
  if private.params_to_deepcopy is None or private.params_to_ref is None or private.params_with_default_factory is None:
3143
- private.params_to_deepcopy = []
3144
- private.params_to_ref = []
3145
- private.params_with_default_factory = []
3225
+ to_deepcopy = []
3226
+ to_ref = []
3227
+ with_default_factory = []
3146
3228
  for pname, pobj in pdict.items():
3147
3229
  if pname == 'name':
3148
3230
  continue
3149
3231
  if pobj.default_factory is not None:
3150
- private.params_with_default_factory.append((pname, pobj))
3232
+ with_default_factory.append((pname, pobj))
3151
3233
  elif pobj.instantiate:
3152
- private.params_to_deepcopy.append(pobj)
3234
+ to_deepcopy.append(pobj)
3153
3235
  elif pobj.constant:
3154
- private.params_to_ref.append(pobj)
3236
+ to_ref.append(pobj)
3237
+ private.params_to_deepcopy = to_deepcopy
3238
+ private.params_to_ref = to_ref
3239
+ private.params_with_default_factory = with_default_factory
3155
3240
  return pdict
3156
3241
 
3157
3242
  paramdict = {}
@@ -5603,6 +5688,8 @@ class _InstancePrivate:
5603
5688
  'dynamic_watchers',
5604
5689
  'params',
5605
5690
  'async_refs',
5691
+ 'async_ref_scheduled',
5692
+ 'async_ref_settled',
5606
5693
  'refs',
5607
5694
  'ref_watchers',
5608
5695
  'syncing',
@@ -5616,6 +5703,8 @@ class _InstancePrivate:
5616
5703
  dynamic_watchers: defaultdict[str, list[Watcher]]
5617
5704
  params: dict[str, Parameter]
5618
5705
  async_refs: dict[str, t.Any]
5706
+ async_ref_scheduled: defaultdict[str, int]
5707
+ async_ref_settled: defaultdict[str, int]
5619
5708
  refs: dict[str, t.Any]
5620
5709
  ref_watchers: list[tuple[tuple[str, ...], Watcher]]
5621
5710
  syncing: set[str]
@@ -5646,6 +5735,8 @@ class _InstancePrivate:
5646
5735
  }
5647
5736
  self.ref_watchers = []
5648
5737
  self.async_refs = {}
5738
+ self.async_ref_scheduled = defaultdict(int)
5739
+ self.async_ref_settled = defaultdict(int)
5649
5740
  self.parameters_state = parameters_state
5650
5741
  self.dynamic_watchers = defaultdict(list, dynamic_watchers or ())
5651
5742
  self.params = {} if params is None else params
@@ -6320,7 +6411,7 @@ class ParameterizedFunction(Parameterized, t.Generic[_P, _R]):
6320
6411
  params.pop('name')
6321
6412
  cls = self_or_cls.__class__
6322
6413
 
6323
- inst = Parameterized.__new__(cls)
6414
+ inst = Parameterized.__new__(cls) # pyrefly: ignore[bad-argument-type]
6324
6415
  Parameterized.__init__(inst, **params)
6325
6416
  if 'name' in params:
6326
6417
  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-typed-dict-key]
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 (type(v) is not type or not issubclass(v, item_type)):
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
@@ -114,6 +115,8 @@ from ._utils import _to_async_gen, iscoroutinefunction, full_groupby
114
115
  if t.TYPE_CHECKING:
115
116
  from typing_extensions import Self
116
117
 
118
+ from .parameterized import Watcher
119
+
117
120
  _P = t.ParamSpec('_P')
118
121
  _R = t.TypeVar('_R')
119
122
  _Y = t.TypeVar('_Y')
@@ -1359,6 +1362,76 @@ def bind(
1359
1362
  setattr(wrapped, name, t.cast('Callable', accessor)(wrapped))
1360
1363
  return wrapped
1361
1364
 
1365
+ class _WeakInvalidator:
1366
+ """
1367
+ A weakly-bound invalidation callback for an ``rx`` pipeline node.
1368
+
1369
+ ``rx`` nodes register invalidation callbacks on their *source* parameters.
1370
+ If those callbacks were strong bound-method references the source (which is
1371
+ typically long-lived) would keep every derived node — and anything it
1372
+ captured, such as large arrays — alive indefinitely. Wrapping the bound
1373
+ method in a :class:`weakref.WeakMethod` lets the derived node be garbage
1374
+ collected as soon as nothing else references it; once collected the call
1375
+ becomes a no-op and the now-dead watcher is removed by a finalizer (see
1376
+ ``rx._watch_invalidation``).
1377
+ """
1378
+
1379
+ __slots__ = ('_ref', '_watcher', '__weakref__')
1380
+
1381
+ _watcher: Watcher | None
1382
+
1383
+ def __init__(self, method):
1384
+ self._ref = weakref.WeakMethod(method)
1385
+ self._watcher = None
1386
+
1387
+ def __call__(self, *events):
1388
+ method = self._ref()
1389
+ if method is not None:
1390
+ return method(*events)
1391
+
1392
+
1393
+ def _remove_watcher(
1394
+ owner_ref: weakref.ref[Parameterized | type[Parameterized]],
1395
+ invalidator_ref: weakref.ref[_WeakInvalidator],
1396
+ ) -> None:
1397
+ """
1398
+ Unwatch a dead node's invalidation watcher, ignoring if it is already gone.
1399
+
1400
+ Both refs must be weak: ``weakref.finalize`` holds its arguments until the
1401
+ referent dies, so a strong owner (or ``Watcher``, whose ``inst`` is the
1402
+ owner) would make the node uncollectable. ``Watcher`` subclasses ``tuple``
1403
+ and cannot be weakly referenced, so it is reached via the invalidator.
1404
+ """
1405
+ owner, invalidator = owner_ref(), invalidator_ref()
1406
+ if owner is None or invalidator is None or invalidator._watcher is None:
1407
+ return
1408
+ try:
1409
+ owner.param.unwatch(invalidator._watcher)
1410
+ except Exception:
1411
+ pass
1412
+
1413
+
1414
+ async def _close_stale(obj):
1415
+ """
1416
+ Discard an awaitable or async generator whose result is no longer needed.
1417
+
1418
+ Closing a coroutine that was never awaited also suppresses the warning
1419
+ Python emits when it is garbage collected.
1420
+ """
1421
+ try:
1422
+ if inspect.isasyncgen(obj):
1423
+ await obj.aclose()
1424
+ elif inspect.iscoroutine(obj):
1425
+ obj.close()
1426
+ except (StopAsyncIteration, GeneratorExit):
1427
+ pass
1428
+ except Exception:
1429
+ logger.debug(
1430
+ "Ignoring close error for stale reactive task.",
1431
+ exc_info=True,
1432
+ )
1433
+
1434
+
1362
1435
  # When we only support python >= 3.11 we should exchange 'rx' with Self type annotation below.
1363
1436
  # See https://peps.python.org/pep-0673/
1364
1437
 
@@ -1524,6 +1597,8 @@ class rx:
1524
1597
  self._dirty_obj = False
1525
1598
  self._current_task = None
1526
1599
  self._resolve_generation = 0
1600
+ self._finished_generation = 0
1601
+ self._skipped = False
1527
1602
  self._error_state = None
1528
1603
  self._current_ = _current
1529
1604
  # _shared is used for branching rx pipelines where we clone the input.
@@ -1627,6 +1702,14 @@ class rx:
1627
1702
  inspect.isgeneratorfunction(fn)
1628
1703
  )
1629
1704
 
1705
+ @property
1706
+ def _awaiting(self) -> bool:
1707
+ """
1708
+ Whether an asynchronous resolution is in flight that has not yet
1709
+ produced a value for the current generation.
1710
+ """
1711
+ return self._resolve_generation != self._finished_generation
1712
+
1630
1713
  @property
1631
1714
  def _current(self):
1632
1715
  if self._error_state:
@@ -1712,9 +1795,25 @@ class rx:
1712
1795
  for _, params in full_groupby(self._fn_params, lambda x: id(x.owner)):
1713
1796
  fps = [p.name for p in params if p in self._root._fn_params]
1714
1797
  if fps:
1715
- params[0].owner.param._watch(self._invalidate_obj, fps, precedence=-1)
1798
+ self._watch_invalidation(params[0].owner, self._invalidate_obj, fps)
1716
1799
  for _, params in full_groupby(self._internal_params, lambda x: id(x.owner)):
1717
- params[0].owner.param._watch(self._invalidate_current, [p.name for p in params], precedence=-1)
1800
+ self._watch_invalidation(params[0].owner, self._invalidate_current, [p.name for p in params])
1801
+
1802
+ def _watch_invalidation(self, owner, method, names):
1803
+ """
1804
+ Register a *weak* invalidation watcher on a source parameter.
1805
+
1806
+ The callback only holds a weak reference to this node, so a long-lived
1807
+ source does not pin the (potentially short-lived) derived node alive.
1808
+ A finalizer removes the watcher automatically once this node is garbage
1809
+ collected, keeping the source's watcher list from growing without bound.
1810
+ The finalizer is handed weak references only (see ``_remove_watcher``).
1811
+ """
1812
+ invalidator = _WeakInvalidator(method)
1813
+ invalidator._watcher = owner.param._watch(invalidator, names, precedence=-1)
1814
+ weakref.finalize(
1815
+ self, _remove_watcher, weakref.ref(owner), weakref.ref(invalidator)
1816
+ )
1718
1817
 
1719
1818
  def _invalidate_current(self, *events):
1720
1819
  if all(event.obj is self._trigger for event in events):
@@ -1726,14 +1825,23 @@ class rx:
1726
1825
  t.cast('t.Any', self._root)._dirty_obj = True
1727
1826
  self._error_state = None
1728
1827
 
1729
- async def _resolve_async(self, obj=None, generation=None):
1828
+ async def _resolve_async(self, obj=None, generation: int = 0):
1730
1829
  import asyncio
1731
- self._current_task = task = asyncio.current_task()
1732
- trigger = self._trigger
1733
1830
 
1734
1831
  def stale():
1735
1832
  return generation != self._resolve_generation
1736
1833
 
1834
+ if stale():
1835
+ # A newer resolution was requested before this task was scheduled,
1836
+ # so nothing has awaited obj yet and the operation has not begun.
1837
+ # Close it instead of computing a result that is already superseded.
1838
+ # This must happen before _current_task is claimed below, otherwise
1839
+ # the finally clause would clear the genuinely current task and hide
1840
+ # it from the next _lazy_resolve.
1841
+ await _close_stale(obj)
1842
+ return
1843
+ self._current_task = task = asyncio.current_task()
1844
+ trigger = self._trigger
1737
1845
  try:
1738
1846
  if trigger is None:
1739
1847
  return
@@ -1746,27 +1854,22 @@ class rx:
1746
1854
  if stale():
1747
1855
  return
1748
1856
  self._current_ = shared.rx.value
1857
+ self._finished_generation = generation
1749
1858
  trigger.param.trigger('value')
1750
1859
  elif inspect.isasyncgen(obj):
1751
1860
  async for val in obj:
1752
1861
  if stale():
1753
- try:
1754
- await obj.aclose()
1755
- except (StopAsyncIteration, GeneratorExit):
1756
- pass
1757
- except Exception:
1758
- logger.debug(
1759
- "Ignoring async generator close error for stale reactive task.",
1760
- exc_info=True,
1761
- )
1862
+ await _close_stale(obj)
1762
1863
  break
1763
1864
  self._current_ = val
1865
+ self._finished_generation = generation
1764
1866
  trigger.param.trigger('value')
1765
1867
  else:
1766
1868
  value = await obj
1767
1869
  if stale():
1768
1870
  return
1769
1871
  self._current_ = value
1872
+ self._finished_generation = generation
1770
1873
  trigger.param.trigger('value')
1771
1874
  except asyncio.CancelledError:
1772
1875
  return
@@ -1794,6 +1897,8 @@ class rx:
1794
1897
  if obj is Skip or obj is Undefined:
1795
1898
  self._current_ = Undefined
1796
1899
  raise Skip
1900
+ elif self._prev is not None and self._prev._skipped:
1901
+ raise Skip
1797
1902
  elif (
1798
1903
  self._shared is not None and
1799
1904
  self._method is None and
@@ -1805,9 +1910,14 @@ class rx:
1805
1910
  if self._is_async:
1806
1911
  self._shared.rx.value # trigger async resolve
1807
1912
  self._lazy_resolve()
1808
- else:
1809
- self._current_ = self._shared.rx.value
1810
- raise Skip
1913
+ raise Skip
1914
+ # Returns instead of raising Skip because this path does
1915
+ # resolve to a value, so it must mirror the shared node's
1916
+ # skip state rather than be marked skipped by the handler.
1917
+ self._current_ = self._shared.rx.value
1918
+ self._skipped = self._shared._skipped
1919
+ self._dirty = False
1920
+ return self._current_
1811
1921
  operation = self._operation
1812
1922
  if operation:
1813
1923
  obj = self._eval_operation(obj, operation)
@@ -1818,13 +1928,19 @@ class rx:
1818
1928
  raise Skip
1819
1929
  except Skip:
1820
1930
  self._dirty = False
1931
+ self._skipped = True
1821
1932
  return self._current_
1822
1933
  except Exception as e:
1823
1934
  self._error_state = e
1824
1935
  raise e
1825
1936
  self._current_ = current = obj
1937
+ self._skipped = False
1826
1938
  else:
1827
1939
  current = self._current_
1940
+ # A node awaiting an asynchronous result still holds the value it
1941
+ # computed from the previous inputs; report it as skipped so it is
1942
+ # not propagated as if it were current.
1943
+ self._skipped = self._awaiting
1828
1944
  self._dirty = False
1829
1945
  if self._method:
1830
1946
  # E.g. `pi = dfi.A` leads to `pi._method` equal to `'A'`.
@@ -2164,6 +2280,11 @@ class rx:
2164
2280
  def _rx_transform(obj):
2165
2281
  if not isinstance(obj, rx):
2166
2282
  return obj
2167
- return bind(lambda *_: obj.rx.value, *obj._params)
2283
+ def resolve(*_):
2284
+ value = obj.rx.value
2285
+ if obj._skipped or value is Skip or value is Undefined:
2286
+ raise Skip
2287
+ return value
2288
+ return bind(resolve, *obj._params)
2168
2289
 
2169
2290
  register_reference_transform(_rx_transform)
@@ -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(