Source code for petab_select.handlers

from collections.abc import Callable

# `float` for `np.inf`
TYPE_LIMIT = float | int


# TODO exclusions handler


[docs] class LimitHandler: """A handler for classes that have a limit. Attributes: current: A callable to determine the current value. limit: The upper limit of the current value. """
[docs] def __init__( self, current: Callable[[], bool], limit: TYPE_LIMIT, ): self.current = current self.limit = limit
[docs] def reached(self) -> bool: """Check whether the limit has been reached.""" if self.current() >= self.limit: return True return False
[docs] def set_limit(self, limit: TYPE_LIMIT) -> None: """Set the limit. Args: limit: The limit. """ self.limit = limit
[docs] def get_limit(self) -> TYPE_LIMIT: """Get the limit. Returns: The limit. """ return self.limit