Skip to content

refactor: make base instruments generic over their config type - #286

Merged
lesnik512 merged 1 commit into
mainfrom
refactor/generic-instruments
Oct 14, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
refactor/generic-instruments

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Fixes #285.

The Cors, HealthChecks, Logging, OpenTelemetry, Prometheus and Swagger instruments each get a config type variable bound to their config class, and each framework instrument binds it:

class FastAPICorsInstrument(CorsInstrument[FastAPIConfig]): ...

Before this, every framework instrument re-annotated bootstrap_config with its own config type, and ty 0.0.87 rejected that as invalid-mutable-override. The 20 ignores #284 added for this are gone. So is an invalid-method-override ignore on LitestarSwaggerInstrument.is_configured: its LitestarConfig parameter is no longer narrower than the parameter it overrides.

Nothing changes at runtime. Out-of-tree subclasses such as class MyCors(CorsInstrument) keep working; ty just sees their config type as unknown until they bind the parameter.

The 5 bootstrapper ignores stay. The issue explains why: making BaseBootstrapper generic over its config would either break BaseBootstrapper[App] or need a typing-extensions TypeVar default.

Locally with ty 0.0.87, just lint-ci is clean and just test-ci passes (362 passed, 100% coverage).

@lesnik512
lesnik512 merged commit d215273 into main Oct 14, 2026
30 checks passed
@lesnik512
lesnik512 deleted the refactor/generic-instruments branch October 14, 2026 16:48
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.

Make the base instruments generic over their config type and drop the instrument bootstrap_config ignores

1 participant