From ee55f61c81e0849b8e3667a1e4162f93f2e24d4e Mon Sep 17 00:00:00 2001 From: maximlt Date: Fri, 14 Feb 2025 01:19:14 +0100 Subject: [PATCH] raise AttributeError when attempting to set value on an rx obj --- param/reactive.py | 5 +++++ tests/testreactive.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/param/reactive.py b/param/reactive.py index cc22c1597..ba7731e06 100644 --- a/param/reactive.py +++ b/param/reactive.py @@ -1961,6 +1961,11 @@ def _eval_operation(self, obj, operation): obj = fn(obj, *resolved_args, **resolved_kwargs) return obj + def __setattr__(self, name, value): + if name == "value": + raise AttributeError("'rx' has no attribute 'value', try '.rx.value = '.") + super().__setattr__(name, value) + def _rx_transform(obj): if not isinstance(obj, rx): diff --git a/tests/testreactive.py b/tests/testreactive.py index c4fff0f16..77f1e6415 100644 --- a/tests/testreactive.py +++ b/tests/testreactive.py @@ -767,3 +767,8 @@ def test_reactive_callback_resolve_accessor(): dfx = rx(df) out = dfx["name"].str._callback() assert out is df["name"].str + +def test_reactive_set_value_attributeerror(): + x = rx(1) + with pytest.raises(AttributeError, match="'rx' has no attribute 'value'"): + x.value = 1