Skip to content

refactor: make BaseInstrument generic; delete pure-annotation subclasses#95

Merged
lesnik512 merged 1 commit into
mainfrom
refactor/des-1-generic-instruments
Jun 1, 2026
Merged

refactor: make BaseInstrument generic; delete pure-annotation subclasses#95
lesnik512 merged 1 commit into
mainfrom
refactor/des-1-generic-instruments

Conversation

@lesnik512

@lesnik512 lesnik512 commented Jun 1, 2026

Copy link
Copy Markdown
Member

Summary

Closes DES-1 from an internal audit: the four pure type-annotation framework subclasses (FastAPILoggingInstrument, FastAPISentryInstrument, LitestarSentryInstrument, FastStreamSentryInstrument) existed only to narrow bootstrap_config. They contributed no behavior.

  • BaseInstrument is now generic in ConfigT (TypeVar bound to BaseConfig).
  • Each base instrument concretely parameterizes the generic (LoggingInstrument(BaseInstrument[LoggingConfig]), etc.) and drops its redundant bootstrap_config field declaration.
  • The four pure-annotation framework subclasses are deleted. The three affected bootstrappers' instruments_types lists now reference base names directly (SentryInstrument, LoggingInstrument).
  • Framework subclasses that override bootstrap() with framework-specific logic (15 total) keep their existing structure.

12 files modified, net -24 lines. No behavior change. Existing 89 tests verify correctness.

Deviation from sequencing spec

The sequencing spec called for "dropping redundant bootstrap_config: annotations on kept subclasses." Under single-level generic those annotations are NOT redundant — they provide essential type narrowing for framework field access (e.g. self.bootstrap_config.application in FastAPICorsInstrument.bootstrap()). Making them truly redundant would require a two-level-generic design (each base instrument with its own bounded TypeVar); the complexity isn't worth the marginal cleanup. The audit's stated goal — eliminating the pure-annotation boilerplate — is fully addressed regardless.

Test plan

  • just test — 89/89.
  • just lint — clean (ty check clean, ruff check clean).
  • BaseInstrument's slots=True worked first try with Generic (no fallback needed).
  • No # ty: ignore comments required on framework subclasses' bootstrap_config re-annotations.
  • Reviewer: confirm the # noqa: B027 removal is acceptable. Ruff stopped flagging abc.ABC + Generic[T] classes once Generic was added — the suppressions became genuinely unnecessary. bootstrap() and teardown() on BaseInstrument are still concrete no-ops (overridable but not required); they're not abstract.

Notes for reviewer

  • The 15 kept framework subclasses (FastAPICorsInstrument, LitestarLoggingInstrument, etc.) still declare bootstrap_config: <FrameworkConfig>. This is a covariant narrowing (FrameworkConfig is a subtype of LoggingConfig/CorsConfig/etc.) — standard dataclass pattern for narrowing inherited fields.
  • SwaggerInstrument ended up with a pass body (only contained the dropped field declaration). Cosmetically odd but mechanically correct.

🤖 Generated with Claude Code

Closes DES-1: the four pure type-annotation framework subclasses
(FastAPILoggingInstrument, FastAPISentryInstrument, LitestarSentryInstrument,
FastStreamSentryInstrument) existed only to narrow bootstrap_config. They
contributed no behavior.

Make BaseInstrument generic in ConfigT (TypeVar bound to BaseConfig).
Each base instrument concretely parameterizes the generic
(LoggingInstrument(BaseInstrument[LoggingConfig]), etc.) and drops its
own redundant bootstrap_config field declaration — the type is now
provided by the parent's generic parameter.

Delete the four pure-annotation framework subclasses. In the three
affected bootstrappers' instruments_types lists, replace the deleted
class references with the base names (SentryInstrument, LoggingInstrument).

Framework subclasses that override bootstrap() with real framework-specific
logic (FastAPICorsInstrument, LitestarLoggingInstrument, etc. — 15 in
total) keep their existing structure including the bootstrap_config:
<FrameworkConfig> annotation. These annotations are NOT redundant under
the single-level-generic design adopted here — they provide essential
type narrowing for framework field access (e.g.,
self.bootstrap_config.application inside FastAPICorsInstrument.bootstrap).

This deviates from the sequencing spec's "drop redundant annotations
on kept subclasses" decision: a two-level-generic design would be needed
to make those annotations truly redundant, and the complexity isn't
worth it. The audit's stated goal (eliminate the pure-annotation
boilerplate) is fully addressed regardless.

No behavior change. Existing tests verify correctness.

Closes DES-1 from the audit.
@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...te_bootstrap/bootstrappers/fastapi_bootstrapper.py 100.00% <ø> (ø)
...bootstrap/bootstrappers/faststream_bootstrapper.py 100.00% <ø> (ø)
...e_bootstrap/bootstrappers/litestar_bootstrapper.py 100.00% <ø> (ø)
lite_bootstrap/instruments/base.py 100.00% <100.00%> (ø)
lite_bootstrap/instruments/cors_instrument.py 100.00% <100.00%> (ø)
...e_bootstrap/instruments/healthchecks_instrument.py 100.00% <100.00%> (ø)
lite_bootstrap/instruments/logging_instrument.py 100.00% <100.00%> (ø)
..._bootstrap/instruments/opentelemetry_instrument.py 100.00% <100.00%> (ø)
...ite_bootstrap/instruments/prometheus_instrument.py 100.00% <100.00%> (ø)
lite_bootstrap/instruments/pyroscope_instrument.py 100.00% <100.00%> (ø)
... and 2 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lesnik512 lesnik512 self-assigned this Jun 1, 2026
@lesnik512 lesnik512 merged commit ade49f7 into main Jun 1, 2026
8 checks passed
@lesnik512 lesnik512 deleted the refactor/des-1-generic-instruments branch June 1, 2026 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant