Skip to content

Commit

Permalink
style: minor cleanup and docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeshultz committed Nov 21, 2023
1 parent c420f49 commit 7e9e67a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
8 changes: 4 additions & 4 deletions silverback/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def on_startup(self) -> Callable:
Usage example::
@app.on_startup()
def do_something_on_startup(state):
... # Can provision resources, or add things to `state`.
def do_something_on_startup(startup_state):
... # Reprocess missed events or blocks
"""
return self.broker.task(task_name="silverback_startup")

Expand All @@ -92,8 +92,8 @@ def on_shutdown(self) -> Callable:
Usage example::
@app.on_shutdown()
def do_something_on_shutdown(state):
... # Update some external service, perhaps using information from `state`.
def do_something_on_shutdown():
... # Record final state of app
"""
return self.broker.task(task_name="silverback_shutdown")

Expand Down
4 changes: 2 additions & 2 deletions silverback/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from taskiq import TaskiqResult
from typing_extensions import Self # Introduced 3.11

from .types import IntOrNone, SilverbackIdent, SilverbackSettings
from .types import IntOrNone, SilverbackIdent, ISilverbackSettings


class SilverbackState(BaseModel):
Expand Down Expand Up @@ -57,7 +57,7 @@ def from_taskiq(


class BasePersistentStorage(ABC):
def __init__(self, settings: SilverbackSettings):
def __init__(self, settings: ISilverbackSettings):
self.settings = settings

@abstractmethod
Expand Down
1 change: 0 additions & 1 deletion silverback/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def get_broker(self) -> AsyncBroker:
return broker

def get_network_choice(self) -> str:
# return self.NETWORK_CHOICE or self.network_manager.default_ecosystem.name
return self.NETWORK_CHOICE or self.network_manager.network.choice

def get_persistent_storage(self) -> Optional[BasePersistentStorage]:
Expand Down
7 changes: 5 additions & 2 deletions silverback/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
IntOrNone = Union[int, None]


class SilverbackSettings(Protocol):
class ISilverbackSettings(Protocol):
"""Loose approximation of silverback.settings.Settings. If you can, use the class as
a type reference."""

INSTANCE: str
PERSISTENCE_CLASS: Optional[str]
PERSISTENCE_URI: Optional[str]
Expand All @@ -22,7 +25,7 @@ class SilverbackIdent(BaseModel):
network_choice: str

@classmethod
def from_settings(cls, settings_: SilverbackSettings) -> Self:
def from_settings(cls, settings_: ISilverbackSettings) -> Self:
return cls(identifier=settings_.INSTANCE, network_choice=settings_.get_network_choice())


Expand Down
1 change: 1 addition & 0 deletions silverback/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def iter_to_queue():


def hexbytes_dict(data: dict) -> dict:
"""Converts any hex string values in a flat dictionary to HexBytes."""
fixed_data = {}

for name, value in data.items():
Expand Down

0 comments on commit 7e9e67a

Please sign in to comment.