param 2.5.0b3__tar.gz → 2.5.0b4__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.5.0b3 → param-2.5.0b4}/PKG-INFO +1 -1
  2. {param-2.5.0b3 → param-2.5.0b4}/param/_version.py +2 -2
  3. {param-2.5.0b3 → param-2.5.0b4}/param/parameterized.py +95 -14
  4. {param-2.5.0b3 → param-2.5.0b4}/param/reactive.py +298 -81
  5. {param-2.5.0b3 → param-2.5.0b4}/tests/testreactive.py +598 -11
  6. {param-2.5.0b3 → param-2.5.0b4}/tests/testrefs.py +173 -0
  7. {param-2.5.0b3 → param-2.5.0b4}/.gitignore +0 -0
  8. {param-2.5.0b3 → param-2.5.0b4}/LICENSE.txt +0 -0
  9. {param-2.5.0b3 → param-2.5.0b4}/README.md +0 -0
  10. {param-2.5.0b3 → param-2.5.0b4}/numbergen/__init__.py +0 -0
  11. {param-2.5.0b3 → param-2.5.0b4}/param/__init__.py +0 -0
  12. {param-2.5.0b3 → param-2.5.0b4}/param/_utils.py +0 -0
  13. {param-2.5.0b3 → param-2.5.0b4}/param/depends.py +0 -0
  14. {param-2.5.0b3 → param-2.5.0b4}/param/display.py +0 -0
  15. {param-2.5.0b3 → param-2.5.0b4}/param/ipython.py +0 -0
  16. {param-2.5.0b3 → param-2.5.0b4}/param/mypy_plugin.py +0 -0
  17. {param-2.5.0b3 → param-2.5.0b4}/param/parameters.py +0 -0
  18. {param-2.5.0b3 → param-2.5.0b4}/param/py.typed +0 -0
  19. {param-2.5.0b3 → param-2.5.0b4}/param/serializer.py +0 -0
  20. {param-2.5.0b3 → param-2.5.0b4}/param/version.py +0 -0
  21. {param-2.5.0b3 → param-2.5.0b4}/pyproject.toml +0 -0
  22. {param-2.5.0b3 → param-2.5.0b4}/tests/__init__.py +0 -0
  23. {param-2.5.0b3 → param-2.5.0b4}/tests/assert_types.py +0 -0
  24. {param-2.5.0b3 → param-2.5.0b4}/tests/conftest.py +0 -0
  25. {param-2.5.0b3 → param-2.5.0b4}/tests/pyrightconfig-bare.json +0 -0
  26. {param-2.5.0b3 → param-2.5.0b4}/tests/testaddparameter.py +0 -0
  27. {param-2.5.0b3 → param-2.5.0b4}/tests/testbind.py +0 -0
  28. {param-2.5.0b3 → param-2.5.0b4}/tests/testbooleanparam.py +0 -0
  29. {param-2.5.0b3 → param-2.5.0b4}/tests/testbytesparam.py +0 -0
  30. {param-2.5.0b3 → param-2.5.0b4}/tests/testcalendardateparam.py +0 -0
  31. {param-2.5.0b3 → param-2.5.0b4}/tests/testcalendardaterangeparam.py +0 -0
  32. {param-2.5.0b3 → param-2.5.0b4}/tests/testcallable.py +0 -0
  33. {param-2.5.0b3 → param-2.5.0b4}/tests/testclassselector.py +0 -0
  34. {param-2.5.0b3 → param-2.5.0b4}/tests/testcolorparameter.py +0 -0
  35. {param-2.5.0b3 → param-2.5.0b4}/tests/testcomparator.py +0 -0
  36. {param-2.5.0b3 → param-2.5.0b4}/tests/testcompositeparams.py +0 -0
  37. {param-2.5.0b3 → param-2.5.0b4}/tests/testcustomparam.py +0 -0
  38. {param-2.5.0b3 → param-2.5.0b4}/tests/testdateparam.py +0 -0
  39. {param-2.5.0b3 → param-2.5.0b4}/tests/testdaterangeparam.py +0 -0
  40. {param-2.5.0b3 → param-2.5.0b4}/tests/testdefaultfactory.py +0 -0
  41. {param-2.5.0b3 → param-2.5.0b4}/tests/testdefaults.py +0 -0
  42. {param-2.5.0b3 → param-2.5.0b4}/tests/testdeprecations.py +0 -0
  43. {param-2.5.0b3 → param-2.5.0b4}/tests/testdynamicparams.py +0 -0
  44. {param-2.5.0b3 → param-2.5.0b4}/tests/testfiledeserialization.py +0 -0
  45. {param-2.5.0b3 → param-2.5.0b4}/tests/testfileselector.py +0 -0
  46. {param-2.5.0b3 → param-2.5.0b4}/tests/testimports.py +0 -0
  47. {param-2.5.0b3 → param-2.5.0b4}/tests/testipythonmagic.py +0 -0
  48. {param-2.5.0b3 → param-2.5.0b4}/tests/testjsonserialization.py +0 -0
  49. {param-2.5.0b3 → param-2.5.0b4}/tests/testlist.py +0 -0
  50. {param-2.5.0b3 → param-2.5.0b4}/tests/testlistselector.py +0 -0
  51. {param-2.5.0b3 → param-2.5.0b4}/tests/testmultifileselector.py +0 -0
  52. {param-2.5.0b3 → param-2.5.0b4}/tests/testnumbergen.py +0 -0
  53. {param-2.5.0b3 → param-2.5.0b4}/tests/testnumberparameter.py +0 -0
  54. {param-2.5.0b3 → param-2.5.0b4}/tests/testnumpy.py +0 -0
  55. {param-2.5.0b3 → param-2.5.0b4}/tests/testobjectselector.py +0 -0
  56. {param-2.5.0b3 → param-2.5.0b4}/tests/testpandas.py +0 -0
  57. {param-2.5.0b3 → param-2.5.0b4}/tests/testparamdepends.py +0 -0
  58. {param-2.5.0b3 → param-2.5.0b4}/tests/testparameter.py +0 -0
  59. {param-2.5.0b3 → param-2.5.0b4}/tests/testparameterizedobject.py +0 -0
  60. {param-2.5.0b3 → param-2.5.0b4}/tests/testparameterizedrepr.py +0 -0
  61. {param-2.5.0b3 → param-2.5.0b4}/tests/testparamoutput.py +0 -0
  62. {param-2.5.0b3 → param-2.5.0b4}/tests/testparamunion.py +0 -0
  63. {param-2.5.0b3 → param-2.5.0b4}/tests/testpathparam.py +0 -0
  64. {param-2.5.0b3 → param-2.5.0b4}/tests/testpickle.py +0 -0
  65. {param-2.5.0b3 → param-2.5.0b4}/tests/testrangeparameter.py +0 -0
  66. {param-2.5.0b3 → param-2.5.0b4}/tests/testreprhtml.py +0 -0
  67. {param-2.5.0b3 → param-2.5.0b4}/tests/testselector.py +0 -0
  68. {param-2.5.0b3 → param-2.5.0b4}/tests/testsignatures.py +0 -0
  69. {param-2.5.0b3 → param-2.5.0b4}/tests/teststringparam.py +0 -0
  70. {param-2.5.0b3 → param-2.5.0b4}/tests/testtimedependent.py +0 -0
  71. {param-2.5.0b3 → param-2.5.0b4}/tests/testtupleparam.py +0 -0
  72. {param-2.5.0b3 → param-2.5.0b4}/tests/testutils.py +0 -0
  73. {param-2.5.0b3 → param-2.5.0b4}/tests/testversion.py +0 -0
  74. {param-2.5.0b3 → param-2.5.0b4}/tests/testwatch.py +0 -0
  75. {param-2.5.0b3 → param-2.5.0b4}/tests/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: param
3
- Version: 2.5.0b3
3
+ Version: 2.5.0b4
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
@@ -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.0b3'
22
- __version_tuple__ = version_tuple = (2, 5, 0, 'b3')
21
+ __version__ = version = '2.5.0b4'
22
+ __version_tuple__ = version_tuple = (2, 5, 0, 'b4')
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -232,6 +232,38 @@ def _notify_weak_listeners(store: set | None, *args: t.Any) -> None:
232
232
  if callback is not None:
233
233
  callback(*args)
234
234
 
235
+ class _WeakInvalidator:
236
+ """
237
+ A weakly-bound invalidation callback for an ``rx`` pipeline node.
238
+
239
+ ``rx`` nodes register invalidation callbacks on their *source* parameters.
240
+ If those callbacks were strong bound-method references the source (which is
241
+ typically long-lived) would keep every derived node — and anything it
242
+ captured, such as large arrays — alive indefinitely. Wrapping the bound
243
+ method in a :class:`weakref.WeakMethod` lets the derived node be garbage
244
+ collected as soon as nothing else references it; once collected the call
245
+ becomes a no-op and the now-dead watcher is removed by a finalizer (see
246
+ ``rx._watch_invalidation``). Defined here rather than in ``reactive`` so
247
+ ``_call_watcher`` can recognize an unbatched invalidator without an import.
248
+ """
249
+
250
+ __slots__ = ('_ref', '_watcher', '_unbatched', '__weakref__')
251
+
252
+ _watcher: Watcher | None
253
+
254
+ def __init__(self, method, unbatched: bool = False):
255
+ self._ref = weakref.WeakMethod(method)
256
+ self._watcher = None
257
+ # Marking a node dirty is bookkeeping, not a notification; deferring it
258
+ # would let a read inside a batch, or a reference resolved while
259
+ # flushing one, see the value from before the write.
260
+ self._unbatched = unbatched
261
+
262
+ def __call__(self, *events):
263
+ method = self._ref()
264
+ if method is not None:
265
+ return method(*events)
266
+
235
267
  def _watch_ref_change(owner: 'Parameterized', name: str, callback: Callable[[], t.Any]) -> None:
236
268
  """Notify ``callback`` when a reference is replaced without a value change."""
237
269
  private = owner._param__private
@@ -303,8 +335,8 @@ def resolve_value(value: t.Any, recursive: bool = True) -> t.Any:
303
335
  resolve_value(value.step)
304
336
  )
305
337
  value = transform_reference(value)
306
- is_gen = inspect.isgeneratorfunction(value)
307
- if hasattr(value, '_dinfo') or iscoroutinefunction(value) or is_gen:
338
+ if hasattr(value, '_dinfo') or _is_async_fn(value):
339
+ is_gen = inspect.isgeneratorfunction(value)
308
340
  value = eval_function_with_deps(value)
309
341
  if is_gen:
310
342
  value = _to_async_gen(value)
@@ -312,6 +344,51 @@ def resolve_value(value: t.Any, recursive: bool = True) -> t.Any:
312
344
  value = getattr(value.owner, value.name)
313
345
  return value
314
346
 
347
+ def _is_async_fn(value: t.Any) -> bool:
348
+ """Whether value is a coroutine or generator function."""
349
+ return iscoroutinefunction(value) or inspect.isgeneratorfunction(value)
350
+
351
+ def _is_bare_async_ref(value: t.Any) -> bool:
352
+ """
353
+ Whether value is a coroutine or generator function that has not been
354
+ declared a reference with ``bind`` or ``depends``.
355
+ """
356
+ return not hasattr(value, '_dinfo') and _is_async_fn(value)
357
+
358
+ def _warn_bare_async_ref(value: t.Any, operand: bool = False) -> None:
359
+ """
360
+ Warn that rx will stop calling the bare coroutine or generator function
361
+ ``value``. ``operand`` marks an input to an rx operation, which is called
362
+ but whose result is never awaited or iterated.
363
+ """
364
+ if inspect.isasyncgenfunction(value):
365
+ kind = 'async generator'
366
+ elif inspect.isgeneratorfunction(value):
367
+ kind = 'generator'
368
+ else:
369
+ kind = 'coroutine'
370
+ func = value
371
+ while isinstance(func, partial):
372
+ func = func.func
373
+ name = getattr(func, '__name__', repr(func))
374
+ if operand:
375
+ result = 'coroutine' if kind == 'coroutine' else 'async generator'
376
+ message = (
377
+ f"Passing the {kind} function {name!r} as an input to a reactive "
378
+ f"operation is deprecated. It is currently called and the resulting "
379
+ f"{result} is passed on without being awaited or iterated; in a "
380
+ "future version the function itself will be passed on."
381
+ )
382
+ else:
383
+ bound = f"param.bind({name}, ...)" if func is not value else f"param.bind({name})"
384
+ message = (
385
+ f"Passing the {kind} function {name!r} to a reactive expression is "
386
+ "deprecated. In a future version rx will treat it like any other "
387
+ "function, i.e. keep it as a value instead of calling and resolving "
388
+ f"it. Wrap it with {bound} to keep resolving it."
389
+ )
390
+ warnings.warn(message, category=_ParamFutureWarning, stacklevel=_find_stack_level())
391
+
315
392
  def resolve_ref(reference: t.Any, recursive: bool = False) -> list[Parameter]:
316
393
  """Resolve all parameters a dynamic reference depends on."""
317
394
  if recursive:
@@ -456,7 +533,9 @@ def batch_call_watchers(parameterized):
456
533
 
457
534
  This context manager queues any events triggered by setting a parameter value
458
535
  on the supplied :class:`Parameterized` object, saving them up to dispatch
459
- them all at once when the context manager exits.
536
+ them all at once when the context manager exits. Only notifications are
537
+ deferred: an ``rx`` expression read inside the block already reflects the
538
+ writes made so far.
460
539
  """
461
540
  BATCH_WATCH = parameterized.param._BATCH_WATCH
462
541
  parameterized.param._BATCH_WATCH = True
@@ -612,7 +691,9 @@ def batch() -> Generator[None, None, None]:
612
691
  ``onlychanged``, say) is left uncoalesced rather than guessing which
613
692
  should win. Nesting is safe: only the outermost block flushes, and
614
693
  it composes with ``batch_call_watchers``/``.param.update()``/
615
- ``discard_events`` used inside it. If more than one watcher raises
694
+ ``discard_events`` used inside it. Only notifications are deferred:
695
+ an ``rx`` expression read inside the block already reflects the
696
+ writes made so far. If more than one watcher raises
616
697
  while flushing, the rest still run and the first exception is
617
698
  re-raised once the block has finished; if the block itself already
618
699
  raised, a later error while flushing is a warning instead.
@@ -747,7 +828,9 @@ def discard_events(parameterized: 'Parameterized') -> Generator[None, None, None
747
828
  on the supplied :class:`Parameterized` object during its scope are discarded.
748
829
  This allows for silent changes to dependent parameters, making it useful
749
830
  for initialization or setup phases where changes should not propagate
750
- to watchers or dependencies.
831
+ to watchers or dependencies. Only notifications are discarded: an ``rx``
832
+ expression depending on a changed parameter still reflects the new value
833
+ the next time it is read.
751
834
 
752
835
  Be cautious when using this context manager, as it bypasses the normal
753
836
  dependency mechanism. Manual changes made within this context may
@@ -2937,7 +3020,7 @@ class Parameters:
2937
3020
  # speculatively evaluate values to check whether they
2938
3021
  # contain a reference and warn the user that the
2939
3022
  # behavior may change in future.
2940
- if name not in self_.cls._param__private.explicit_no_refs:
3023
+ if name not in self_.cls._param__private.explicit_no_refs and not _is_bare_async_ref(val):
2941
3024
  resolved = val
2942
3025
  try:
2943
3026
  ref, _, resolved, _, _ = self_._resolve_ref(pobj, val)
@@ -3012,8 +3095,7 @@ class Parameters:
3012
3095
  # Skip updating value if dependency has not changed
3013
3096
  recursive = self_[pname].nested_refs
3014
3097
  deps = resolve_ref(ref, recursive)
3015
- is_gen = inspect.isgeneratorfunction(ref)
3016
- is_async = iscoroutinefunction(ref) or is_gen
3098
+ is_async = _is_async_fn(ref)
3017
3099
  if not any((dep.owner is e.obj and dep.name == e.name) for dep in deps for e in events) and not is_async:
3018
3100
  continue
3019
3101
 
@@ -3042,10 +3124,9 @@ class Parameters:
3042
3124
  _notify_async_ref_settle_change(self_.self, pname)
3043
3125
 
3044
3126
  def _resolve_ref(self_, pobj: Parameter, value: t.Any):
3045
- is_gen = inspect.isgeneratorfunction(value)
3046
- is_async = iscoroutinefunction(value) or is_gen
3127
+ is_async = _is_async_fn(value)
3047
3128
  deps = resolve_ref(value, recursive=pobj.nested_refs)
3048
- if not (deps or is_async or is_gen):
3129
+ if not (deps or is_async):
3049
3130
  return None, None, value, False, False
3050
3131
  ref = value
3051
3132
  try:
@@ -3102,8 +3183,7 @@ class Parameters:
3102
3183
  return False
3103
3184
  private = self_.self._param__private
3104
3185
  ref = private.refs.get(pname)
3105
- is_async = iscoroutinefunction(ref) or inspect.isgeneratorfunction(ref)
3106
- return is_async and private.async_ref_scheduled[pname] != private.async_ref_settled[pname]
3186
+ return _is_async_fn(ref) and private.async_ref_scheduled[pname] != private.async_ref_settled[pname]
3107
3187
 
3108
3188
  async def _async_ref(self_, pname: str, awaitable: t.Awaitable[t.Any], generation: int = 0):
3109
3189
  if self_.self is None:
@@ -3718,7 +3798,8 @@ class Parameters:
3718
3798
  elif watcher.onlychanged and (not self_._changed(event)):
3719
3799
  return
3720
3800
 
3721
- if _is_batched(self_.self_or_cls):
3801
+ fn = watcher.fn
3802
+ if not (isinstance(fn, _WeakInvalidator) and fn._unbatched) and _is_batched(self_.self_or_cls):
3722
3803
  self_._events.append(event)
3723
3804
  if not any(watcher is w for w in self_._state_watchers):
3724
3805
  self_._state_watchers.append(watcher)