Skip to content

Commit 6f07863

Browse files
authored
Make BaseBootstrapper generic over its config (#376)
1 parent 182c357 commit 6f07863

7 files changed

Lines changed: 10 additions & 15 deletions

File tree

‎lite_bootstrap/bootstrappers/base.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
InstrumentDependencyMissingWarning,
1010
collect_teardown_errors,
1111
)
12-
from lite_bootstrap.instruments.base import BaseConfig, BaseInstrument
12+
from lite_bootstrap.instruments.base import BaseInstrument, ConfigT
1313
from lite_bootstrap.types import ApplicationT
1414

1515

@@ -19,20 +19,20 @@
1919
InstrumentT = typing.TypeVar("InstrumentT", bound=BaseInstrument)
2020

2121

22-
class BaseBootstrapper(abc.ABC, typing.Generic[ApplicationT]):
22+
class BaseBootstrapper(abc.ABC, typing.Generic[ApplicationT, ConfigT]):
2323
instruments_types: typing.ClassVar[list[type[BaseInstrument]]]
2424
not_ready_message: typing.ClassVar[str]
2525
instruments: list[BaseInstrument]
2626
skipped_instruments: list[tuple[type[BaseInstrument], str]]
27-
bootstrap_config: BaseConfig
27+
bootstrap_config: ConfigT
2828
_application: ApplicationT
2929

3030
# Marker tagged on a user-supplied app (or its config) once this bootstrapper has
3131
# attached its teardown to the framework's shutdown lifecycle. Prevents a second
3232
# bootstrapper on the same app from re-attaching. Its accepted limits: ADR-0003.
3333
_TEARDOWN_MARKER: typing.ClassVar[str] = "_lite_bootstrap_teardown_attached"
3434

35-
def __init__(self, bootstrap_config: BaseConfig) -> None:
35+
def __init__(self, bootstrap_config: ConfigT) -> None:
3636
self.is_bootstrapped = False
3737
self._torn_down = False
3838
# Set when another bootstrapper already owns this application; bootstrap() then refuses.

‎lite_bootstrap/bootstrappers/fastapi_bootstrapper.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def bootstrap(self) -> None:
271271
enable_offline_docs(application, static_path=config.swagger_static_path)
272272

273273

274-
class FastAPIBootstrapper(BaseBootstrapper["fastapi.FastAPI"]):
274+
class FastAPIBootstrapper(BaseBootstrapper["fastapi.FastAPI", FastAPIConfig]):
275275
__slots__ = "bootstrap_config", "instruments"
276276

277277
instruments_types: typing.ClassVar = [
@@ -284,7 +284,6 @@ class FastAPIBootstrapper(BaseBootstrapper["fastapi.FastAPI"]):
284284
FastAPIPrometheusInstrument,
285285
FastAPISwaggerInstrument,
286286
]
287-
bootstrap_config: FastAPIConfig # ty: ignore[invalid-mutable-override]
288287
not_ready_message = "fastapi is not installed"
289288

290289
@contextlib.asynccontextmanager

‎lite_bootstrap/bootstrappers/fastmcp_bootstrapper.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def bootstrap(self) -> None:
381381
self.bootstrap_config.application.add_middleware(FastMcpLoggingMiddleware())
382382

383383

384-
class FastMcpBootstrapper(BaseBootstrapper["FastMCP[typing.Any]"]):
384+
class FastMcpBootstrapper(BaseBootstrapper["FastMCP[typing.Any]", FastMcpConfig]):
385385
__slots__ = "bootstrap_config", "instruments"
386386

387387
instruments_types: typing.ClassVar = [
@@ -392,7 +392,6 @@ class FastMcpBootstrapper(BaseBootstrapper["FastMCP[typing.Any]"]):
392392
FastMcpLoggingInstrument,
393393
FastMcpPrometheusInstrument,
394394
]
395-
bootstrap_config: FastMcpConfig # ty: ignore[invalid-mutable-override]
396395
not_ready_message = "fastmcp is not installed"
397396

398397
def is_ready(self) -> bool:

‎lite_bootstrap/bootstrappers/faststream_bootstrapper.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def bootstrap(self) -> None:
222222
broker.add_middleware(middleware_cls(registry=self.collector_registry))
223223

224224

225-
class FastStreamBootstrapper(BaseBootstrapper["AsgiFastStream"]):
225+
class FastStreamBootstrapper(BaseBootstrapper["AsgiFastStream", FastStreamConfig]):
226226
__slots__ = "bootstrap_config", "instruments"
227227

228228
instruments_types: typing.ClassVar = [
@@ -233,7 +233,6 @@ class FastStreamBootstrapper(BaseBootstrapper["AsgiFastStream"]):
233233
FastStreamLoggingInstrument,
234234
FastStreamPrometheusInstrument,
235235
]
236-
bootstrap_config: FastStreamConfig # ty: ignore[invalid-mutable-override]
237236
not_ready_message = "faststream is not installed"
238237

239238
def is_ready(self) -> bool:

‎lite_bootstrap/bootstrappers/free_bootstrapper.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class FreeConfig(LoggingConfig, OpenTelemetryConfig, PyroscopeConfig, SentryConfig): ...
1313

1414

15-
class FreeBootstrapper(BaseBootstrapper[None]):
15+
class FreeBootstrapper(BaseBootstrapper[None, FreeConfig]):
1616
__slots__ = "bootstrap_config", "instruments"
1717

1818
instruments_types: typing.ClassVar = [
@@ -21,7 +21,6 @@ class FreeBootstrapper(BaseBootstrapper[None]):
2121
OpenTelemetryInstrument,
2222
PyroscopeInstrument,
2323
]
24-
bootstrap_config: FreeConfig # ty: ignore[invalid-mutable-override]
2524
not_ready_message = ""
2625

2726
def is_ready(self) -> bool:

‎lite_bootstrap/bootstrappers/litestar_bootstrapper.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def bootstrap(self) -> None:
479479
)
480480

481481

482-
class LitestarBootstrapper(BaseBootstrapper["litestar.Litestar"]):
482+
class LitestarBootstrapper(BaseBootstrapper["litestar.Litestar", LitestarConfig]):
483483
__slots__ = "bootstrap_config", "instruments"
484484

485485
instruments_types: typing.ClassVar = [
@@ -492,7 +492,6 @@ class LitestarBootstrapper(BaseBootstrapper["litestar.Litestar"]):
492492
LitestarPrometheusInstrument,
493493
LitestarSwaggerInstrument,
494494
]
495-
bootstrap_config: LitestarConfig # ty: ignore[invalid-mutable-override]
496495
not_ready_message = "litestar is not installed"
497496

498497
def __init__(self, bootstrap_config: LitestarConfig) -> None:

‎tests/instruments/test_logging_record_filters.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def test_bootstrap_teardown_bootstrap_attaches_each_filter_once() -> None:
349349

350350
BootstrapperBuilder = typing.Callable[
351351
[dict[str, tuple[logging.Filter, ...]]],
352-
BaseBootstrapper[typing.Any],
352+
BaseBootstrapper[typing.Any, typing.Any],
353353
]
354354

355355

0 commit comments

Comments
 (0)