Skip to content

Commit

Permalink
fix: pydantic 2 settings, fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeshultz committed Nov 13, 2023
1 parent 338717f commit 4714c82
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
include_package_data=True,
install_requires=[
"eth-ape>=0.6.19,<1.0",
"pydantic>=2,<3",
"pydantic-settings>=2,<3",
"taskiq[metrics]>=0.10.2,<0.11.0",
"click", # Use same version as eth-ape
],
Expand Down
9 changes: 8 additions & 1 deletion silverback/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import atexit
from datetime import timedelta
from typing import Callable, Dict, Optional, Union
from typing_extensions import ParamSpec, TypeVar

from ape.api.networks import LOCAL_NETWORK_NAME
from ape.contracts import ContractEvent, ContractInstance
Expand All @@ -14,6 +15,9 @@
from .exceptions import DuplicateHandlerError, InvalidContainerTypeError
from .settings import Settings

_FuncParams = ParamSpec("_FuncParams")
_ReturnType = TypeVar("_ReturnType")


class SilverbackApp(ManagerAccessMixin):
"""
Expand Down Expand Up @@ -137,7 +141,10 @@ def on_(
container: Union[BlockContainer, ContractEvent],
new_block_timeout: Optional[int] = None,
start_block: Optional[int] = None,
) -> AsyncTaskiqDecoratedTask:
) -> Callable[
[Callable[_FuncParams, _ReturnType]],
AsyncTaskiqDecoratedTask[_FuncParams, _ReturnType],
]:
"""
Create task to handle events created by `container`.
Expand Down
8 changes: 4 additions & 4 deletions silverback/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from ape.api import AccountAPI, ProviderContextManager
from ape.utils import ManagerAccessMixin
from pydantic import BaseSettings
from pydantic_settings import BaseSettings, SettingsConfigDict

# from ape._pydantic_compat import BaseSettings
from taskiq import AsyncBroker, InMemoryBroker, PrometheusMiddleware, TaskiqMiddleware

from ._importer import import_from_string
Expand Down Expand Up @@ -31,9 +33,7 @@ class Settings(BaseSettings, ManagerAccessMixin):
NEW_BLOCK_TIMEOUT: Optional[int] = None
START_BLOCK: Optional[int] = None

class Config:
env_prefix = "SILVERBACK_"
case_sensitive = True
model_config = SettingsConfigDict(env_prefix="SILVERBACK_", case_sensitive=True)

def get_broker(self) -> AsyncBroker:
broker_class = import_from_string(self.BROKER_CLASS)
Expand Down

0 comments on commit 4714c82

Please sign in to comment.