From 4714c821bfc7c83809051ddefe3ac21d9f93253d Mon Sep 17 00:00:00 2001 From: Mike Shultz Date: Mon, 13 Nov 2023 14:15:54 -0700 Subject: [PATCH] fix: pydantic 2 settings, fix type errors --- setup.py | 2 ++ silverback/application.py | 9 ++++++++- silverback/settings.py | 8 ++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 1ba5fcfb..75dc1bc1 100644 --- a/setup.py +++ b/setup.py @@ -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 ], diff --git a/silverback/application.py b/silverback/application.py index f88342f0..54cd60cc 100644 --- a/silverback/application.py +++ b/silverback/application.py @@ -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 @@ -14,6 +15,9 @@ from .exceptions import DuplicateHandlerError, InvalidContainerTypeError from .settings import Settings +_FuncParams = ParamSpec("_FuncParams") +_ReturnType = TypeVar("_ReturnType") + class SilverbackApp(ManagerAccessMixin): """ @@ -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`. diff --git a/silverback/settings.py b/silverback/settings.py index bd486863..48140e2c 100644 --- a/silverback/settings.py +++ b/silverback/settings.py @@ -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 @@ -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)