param 2.4.2rc2__tar.gz → 2.5.0a0__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.2rc2 → param-2.5.0a0}/PKG-INFO +2 -1
  2. {param-2.4.2rc2 → param-2.5.0a0}/param/__init__.py +2 -1
  3. {param-2.4.2rc2 → param-2.5.0a0}/param/_version.py +2 -2
  4. {param-2.4.2rc2 → param-2.5.0a0}/param/parameters.py +4 -1
  5. {param-2.4.2rc2 → param-2.5.0a0}/param/reactive.py +294 -16
  6. {param-2.4.2rc2 → param-2.5.0a0}/pyproject.toml +1 -0
  7. {param-2.4.2rc2 → param-2.5.0a0}/tests/testreactive.py +566 -0
  8. {param-2.4.2rc2 → param-2.5.0a0}/.gitignore +0 -0
  9. {param-2.4.2rc2 → param-2.5.0a0}/LICENSE.txt +0 -0
  10. {param-2.4.2rc2 → param-2.5.0a0}/README.md +0 -0
  11. {param-2.4.2rc2 → param-2.5.0a0}/numbergen/__init__.py +0 -0
  12. {param-2.4.2rc2 → param-2.5.0a0}/param/_utils.py +0 -0
  13. {param-2.4.2rc2 → param-2.5.0a0}/param/depends.py +0 -0
  14. {param-2.4.2rc2 → param-2.5.0a0}/param/display.py +0 -0
  15. {param-2.4.2rc2 → param-2.5.0a0}/param/ipython.py +0 -0
  16. {param-2.4.2rc2 → param-2.5.0a0}/param/mypy_plugin.py +0 -0
  17. {param-2.4.2rc2 → param-2.5.0a0}/param/parameterized.py +0 -0
  18. {param-2.4.2rc2 → param-2.5.0a0}/param/py.typed +0 -0
  19. {param-2.4.2rc2 → param-2.5.0a0}/param/serializer.py +0 -0
  20. {param-2.4.2rc2 → param-2.5.0a0}/param/version.py +0 -0
  21. {param-2.4.2rc2 → param-2.5.0a0}/tests/__init__.py +0 -0
  22. {param-2.4.2rc2 → param-2.5.0a0}/tests/assert_types.py +0 -0
  23. {param-2.4.2rc2 → param-2.5.0a0}/tests/conftest.py +0 -0
  24. {param-2.4.2rc2 → param-2.5.0a0}/tests/pyrightconfig-bare.json +0 -0
  25. {param-2.4.2rc2 → param-2.5.0a0}/tests/testaddparameter.py +0 -0
  26. {param-2.4.2rc2 → param-2.5.0a0}/tests/testbind.py +0 -0
  27. {param-2.4.2rc2 → param-2.5.0a0}/tests/testbooleanparam.py +0 -0
  28. {param-2.4.2rc2 → param-2.5.0a0}/tests/testbytesparam.py +0 -0
  29. {param-2.4.2rc2 → param-2.5.0a0}/tests/testcalendardateparam.py +0 -0
  30. {param-2.4.2rc2 → param-2.5.0a0}/tests/testcalendardaterangeparam.py +0 -0
  31. {param-2.4.2rc2 → param-2.5.0a0}/tests/testcallable.py +0 -0
  32. {param-2.4.2rc2 → param-2.5.0a0}/tests/testclassselector.py +0 -0
  33. {param-2.4.2rc2 → param-2.5.0a0}/tests/testcolorparameter.py +0 -0
  34. {param-2.4.2rc2 → param-2.5.0a0}/tests/testcomparator.py +0 -0
  35. {param-2.4.2rc2 → param-2.5.0a0}/tests/testcompositeparams.py +0 -0
  36. {param-2.4.2rc2 → param-2.5.0a0}/tests/testcustomparam.py +0 -0
  37. {param-2.4.2rc2 → param-2.5.0a0}/tests/testdateparam.py +0 -0
  38. {param-2.4.2rc2 → param-2.5.0a0}/tests/testdaterangeparam.py +0 -0
  39. {param-2.4.2rc2 → param-2.5.0a0}/tests/testdefaultfactory.py +0 -0
  40. {param-2.4.2rc2 → param-2.5.0a0}/tests/testdefaults.py +0 -0
  41. {param-2.4.2rc2 → param-2.5.0a0}/tests/testdeprecations.py +0 -0
  42. {param-2.4.2rc2 → param-2.5.0a0}/tests/testdynamicparams.py +0 -0
  43. {param-2.4.2rc2 → param-2.5.0a0}/tests/testfiledeserialization.py +0 -0
  44. {param-2.4.2rc2 → param-2.5.0a0}/tests/testfileselector.py +0 -0
  45. {param-2.4.2rc2 → param-2.5.0a0}/tests/testimports.py +0 -0
  46. {param-2.4.2rc2 → param-2.5.0a0}/tests/testipythonmagic.py +0 -0
  47. {param-2.4.2rc2 → param-2.5.0a0}/tests/testjsonserialization.py +0 -0
  48. {param-2.4.2rc2 → param-2.5.0a0}/tests/testlist.py +0 -0
  49. {param-2.4.2rc2 → param-2.5.0a0}/tests/testlistselector.py +0 -0
  50. {param-2.4.2rc2 → param-2.5.0a0}/tests/testmultifileselector.py +0 -0
  51. {param-2.4.2rc2 → param-2.5.0a0}/tests/testnumbergen.py +0 -0
  52. {param-2.4.2rc2 → param-2.5.0a0}/tests/testnumberparameter.py +0 -0
  53. {param-2.4.2rc2 → param-2.5.0a0}/tests/testnumpy.py +0 -0
  54. {param-2.4.2rc2 → param-2.5.0a0}/tests/testobjectselector.py +0 -0
  55. {param-2.4.2rc2 → param-2.5.0a0}/tests/testpandas.py +0 -0
  56. {param-2.4.2rc2 → param-2.5.0a0}/tests/testparamdepends.py +0 -0
  57. {param-2.4.2rc2 → param-2.5.0a0}/tests/testparameter.py +0 -0
  58. {param-2.4.2rc2 → param-2.5.0a0}/tests/testparameterizedobject.py +0 -0
  59. {param-2.4.2rc2 → param-2.5.0a0}/tests/testparameterizedrepr.py +0 -0
  60. {param-2.4.2rc2 → param-2.5.0a0}/tests/testparamoutput.py +0 -0
  61. {param-2.4.2rc2 → param-2.5.0a0}/tests/testparamunion.py +0 -0
  62. {param-2.4.2rc2 → param-2.5.0a0}/tests/testpathparam.py +0 -0
  63. {param-2.4.2rc2 → param-2.5.0a0}/tests/testpickle.py +0 -0
  64. {param-2.4.2rc2 → param-2.5.0a0}/tests/testrangeparameter.py +0 -0
  65. {param-2.4.2rc2 → param-2.5.0a0}/tests/testrefs.py +0 -0
  66. {param-2.4.2rc2 → param-2.5.0a0}/tests/testreprhtml.py +0 -0
  67. {param-2.4.2rc2 → param-2.5.0a0}/tests/testselector.py +0 -0
  68. {param-2.4.2rc2 → param-2.5.0a0}/tests/testsignatures.py +0 -0
  69. {param-2.4.2rc2 → param-2.5.0a0}/tests/teststringparam.py +0 -0
  70. {param-2.4.2rc2 → param-2.5.0a0}/tests/testtimedependent.py +0 -0
  71. {param-2.4.2rc2 → param-2.5.0a0}/tests/testtupleparam.py +0 -0
  72. {param-2.4.2rc2 → param-2.5.0a0}/tests/testutils.py +0 -0
  73. {param-2.4.2rc2 → param-2.5.0a0}/tests/testversion.py +0 -0
  74. {param-2.4.2rc2 → param-2.5.0a0}/tests/testwatch.py +0 -0
  75. {param-2.4.2rc2 → param-2.5.0a0}/tests/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: param
3
- Version: 2.4.2rc2
3
+ Version: 2.5.0a0
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
@@ -23,6 +23,7 @@ Classifier: Programming Language :: Python :: 3.11
23
23
  Classifier: Programming Language :: Python :: 3.12
24
24
  Classifier: Programming Language :: Python :: 3.13
25
25
  Classifier: Programming Language :: Python :: 3.14
26
+ Classifier: Programming Language :: Python :: 3.15
26
27
  Classifier: Topic :: Scientific/Engineering
27
28
  Classifier: Topic :: Software Development :: Libraries
28
29
  Classifier: Typing :: Typed
@@ -99,7 +99,7 @@ from .parameters import (
99
99
  CalendarDateRange,
100
100
  Event,
101
101
  )
102
- from .reactive import bind, rx
102
+ from .reactive import ReactiveError, bind, rx
103
103
  from ._utils import (
104
104
  descendents,
105
105
  concrete_descendents,
@@ -171,6 +171,7 @@ __all__ = (
171
171
  'Dict',
172
172
  'Dynamic',
173
173
  'ERROR',
174
+ 'ReactiveError',
174
175
  'Event',
175
176
  'FileSelector',
176
177
  'Filename',
@@ -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.2rc2'
22
- __version_tuple__ = version_tuple = (2, 4, 2, 'rc2')
21
+ __version__ = version = '2.5.0a0'
22
+ __version_tuple__ = version_tuple = (2, 5, 0, 'a0')
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -2647,7 +2647,10 @@ 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-assignment]
2650
+ if isinstance(instantiate, bool):
2651
+ params["instantiate"] = instantiate
2652
+ else:
2653
+ params["instantiate"] = False
2651
2654
  super().__init__(default=default, **params)
2652
2655
  # Required as Parameter sets allow_None=True if default is None
2653
2656
  if allow_None is Undefined:
@@ -113,6 +113,7 @@ from .parameters import Boolean, Event
113
113
  from ._utils import _to_async_gen, iscoroutinefunction, full_groupby
114
114
 
115
115
  if t.TYPE_CHECKING:
116
+ import builtins
116
117
  from typing_extensions import Self
117
118
 
118
119
  from .parameterized import Watcher
@@ -125,6 +126,29 @@ if t.TYPE_CHECKING:
125
126
  logger = logging.getLogger(__name__)
126
127
 
127
128
 
129
+ class ReactiveError:
130
+ """A value representing an error raised while evaluating a reactive expression."""
131
+
132
+ def __init__(self, exception: Exception, node=None):
133
+ self.exception = exception
134
+ self.node = weakref.ref(node) if node is not None else None
135
+
136
+ def __bool__(self):
137
+ return False
138
+
139
+ def __str__(self):
140
+ return str(self.exception)
141
+
142
+ def __repr__(self):
143
+ return f"ReactiveError({self.exception!r})"
144
+
145
+ def __getitem__(self, key):
146
+ return t.cast('t.Any', self.exception)[key]
147
+
148
+ def __getattr__(self, name):
149
+ return getattr(self.exception, name)
150
+
151
+
128
152
  class Wrapper(Parameterized):
129
153
  """Helper class to allow updating literal values easily."""
130
154
 
@@ -250,6 +274,17 @@ class reactive_ops:
250
274
  rxi = self._reactive
251
275
  return rxi if isinstance(rxi, rx) else rx(rxi)
252
276
 
277
+ @property
278
+ def error(self):
279
+ """Return the current :class:`ReactiveError` or exception, if any."""
280
+ if isinstance(self._reactive, rx):
281
+ try:
282
+ value = self._reactive._resolve()
283
+ except Exception as exc:
284
+ return exc
285
+ return value if isinstance(value, ReactiveError) else None
286
+ return None
287
+
253
288
  def and_(self, other) -> 'rx':
254
289
  """
255
290
  Perform a logical AND operation with the given operand.
@@ -595,6 +630,47 @@ class reactive_ops:
595
630
  return [func(v, *args, **kwargs) for v in vs]
596
631
  return self._as_rx()._apply_operator(apply, *args, **kwargs)
597
632
 
633
+ @property
634
+ def meta(self) -> dict[t.Any, t.Any]:
635
+ """
636
+ A per-node mapping of user metadata.
637
+
638
+ Unlike the reactive expression itself, metadata is local to this exact
639
+ node: it is not inherited by nodes derived from it (through operators,
640
+ attribute access, method calls, ``.rx.pipe``, indexing, etc.), and it is
641
+ not shared with mirrors created by branching (``expr[0]``, ``expr[1]``).
642
+ Each node starts with its own empty mapping.
643
+
644
+ Metadata takes no part in a node's identity or evaluation: mutating it
645
+ does not dirty the node, notify watchers, or otherwise affect
646
+ computation. It exists purely as a place for a library built on ``rx``
647
+ to attach state to a specific node, such as a provenance record or a
648
+ cache key.
649
+
650
+ Returns
651
+ -------
652
+ dict
653
+ The mutable metadata mapping for this node.
654
+
655
+ Examples
656
+ --------
657
+ >>> import param
658
+ >>> a = param.rx(1)
659
+ >>> a.rx.meta['trace'] = 'created at step 1'
660
+ >>> b = a + 1
661
+ >>> 'trace' in b.rx.meta
662
+ False
663
+ """
664
+ rxi = self._reactive
665
+ if not isinstance(rxi, rx):
666
+ raise AttributeError(
667
+ "'.rx.meta' is only available on `rx` nodes, not on "
668
+ f"the `.rx` namespace of a {type(rxi).__name__!r} object."
669
+ )
670
+ if rxi._meta is None:
671
+ rxi._meta = {}
672
+ return rxi._meta
673
+
598
674
  def not_(self) -> 'rx':
599
675
  """
600
676
  Perform a logical NOT operation on the current reactive value.
@@ -668,7 +744,7 @@ class reactive_ops:
668
744
  """
669
745
  return self._as_rx()._apply_operator(lambda obj, other: obj or other, other)
670
746
 
671
- def pipe(self, func, /, *args, **kwargs)-> 'rx':
747
+ def pipe(self, func, /, *args, process_failures=False, **kwargs)-> 'rx':
672
748
  """
673
749
  Apply a chainable function to the current reactive value.
674
750
 
@@ -716,7 +792,9 @@ class reactive_ops:
716
792
  >>> rx_result.rx.value
717
793
  30
718
794
  """
719
- return self._as_rx()._apply_operator(func, *args, **kwargs)
795
+ return self._as_rx()._apply_operator(
796
+ func, *args, process_failures=process_failures, **kwargs
797
+ )
720
798
 
721
799
  def resolve(self, nested=True, recursive=False) -> 'rx':
722
800
  """
@@ -763,6 +841,67 @@ class reactive_ops:
763
841
  resolver = resolver_type(object=self._reactive, recursive=recursive)
764
842
  return resolver.param.value.rx()
765
843
 
844
+ @property
845
+ def awaiting(self) -> builtins.bool:
846
+ """
847
+ Whether any asynchronous operation in this expression is still resolving.
848
+
849
+ ``True`` from the moment an asynchronous operation is scheduled until it
850
+ produces a value for the current inputs. While a node is awaiting, the
851
+ expression still holds the value it computed from the previous inputs,
852
+ so ``.rx.value`` reports :obj:`param.Undefined` rather than that stale
853
+ value; ``awaiting`` distinguishes "not resolved yet" from an operation
854
+ that deliberately skipped.
855
+
856
+ The whole graph feeding the expression is considered, not just the node
857
+ it is accessed on, so a synchronous operation downstream of an
858
+ asynchronous one reports ``True`` while its input resolves.
859
+
860
+ Reading this does not itself schedule anything, so an expression whose
861
+ value has never been requested reports ``False`` until something asks
862
+ for it.
863
+
864
+ Both routes an asynchronous callable can take are tracked: one applied
865
+ as an operation, e.g. passed to ``.rx.pipe``, and one passed to ``rx``
866
+ as the object itself, which is held on a parameter and resolved by the
867
+ reference machinery. A generator settles on each value it yields, so it
868
+ reports ``True`` only until its next value arrives rather than until it
869
+ is exhausted. Accessed on a parameter rather than an expression this is
870
+ always ``False``.
871
+
872
+ Returns
873
+ -------
874
+ bool
875
+ ``True`` while an asynchronous operation has not yet produced a
876
+ value for the current inputs, ``False`` otherwise.
877
+
878
+ Examples
879
+ --------
880
+ Pipe through a coroutine function and observe the expression settle:
881
+
882
+ >>> import asyncio, param
883
+ >>> async def double(value):
884
+ ... await asyncio.sleep(0.1)
885
+ ... return value * 2
886
+ >>> expr = param.rx(1).rx.pipe(double) + 1
887
+
888
+ Requesting the value schedules the operation:
889
+
890
+ >>> expr.rx.value is param.Undefined
891
+ True
892
+ >>> expr.rx.awaiting
893
+ True
894
+
895
+ Once the coroutine has resolved the expression reports a value again:
896
+
897
+ >>> expr.rx.awaiting # doctest: +SKIP
898
+ False
899
+ """
900
+ reactive = self._reactive
901
+ if not isinstance(reactive, rx):
902
+ return False
903
+ return any(node._settling for node in reactive._upstream())
904
+
766
905
  def updating(self) -> 'rx':
767
906
  """
768
907
  Return a new expression that indicates whether the current expression is updating.
@@ -1450,6 +1589,9 @@ class rx:
1450
1589
  obj : any
1451
1590
  The object to wrap, such as a number, string, list, or any supported
1452
1591
  data structure.
1592
+ error_mode : {"raise", "propagate"}, default "raise"
1593
+ Whether exceptions raised while evaluating the expression should be
1594
+ re-raised or represented as :class:`ReactiveError` values.
1453
1595
 
1454
1596
  References
1455
1597
  ----------
@@ -1499,6 +1641,12 @@ class rx:
1499
1641
  """
1500
1642
  Register an accessor that extends ``rx`` with custom behavior.
1501
1643
 
1644
+ Accessors are instantiated lazily the first time it is accessed on a given
1645
+ node. If a ``predicate`` is provided it is evaluated against the node's
1646
+ current value at that point in time. If it does not evaluate as true the first
1647
+ time, e.g. because the value has not yet settled, it may still be created on
1648
+ subsequent accesses.
1649
+
1502
1650
  Parameters
1503
1651
  ----------
1504
1652
  name: str
@@ -1507,6 +1655,9 @@ class rx:
1507
1655
  A callable that will return the accessor namespace object
1508
1656
  given the ``rx`` object it is registered on.
1509
1657
  predicate: Callable[[Any], bool] | None
1658
+ Called with the node's current value the first time ``name`` is
1659
+ accessed on that node; the accessor is only instantiated if a
1660
+ callable returns True or if ``predicate`` is None.
1510
1661
 
1511
1662
  """
1512
1663
  cls._accessors[name] = (accessor, predicate)
@@ -1575,7 +1726,8 @@ class rx:
1575
1726
 
1576
1727
  def __init__(
1577
1728
  self, obj=None, operation=None, fn=None, depth=0, method=None, prev=None, lazy=False,
1578
- _shared_obj=None, _current=None, _wrapper=None, _shared=None, **kwargs
1729
+ _shared_obj=None, _current=None, _wrapper=None, _shared=None, error_mode='raise',
1730
+ **kwargs
1579
1731
  ):
1580
1732
  # _init is used to prevent to __getattribute__ to execute its
1581
1733
  # specialized code.
@@ -1600,7 +1752,11 @@ class rx:
1600
1752
  self._finished_generation = 0
1601
1753
  self._skipped = False
1602
1754
  self._error_state = None
1755
+ self._error_mode = error_mode
1756
+ if error_mode not in ('raise', 'propagate'):
1757
+ raise ValueError("error_mode must be either 'raise' or 'propagate'")
1603
1758
  self._current_ = _current
1759
+ self._meta: dict[t.Any, t.Any] | None = None # Do not allocate unless needed
1604
1760
  # _shared is used for branching rx pipelines where we clone the input.
1605
1761
  # Here we store the original shared input, which makes it possible to
1606
1762
  # cache the input value as long as the shared instance does not store
@@ -1615,8 +1771,8 @@ class rx:
1615
1771
  self._trigger: Trigger | None
1616
1772
  if operation and (iscoroutinefunction(operation['fn']) or inspect.isgeneratorfunction(operation['fn'])):
1617
1773
  self._trigger = Trigger(internal=True)
1618
- self._current_ = Undefined
1619
- self._dirty = True # Otherwise current will be stuck as Undefined.
1774
+ self._current_ = Undefined
1775
+ self._dirty = True # Otherwise current will be stuck as Undefined.
1620
1776
  else:
1621
1777
  self._trigger = None
1622
1778
  self._root = self._compute_root()
@@ -1637,9 +1793,6 @@ class rx:
1637
1793
  self._init = True
1638
1794
  for name, accessor in _display_accessors.items():
1639
1795
  setattr(self, name, t.cast('Callable', accessor)(self))
1640
- for name, (accessor, predicate) in rx._accessors.items():
1641
- if predicate is None or predicate(self._current):
1642
- setattr(self, name, accessor(self))
1643
1796
 
1644
1797
  @property
1645
1798
  def rx(self) -> reactive_ops:
@@ -1708,9 +1861,64 @@ class rx:
1708
1861
  """
1709
1862
  Whether an asynchronous resolution is in flight that has not yet
1710
1863
  produced a value for the current generation.
1864
+
1865
+ While a node is awaiting, the cached ``_current_`` value was computed
1866
+ from inputs that have since been superseded, so resolving the node
1867
+ skips instead of reporting the stale value as if it were current.
1711
1868
  """
1712
1869
  return self._resolve_generation != self._finished_generation
1713
1870
 
1871
+ @property
1872
+ def _awaiting_ref(self) -> bool:
1873
+ """
1874
+ Whether an asynchronous reference feeding this node has not yet
1875
+ produced a value for the current inputs.
1876
+
1877
+ A coroutine or generator function passed to ``rx`` as the object rather
1878
+ than as an operation is held on a parameter and resolved by the
1879
+ reference machinery, so its settlement is tracked there instead of by
1880
+ this node's own generations.
1881
+ """
1882
+ for p in self._internal_params:
1883
+ owner, name = p.owner, p.name
1884
+ if name is None or not isinstance(owner, Parameterized):
1885
+ continue
1886
+ if owner.param._awaiting_ref(name):
1887
+ return True
1888
+ return False
1889
+
1890
+ @property
1891
+ def _settling(self) -> bool:
1892
+ """Whether this node is waiting on an asynchronous result of its own."""
1893
+ return self._awaiting or self._awaiting_ref
1894
+
1895
+ def _upstream(self) -> Iterator[t.Any]:
1896
+ """
1897
+ Yield this node and every ``rx`` node it derives its value from.
1898
+
1899
+ Inputs reach a node by three routes, all of which have to be visited
1900
+ because an operation is only as settled as the nodes feeding it: the
1901
+ ``_prev`` chain of the pipeline the node belongs to, the ``_shared``
1902
+ input it was cloned from when a pipeline branches, and any ``rx``
1903
+ passed as an argument to one of its operations.
1904
+ """
1905
+ seen: set[int] = set()
1906
+ stack: list[rx] = [self]
1907
+ while stack:
1908
+ node = stack.pop()
1909
+ if (id_node := id(node)) in seen:
1910
+ continue
1911
+ seen.add(id_node)
1912
+ yield node
1913
+ for inp in (node._prev, node._shared):
1914
+ if isinstance(inp, rx):
1915
+ stack.append(inp)
1916
+ operation = node._operation
1917
+ if operation:
1918
+ stack.extend(_iter_rx((
1919
+ operation['fn'], operation.get('args', ()), operation.get('kwargs', {})
1920
+ )))
1921
+
1714
1922
  @property
1715
1923
  def _current(self):
1716
1924
  if self._error_state:
@@ -1855,6 +2063,7 @@ class rx:
1855
2063
  if stale():
1856
2064
  return
1857
2065
  self._current_ = shared.rx.value
2066
+ self._skipped = False
1858
2067
  self._finished_generation = generation
1859
2068
  trigger.param.trigger('value')
1860
2069
  elif inspect.isasyncgen(obj):
@@ -1863,6 +2072,7 @@ class rx:
1863
2072
  await _close_stale(obj)
1864
2073
  break
1865
2074
  self._current_ = val
2075
+ self._skipped = False
1866
2076
  self._finished_generation = generation
1867
2077
  trigger.param.trigger('value')
1868
2078
  else:
@@ -1870,6 +2080,7 @@ class rx:
1870
2080
  if stale():
1871
2081
  return
1872
2082
  self._current_ = value
2083
+ self._skipped = False
1873
2084
  self._finished_generation = generation
1874
2085
  trigger.param.trigger('value')
1875
2086
  except asyncio.CancelledError:
@@ -1906,6 +2117,12 @@ class rx:
1906
2117
  elif self._dirty or self._root._dirty_obj:
1907
2118
  try:
1908
2119
  obj = self._obj if self._prev is None else self._prev._resolve()
2120
+ operation = self._operation
2121
+ if isinstance(obj, ReactiveError) and not (operation or {}).get('process_failures'):
2122
+ self._current_ = obj
2123
+ self._skipped = False
2124
+ self._dirty = False
2125
+ return obj
1909
2126
  if obj is Skip or obj is Undefined:
1910
2127
  self._current_ = Undefined
1911
2128
  raise Skip
@@ -1940,11 +2157,16 @@ class rx:
1940
2157
  self._finished_generation = self._resolve_generation
1941
2158
  self._dirty = False
1942
2159
  return self._current_
1943
- operation = self._operation
1944
2160
  if operation:
1945
2161
  obj = self._eval_operation(obj, operation)
1946
2162
  if self._is_async:
1947
2163
  self._lazy_resolve(obj)
2164
+ if self._finished_generation == self._resolve_generation:
2165
+ # Handle case where async call is resolved synchronously
2166
+ # e.g. when there is no running event loop
2167
+ self._skipped = False
2168
+ self._dirty = False
2169
+ return self._current_
1948
2170
  obj = Skip
1949
2171
  if obj is Skip:
1950
2172
  raise Skip
@@ -1953,6 +2175,11 @@ class rx:
1953
2175
  self._skipped = True
1954
2176
  return self._current_
1955
2177
  except Exception as e:
2178
+ if self._error_mode == 'propagate':
2179
+ self._current_ = ReactiveError(e, self)
2180
+ self._dirty = False
2181
+ self._skipped = False
2182
+ return self._current_
1956
2183
  self._error_state = e
1957
2184
  raise e
1958
2185
  self._current_ = current = obj
@@ -1961,8 +2188,9 @@ class rx:
1961
2188
  current = self._current_
1962
2189
  # A node awaiting an asynchronous result still holds the value it
1963
2190
  # computed from the previous inputs; report it as skipped so it is
1964
- # not propagated as if it were current.
1965
- self._skipped = self._awaiting
2191
+ # not propagated as if it were current. Preserve an explicit skip
2192
+ # across rereads so a second watcher cannot publish that value.
2193
+ self._skipped = self._skipped or self._awaiting
1966
2194
  self._dirty = False
1967
2195
  if self._method:
1968
2196
  # E.g. `pi = dfi.A` leads to `pi._method` equal to `'A'`.
@@ -2005,28 +2233,39 @@ class rx:
2005
2233
  operation = operation or self._operation
2006
2234
  depth = self._depth + 1
2007
2235
  if copy:
2236
+ # Do not trigger resolve via self._current since result is discarded
2237
+ # by the cloned nodes constructor anyway
2238
+ current = self._current_ if self._is_async else self._current
2008
2239
  kwargs = dict(
2009
- self._kwargs, _current=self._current, method=self._method,
2240
+ self._kwargs, _current=current, method=self._method,
2010
2241
  prev=self._prev, _shared=self, **kwargs
2011
2242
  )
2012
2243
  else:
2013
2244
  kwargs = dict(prev=self, **dict(self._kwargs, **kwargs))
2014
2245
  kwargs = dict(self._display_opts, **kwargs)
2246
+ error_mode = t.cast('str', kwargs.pop('error_mode', self._error_mode))
2015
2247
  return type(self)(
2016
2248
  self._obj, operation=operation, depth=depth, fn=self._fn, lazy=self._lazy,
2017
2249
  _shared_obj=self._shared_obj, _wrapper=self._wrapper,
2250
+ error_mode=error_mode,
2018
2251
  **kwargs
2019
2252
  )
2020
2253
 
2021
2254
  def __dir__(self):
2022
- current = self._current
2255
+ resolved = self._current
2256
+ current = resolved
2023
2257
  if self._method:
2024
2258
  current = getattr(current, self._method)
2025
2259
  extras = {attr for attr in dir(current) if not attr.startswith('_')}
2260
+ # Explicitly list registered but uninstantiated accessors
2261
+ accessor_names = {
2262
+ name for name, (_, predicate) in rx._accessors.items()
2263
+ if name not in self.__dict__ and (predicate is None or predicate(resolved))
2264
+ }
2026
2265
  try:
2027
- return sorted(set(super().__dir__()) | extras)
2266
+ return sorted(set(super().__dir__()) | extras | accessor_names)
2028
2267
  except Exception:
2029
- return sorted(set(dir(type(self))) | set(self.__dict__) | extras)
2268
+ return sorted(set(dir(type(self))) | set(self.__dict__) | extras | accessor_names)
2030
2269
 
2031
2270
  def _resolve_accessor(self) -> Self:
2032
2271
  if not self._method:
@@ -2064,6 +2303,14 @@ class rx:
2064
2303
  self._resolve()
2065
2304
  current = self_dict['_current_']
2066
2305
 
2306
+ # Capture uninstantiated accessor access
2307
+ if name in rx._accessors and name not in self_dict:
2308
+ accessor, predicate = rx._accessors[name]
2309
+ if predicate is None or predicate(current):
2310
+ value = accessor(self)
2311
+ setattr(self, name, value)
2312
+ return value
2313
+
2067
2314
  method = self_dict['_method']
2068
2315
  if method:
2069
2316
  current = getattr(current, method)
@@ -2116,7 +2363,8 @@ class rx:
2116
2363
  return new._clone(operation)
2117
2364
 
2118
2365
  def _apply_operator(
2119
- self, operator: Callable, *args, reverse: bool = False, **kwargs
2366
+ self, operator: Callable, *args, reverse: bool = False, process_failures=False,
2367
+ **kwargs
2120
2368
  ) -> Self:
2121
2369
  new = self._resolve_accessor()
2122
2370
  operation = {
@@ -2125,6 +2373,7 @@ class rx:
2125
2373
  'kwargs': kwargs,
2126
2374
  'reverse': reverse
2127
2375
  }
2376
+ operation['process_failures'] = process_failures
2128
2377
  return new._clone(operation)
2129
2378
 
2130
2379
  # Builtin functions
@@ -2269,13 +2518,21 @@ class rx:
2269
2518
  fn, args, kwargs = operation['fn'], operation['args'], operation['kwargs']
2270
2519
  resolved_args = []
2271
2520
  for arg in args:
2521
+ if any(ref._settling for ref in _iter_rx(arg)):
2522
+ raise Skip
2272
2523
  val = resolve_value(arg)
2524
+ if isinstance(val, ReactiveError) and not operation.get('process_failures'):
2525
+ return val
2273
2526
  if val is Skip or val is Undefined:
2274
2527
  raise Skip
2275
2528
  resolved_args.append(val)
2276
2529
  resolved_kwargs = {}
2277
2530
  for k, arg in kwargs.items():
2531
+ if any(ref._settling for ref in _iter_rx(arg)):
2532
+ raise Skip
2278
2533
  val = resolve_value(arg)
2534
+ if isinstance(val, ReactiveError) and not operation.get('process_failures'):
2535
+ return val
2279
2536
  if val is Skip or val is Undefined:
2280
2537
  raise Skip
2281
2538
  resolved_kwargs[k] = val
@@ -2299,6 +2556,27 @@ class rx:
2299
2556
  super().__setattr__(name, value)
2300
2557
 
2301
2558
 
2559
+ def _iter_rx(value: t.Any) -> Iterator[rx]:
2560
+ """
2561
+ Yield the reactive expressions nested anywhere inside a reference.
2562
+
2563
+ Mirrors the containers ``resolve_value`` descends into, so an ``rx`` used
2564
+ as an operation argument is found wherever ``resolve_value`` would find it.
2565
+ """
2566
+ if isinstance(value, rx):
2567
+ yield value
2568
+ elif isinstance(value, (list, tuple, set)):
2569
+ for v in value:
2570
+ yield from _iter_rx(v)
2571
+ elif isinstance(value, dict):
2572
+ for k, v in value.items():
2573
+ yield from _iter_rx(k)
2574
+ yield from _iter_rx(v)
2575
+ elif isinstance(value, slice):
2576
+ for v in (value.start, value.stop, value.step):
2577
+ yield from _iter_rx(v)
2578
+
2579
+
2302
2580
  def _rx_transform(obj):
2303
2581
  if not isinstance(obj, rx):
2304
2582
  return obj
@@ -28,6 +28,7 @@ classifiers = [
28
28
  "Programming Language :: Python :: 3.12",
29
29
  "Programming Language :: Python :: 3.13",
30
30
  "Programming Language :: Python :: 3.14",
31
+ "Programming Language :: Python :: 3.15",
31
32
  "Topic :: Scientific/Engineering",
32
33
  "Topic :: Software Development :: Libraries",
33
34
  "Typing :: Typed"