diff --git a/lite_bootstrap/bootstrappers/base.py b/lite_bootstrap/bootstrappers/base.py index 881e42e..72b1b3b 100644 --- a/lite_bootstrap/bootstrappers/base.py +++ b/lite_bootstrap/bootstrappers/base.py @@ -9,7 +9,7 @@ InstrumentDependencyMissingWarning, collect_teardown_errors, ) -from lite_bootstrap.instruments.base import BaseConfig, BaseInstrument +from lite_bootstrap.instruments.base import BaseInstrument, ConfigT from lite_bootstrap.types import ApplicationT @@ -19,12 +19,12 @@ InstrumentT = typing.TypeVar("InstrumentT", bound=BaseInstrument) -class BaseBootstrapper(abc.ABC, typing.Generic[ApplicationT]): +class BaseBootstrapper(abc.ABC, typing.Generic[ApplicationT, ConfigT]): instruments_types: typing.ClassVar[list[type[BaseInstrument]]] not_ready_message: typing.ClassVar[str] instruments: list[BaseInstrument] skipped_instruments: list[tuple[type[BaseInstrument], str]] - bootstrap_config: BaseConfig + bootstrap_config: ConfigT _application: ApplicationT # Marker tagged on a user-supplied app (or its config) once this bootstrapper has @@ -32,7 +32,7 @@ class BaseBootstrapper(abc.ABC, typing.Generic[ApplicationT]): # bootstrapper on the same app from re-attaching. Its accepted limits: ADR-0003. _TEARDOWN_MARKER: typing.ClassVar[str] = "_lite_bootstrap_teardown_attached" - def __init__(self, bootstrap_config: BaseConfig) -> None: + def __init__(self, bootstrap_config: ConfigT) -> None: self.is_bootstrapped = False self._torn_down = False # Set when another bootstrapper already owns this application; bootstrap() then refuses. diff --git a/lite_bootstrap/bootstrappers/fastapi_bootstrapper.py b/lite_bootstrap/bootstrappers/fastapi_bootstrapper.py index 2f58f04..24e352f 100644 --- a/lite_bootstrap/bootstrappers/fastapi_bootstrapper.py +++ b/lite_bootstrap/bootstrappers/fastapi_bootstrapper.py @@ -271,7 +271,7 @@ def bootstrap(self) -> None: enable_offline_docs(application, static_path=config.swagger_static_path) -class FastAPIBootstrapper(BaseBootstrapper["fastapi.FastAPI"]): +class FastAPIBootstrapper(BaseBootstrapper["fastapi.FastAPI", FastAPIConfig]): __slots__ = "bootstrap_config", "instruments" instruments_types: typing.ClassVar = [ @@ -284,7 +284,6 @@ class FastAPIBootstrapper(BaseBootstrapper["fastapi.FastAPI"]): FastAPIPrometheusInstrument, FastAPISwaggerInstrument, ] - bootstrap_config: FastAPIConfig # ty: ignore[invalid-mutable-override] not_ready_message = "fastapi is not installed" @contextlib.asynccontextmanager diff --git a/lite_bootstrap/bootstrappers/fastmcp_bootstrapper.py b/lite_bootstrap/bootstrappers/fastmcp_bootstrapper.py index 47f7745..a67a421 100644 --- a/lite_bootstrap/bootstrappers/fastmcp_bootstrapper.py +++ b/lite_bootstrap/bootstrappers/fastmcp_bootstrapper.py @@ -381,7 +381,7 @@ def bootstrap(self) -> None: self.bootstrap_config.application.add_middleware(FastMcpLoggingMiddleware()) -class FastMcpBootstrapper(BaseBootstrapper["FastMCP[typing.Any]"]): +class FastMcpBootstrapper(BaseBootstrapper["FastMCP[typing.Any]", FastMcpConfig]): __slots__ = "bootstrap_config", "instruments" instruments_types: typing.ClassVar = [ @@ -392,7 +392,6 @@ class FastMcpBootstrapper(BaseBootstrapper["FastMCP[typing.Any]"]): FastMcpLoggingInstrument, FastMcpPrometheusInstrument, ] - bootstrap_config: FastMcpConfig # ty: ignore[invalid-mutable-override] not_ready_message = "fastmcp is not installed" def is_ready(self) -> bool: diff --git a/lite_bootstrap/bootstrappers/faststream_bootstrapper.py b/lite_bootstrap/bootstrappers/faststream_bootstrapper.py index 1a20ab4..641c235 100644 --- a/lite_bootstrap/bootstrappers/faststream_bootstrapper.py +++ b/lite_bootstrap/bootstrappers/faststream_bootstrapper.py @@ -222,7 +222,7 @@ def bootstrap(self) -> None: broker.add_middleware(middleware_cls(registry=self.collector_registry)) -class FastStreamBootstrapper(BaseBootstrapper["AsgiFastStream"]): +class FastStreamBootstrapper(BaseBootstrapper["AsgiFastStream", FastStreamConfig]): __slots__ = "bootstrap_config", "instruments" instruments_types: typing.ClassVar = [ @@ -233,7 +233,6 @@ class FastStreamBootstrapper(BaseBootstrapper["AsgiFastStream"]): FastStreamLoggingInstrument, FastStreamPrometheusInstrument, ] - bootstrap_config: FastStreamConfig # ty: ignore[invalid-mutable-override] not_ready_message = "faststream is not installed" def is_ready(self) -> bool: diff --git a/lite_bootstrap/bootstrappers/free_bootstrapper.py b/lite_bootstrap/bootstrappers/free_bootstrapper.py index 2da2fd6..2428ab5 100644 --- a/lite_bootstrap/bootstrappers/free_bootstrapper.py +++ b/lite_bootstrap/bootstrappers/free_bootstrapper.py @@ -12,7 +12,7 @@ class FreeConfig(LoggingConfig, OpenTelemetryConfig, PyroscopeConfig, SentryConfig): ... -class FreeBootstrapper(BaseBootstrapper[None]): +class FreeBootstrapper(BaseBootstrapper[None, FreeConfig]): __slots__ = "bootstrap_config", "instruments" instruments_types: typing.ClassVar = [ @@ -21,7 +21,6 @@ class FreeBootstrapper(BaseBootstrapper[None]): OpenTelemetryInstrument, PyroscopeInstrument, ] - bootstrap_config: FreeConfig # ty: ignore[invalid-mutable-override] not_ready_message = "" def is_ready(self) -> bool: diff --git a/lite_bootstrap/bootstrappers/litestar_bootstrapper.py b/lite_bootstrap/bootstrappers/litestar_bootstrapper.py index 95ccd7d..a912c27 100644 --- a/lite_bootstrap/bootstrappers/litestar_bootstrapper.py +++ b/lite_bootstrap/bootstrappers/litestar_bootstrapper.py @@ -479,7 +479,7 @@ def bootstrap(self) -> None: ) -class LitestarBootstrapper(BaseBootstrapper["litestar.Litestar"]): +class LitestarBootstrapper(BaseBootstrapper["litestar.Litestar", LitestarConfig]): __slots__ = "bootstrap_config", "instruments" instruments_types: typing.ClassVar = [ @@ -492,7 +492,6 @@ class LitestarBootstrapper(BaseBootstrapper["litestar.Litestar"]): LitestarPrometheusInstrument, LitestarSwaggerInstrument, ] - bootstrap_config: LitestarConfig # ty: ignore[invalid-mutable-override] not_ready_message = "litestar is not installed" def __init__(self, bootstrap_config: LitestarConfig) -> None: diff --git a/tests/instruments/test_logging_record_filters.py b/tests/instruments/test_logging_record_filters.py index 7acd109..979a7b5 100644 --- a/tests/instruments/test_logging_record_filters.py +++ b/tests/instruments/test_logging_record_filters.py @@ -349,7 +349,7 @@ def test_bootstrap_teardown_bootstrap_attaches_each_filter_once() -> None: BootstrapperBuilder = typing.Callable[ [dict[str, tuple[logging.Filter, ...]]], - BaseBootstrapper[typing.Any], + BaseBootstrapper[typing.Any, typing.Any], ]