Skip to content

Commit

Permalink
refactor: rollback weird typing backport issue
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Apr 11, 2024
1 parent 9ca7692 commit 897cf95
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
"eth-pydantic-types", # Use same version as eth-ape
"pydantic_settings", # Use same version as eth-ape
"taskiq[metrics]>=0.10.4,<0.11.0",
"backports.strenum ; python_version<'3.11'",
],
entry_points={
"console_scripts": ["silverback=silverback._cli:cli"],
Expand Down
14 changes: 4 additions & 10 deletions silverback/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def on_startup(self) -> Callable:
def do_something_on_startup(startup_state):
... # Reprocess missed events or blocks
"""
return self.broker_task_decorator(TaskType.STARTUP) # type: ignore[arg-type]
return self.broker_task_decorator(TaskType.STARTUP)

def on_shutdown(self) -> Callable:
"""
Expand All @@ -151,7 +151,7 @@ def on_shutdown(self) -> Callable:
def do_something_on_shutdown():
... # Record final state of app
"""
return self.broker_task_decorator(TaskType.SHUTDOWN) # type: ignore[arg-type]
return self.broker_task_decorator(TaskType.SHUTDOWN)

def on_worker_startup(self) -> Callable:
"""
Expand Down Expand Up @@ -210,10 +210,7 @@ def on_(
else:
self.poll_settings["_blocks_"] = {"start_block": start_block}

return self.broker_task_decorator(
TaskType.NEW_BLOCKS, # type: ignore[arg-type]
container=container,
)
return self.broker_task_decorator(TaskType.NEW_BLOCKS, container=container)

elif isinstance(container, ContractEvent) and isinstance(
container.contract, ContractInstance
Expand All @@ -232,10 +229,7 @@ def on_(
else:
self.poll_settings[key] = {"start_block": start_block}

return self.broker_task_decorator(
TaskType.EVENT_LOG, # type: ignore[arg-type]
container=container,
)
return self.broker_task_decorator(TaskType.EVENT_LOG, container=container)

# TODO: Support account transaction polling
# TODO: Support mempool polling
Expand Down
13 changes: 5 additions & 8 deletions silverback/types.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
from enum import Enum # NOTE: `enum.StrEnum` only in Python 3.11+
from typing import Optional, Protocol

from pydantic import BaseModel
from typing_extensions import Self # Introduced 3.11

try:
# NOTE: Only Python 3.11+
from enum import StrEnum # type: ignore[attr-defined]

except ImportError:
from backports.strenum import StrEnum # type: ignore[no-redef,import-not-found]


class TaskType(StrEnum):
class TaskType(str, Enum):
STARTUP = "silverback_startup" # TODO: Shorten in 0.4.0
NEW_BLOCKS = "block"
EVENT_LOG = "event"
SHUTDOWN = "silverback_shutdown" # TODO: Shorten in 0.4.0

def __str__(self) -> str:
return self.value


class ISilverbackSettings(Protocol):
"""Loose approximation of silverback.settings.Settings. If you can, use the class as
Expand Down

0 comments on commit 897cf95

Please sign in to comment.