Skip to content

Commit

Permalink
python attribute comments inside __init__
Browse files Browse the repository at this point in the history
  • Loading branch information
mgonzs13 committed Nov 3, 2024
1 parent 7965e31 commit 216bc1a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
5 changes: 2 additions & 3 deletions yasmin/yasmin/blackboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ class Blackboard(object):
__repr__(): Return a string representation of the blackboard's data.
"""

## A threading lock to ensure thread-safe access to the _data attribute.
__lock: Lock = Lock()

def __init__(self, init: Dict[str, Any] = None) -> None:
"""
Initializes the Blackboard with an optional initial dictionary.
Expand All @@ -54,6 +51,8 @@ def __init__(self, init: Dict[str, Any] = None) -> None:
None
"""

## A threading lock to ensure thread-safe access to the _data attribute.
self.__lock: Lock = Lock()
## A dictionary holding the data stored in the blackboard.
self._data: Dict[str, Any] = {}

Expand Down
4 changes: 2 additions & 2 deletions yasmin/yasmin/cb_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class CbState(State):
cb (Callable): A callable that will be invoked when the state is executed.
"""

_cb: Callable ##< A callable that will be invoked when the state is executed.

def __init__(self, outcomes: Set[str], cb: Callable) -> None:
"""
Initializes a new instance of CbState.
Expand All @@ -48,6 +46,8 @@ def __init__(self, outcomes: Set[str], cb: Callable) -> None:
TypeError: If 'outcomes' is not a set or 'cb' is not callable.
"""
super().__init__(outcomes)

## A callable that will be invoked when the state is executed.
self._cb: Callable = cb

def execute(self, blackboard: Blackboard) -> str:
Expand Down
12 changes: 5 additions & 7 deletions yasmin/yasmin/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ class State(ABC):
_canceled (bool): A flag indicating whether the state has been canceled.
"""

## A set of valid outcomes for this state.
_outcomes: Set
## A flag indicating whether the state is currently running.
_running: bool = False
## A flag indicating whether the state has been canceled.
_canceled: bool = False

def __init__(self, outcomes: Set[str]) -> None:
"""
Initializes the State instance.
Expand All @@ -49,7 +42,12 @@ def __init__(self, outcomes: Set[str]) -> None:
:raises ValueError: If the provided outcomes set is empty.
"""

## A set of valid outcomes for this state.
self._outcomes: Set = set()
## A flag indicating whether the state is currently running.
self._running: bool = False
## A flag indicating whether the state has been canceled.
self._canceled: bool = False

if outcomes:
self._outcomes.update(outcomes)
Expand Down
38 changes: 19 additions & 19 deletions yasmin/yasmin/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,6 @@ class StateMachine(State):
__end_cbs (List[Tuple[Callable[[Blackboard, str, List[Any]], None], List[Any]]]): A list of callbacks to call when the state machine ends.
"""

## A dictionary mapping state names to their corresponding state objects and transitions.
_states: Dict[str, Dict[str, Any]]
## The name of the initial state of the state machine.
_start_state: str = None
## The name of the current state being executed.
__current_state: str = None
## A threading lock to manage access to the current state.
__current_state_lock: Lock = Lock()
## A list of callbacks to call when the state machine starts.
__start_cbs: List[
Tuple[Callable[[Blackboard, str, List[Any]], None], List[Any]]
] = []
## A list of callbacks to call during state transitions.
__transition_cbs: List[
Tuple[Callable[[Blackboard, str, List[Any]], None], List[Any]]
] = []
## A list of callbacks to call when the state machine ends.
__end_cbs: List[Tuple[Callable[[Blackboard, str, List[Any]], None], List[Any]]] = []

def __init__(self, outcomes: Set[str]) -> None:
"""
Initializes the StateMachine with a set of possible outcomes.
Expand All @@ -65,7 +46,26 @@ def __init__(self, outcomes: Set[str]) -> None:
"""
super().__init__(outcomes)

## A dictionary mapping state names to their corresponding state objects and transitions.
self._states: Dict[str, Dict[str, Any]] = {}
## The name of the initial state of the state machine.
self._start_state: str = None
## The name of the current state being executed.
self.__current_state: str = None
## A threading lock to manage access to the current state.
self.__current_state_lock: Lock = Lock()
## A list of callbacks to call when the state machine starts.
self.__start_cbs: List[
Tuple[Callable[[Blackboard, str, List[Any]], None], List[Any]]
] = []
## A list of callbacks to call during state transitions.
self.__transition_cbs: List[
Tuple[Callable[[Blackboard, str, List[Any]], None], List[Any]]
] = []
## A list of callbacks to call when the state machine ends.
self.__end_cbs: List[
Tuple[Callable[[Blackboard, str, List[Any]], None], List[Any]]
] = []

def add_state(
self,
Expand Down

0 comments on commit 216bc1a

Please sign in to comment.