forked from snaptec/openWB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
when storing anything in a
ValueStore
, log the value
- Loading branch information
Showing
6 changed files
with
47 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from typing import TypeVar | ||
|
||
T = TypeVar('T') | ||
|
||
|
||
def auto_str(cls: T) -> T: | ||
def __str__(self): | ||
return '%s(%s)' % ( | ||
type(self).__name__, | ||
', '.join('%s=%s' % item for item in vars(self).items()) | ||
) | ||
|
||
cls.__str__ = __str__ | ||
return cls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
import logging | ||
from abc import abstractmethod | ||
from typing import Generic, TypeVar | ||
|
||
T = TypeVar("T") | ||
log = logging.getLogger("ValueStore") | ||
|
||
|
||
class ValueStore(Generic[T]): | ||
@abstractmethod | ||
def set(self, state: T) -> None: | ||
pass | ||
|
||
|
||
class LoggingValueStore(Generic[T], ValueStore[T]): | ||
def __init__(self, delegate: ValueStore[T]): | ||
self.delegate = delegate | ||
|
||
def set(self, state: T) -> None: | ||
log.debug("Saving %s", state) | ||
self.delegate.set(state) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters