Skip to content

Commit

Permalink
DEV : Replace static change handlers with observe decorated methods (#…
Browse files Browse the repository at this point in the history
…372)

This commit replaces static trait change handlers (_trait_name_changed)
with methods decorated with observe.

	modified:   traits_futures/base_future.py
	modified:   traits_futures/traits_executor.py
  • Loading branch information
Poruri Sai Rahul committed Jul 6, 2021
1 parent 973aa43 commit d7b2e4d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion traits_futures/base_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Callable,
Enum,
HasStrictTraits,
observe,
Property,
provides,
Str,
Expand Down Expand Up @@ -377,8 +378,11 @@ def _get_done(self):
"""Property getter for the "done" trait."""
return self._internal_state in _DONE_INTERNAL_STATES

def __internal_state_changed(self, old_internal_state, new_internal_state):
@observe("_internal_state")
def _update_property_traits(self, event):
"""Trait change handler for the "_internal_state" trait."""
old_internal_state, new_internal_state = event.old, event.new

old_state = _INTERNAL_STATE_TO_STATE[old_internal_state]
new_state = _INTERNAL_STATE_TO_STATE[new_internal_state]
if old_state != new_state:
Expand Down
5 changes: 4 additions & 1 deletion traits_futures/traits_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,11 @@ def _get_stopped(self):
"""Property getter for the "stopped" trait."""
return self._internal_state in _STOPPED_INTERNAL_STATES

def __internal_state_changed(self, old_internal_state, new_internal_state):
@observe("_internal_state")
def _update_property_traits(self, event):
"""Trait change handler for the "_internal_state" trait."""
old_internal_state, new_internal_state = event.old, event.new

logger.debug(
f"{self} internal state changed "
f"from {old_internal_state} to {new_internal_state}"
Expand Down

0 comments on commit d7b2e4d

Please sign in to comment.