MCPcopy Index your code
hub / github.com/reactive-python/reactpy / set_current

Method set_current

src/py/reactpy/reactpy/_option.py:88–109  ·  view source on GitHub ↗

Set the value of this option Raises a ``TypeError`` if this option is not :attr:`Option.mutable`.

(self, new: Any)

Source from the content-addressed store, hash-verified

86 return hasattr(self, "_current")
87
88 def set_current(self, new: Any) -> None:
89 """Set the value of this option
90
91 Raises a ``TypeError`` if this option is not :attr:`Option.mutable`.
92 """
93 old = self.current
94 if new is old:
95 return None
96
97 if not self._mutable:
98 msg = f"{self} cannot be modified after initial load"
99 raise TypeError(msg)
100
101 try:
102 new = self._current = self._validator(new)
103 except ValueError as error:
104 raise ValueError(f"Invalid value for {self._name}: {new!r}") from error
105
106 logger.debug(f"{self._name}={self._current}")
107 if new != old:
108 for sub_func in self._subscribers:
109 sub_func(new)
110
111 def set_default(self, new: _O) -> _O:
112 """Set the value of this option if not :meth:`Option.is_set`

Callers 3

currentMethod · 0.95
set_defaultMethod · 0.95
reloadMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected