diff --git a/lisa/fuzz.py b/lisa/fuzz.py index 4f91b61d8c5e7f670291fa874f185e6f4bc098a9..aebbb3fd1dabc41d4b692e60ae3a8296f190bc65 100644 --- a/lisa/fuzz.py +++ b/lisa/fuzz.py @@ -153,7 +153,7 @@ class Gen(StateMonad, Loggable): self.logger.log(log_level, f'Drawn {val}{trials}from {self}{info}') return x - self.name = name + self.name = name or f.__qualname__ super().__init__(wrapper) class _STATE: diff --git a/lisa/monad.py b/lisa/monad.py index 6e66ee11c7fc883ba7020399ce735aebb3ee8c0f..22ef07e29eb376f263de8b53a58d4c66f0349afb 100644 --- a/lisa/monad.py +++ b/lisa/monad.py @@ -66,8 +66,8 @@ class StateMonad(abc.ABC): """ The state monad. - :param f: Callable that takes the state as parameter and returns an - instance of the monad. + :param f: Callable that takes the state as parameter and returns a tuple + ``(value, new_state)``. :type f: collections.abc.Callable """ @@ -86,10 +86,16 @@ class StateMonad(abc.ABC): return (yield self) def __call__(self, *args, **kwargs): - state = self.make_state(*args, **kwargs) - x, _ = self._f(state) + x, _ = self.run(*args, **kwargs) return x + def run(self, *args, **kwargs): + """ + Run the state monad and return a tuple of ``(value, state)``. + """ + state = self.make_state(*args, **kwargs) + return self._f(state) + def __init_subclass__(cls, **kwargs): # The one inheriting directly from StateMonad is the base of the # hierarchy @@ -137,6 +143,7 @@ class StateMonad(abc.ABC): call = lambda: _f(*args, **kwargs) x = call() if inspect.iscoroutine(x): + @functools.wraps(f) def body(state): if inspect.getcoroutinestate(x) == inspect.CORO_CLOSED: _x = call() @@ -167,7 +174,7 @@ class StateMonad(abc.ABC): else: return (val, state) - val = cls.from_f(body, name=f.__qualname__) + val = cls.from_f(body) else: if isinstance(x, cls): val = x diff --git a/lisa/wlgen/rta.py b/lisa/wlgen/rta.py index 0d1dcb6cffdef9fa4e08bafff8a2fdf68dbd26c5..0dda684690aa7fa920bd0b96aa43bfdadfaa7103 100644 --- a/lisa/wlgen/rta.py +++ b/lisa/wlgen/rta.py @@ -1606,8 +1606,8 @@ def leaf_precedence(val, **kwargs): """ Give precedence to the leaf values when combining with ``&``:: - phase = phase.with_props(prop_meta=({'hello': 'leaf'}) - phase = phase.with_props(prop_meta=leaf_precedence({'hello': 'root'}) + phase = phase.with_props(meta=({'hello': 'leaf'}) + phase = phase.with_props(meta=leaf_precedence({'hello': 'root'}) assert phase['meta'] == {'hello': 'leaf'} This allows setting a property with some kind of default value on a root @@ -1633,7 +1633,7 @@ def override(val, **kwargs): Override a property with the given value, rather than combining it with the property-specific ``&`` implementation:: - phase = phase.with_props(prop_cpus=override({1,2})) + phase = phase.with_props(cpus=override({1,2})) """ return _OverridingValue(val, **kwargs) @@ -1687,7 +1687,7 @@ def delete(): """ Remove the given property from the phase:: - phase = phase.with_props(prop_cpus=delete()) + phase = phase.with_props(cpus=delete()) """ return _DeletingValue()