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

Method __init__

src/py/reactpy/reactpy/_option.py:17–43  ·  view source on GitHub ↗
(
        self,
        name: str,
        default: _O = UNDEFINED,
        mutable: bool = True,
        parent: Option[_O] | None = None,
        validator: Callable[[Any], _O] = lambda x: cast(_O, x),
    )

Source from the content-addressed store, hash-verified

15 """An option that can be set using an environment variable of the same name"""
16
17 def __init__(
18 self,
19 name: str,
20 default: _O = UNDEFINED,
21 mutable: bool = True,
22 parent: Option[_O] | None = None,
23 validator: Callable[[Any], _O] = lambda x: cast(_O, x),
24 ) -> None:
25 self._name = name
26 self._mutable = mutable
27 self._validator = validator
28 self._subscribers: list[Callable[[_O], None]] = []
29
30 if name in os.environ:
31 self._current = validator(os.environ[name])
32
33 if parent is not None:
34 if not (parent.mutable and self.mutable):
35 raise TypeError("Parent and child options must be mutable")
36 self._default = parent.default
37 parent.subscribe(self.set_current)
38 elif default is not UNDEFINED:
39 self._default = default
40 else:
41 raise TypeError("Must specify either a default or a parent option")
42
43 logger.debug(f"{self._name}={self.current}")
44
45 @property
46 def name(self) -> str:

Callers 1

__init__Method · 0.45

Calls 1

subscribeMethod · 0.80

Tested by

no test coverage detected