feat: expose ContextProvider.context_type as a public attribute#244
Merged
Conversation
`context_type` was stored privately as `_context_type` with no accessor, so integrations had to re-state the connection/context-key type they already passed in. Make it a public plain slot, matching its sibling `bound_type` (both derive from the same constructor arg) and the base provider's public `scope` / `bound_type`. Plain attribute, not a property: every property in the providers wraps a *derived* value (`display_name`); `context_type` is stored config. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
lesnik512
added a commit
that referenced
this pull request
Jun 26, 2026
Curated notes for the 2.21.0 stable tag — release.yml requires planning/releases/<tag>.md before it will publish. 2.20.0 already shipped get_named_providers (#242) without context_type (#244), so the public context_type attribute ships as 2.21.0. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ContextProviderstored its context type privately (_context_type) with no accessor. Expose it as a public plain attributecontext_type.Why
Integrations (modern-di-fastapi, and the same pattern in -litestar / -faststream / -typer) build a connection→scope→context-key mapping. Without a public
context_typethey re-state, in anisinstanceladder, the very type they passed into the provider — the knowledge is split across two places. Exposingcontext_typelets an integration drive that dispatch off the provider objects themselves, single-sourcing the mapping.Design choice — attribute, not property
context_typeis the sibling ofbound_type(both come from the same constructor arg;bound_typedefaults tocontext_type).bound_typeandscopeare public plain slots on the base provider — socontext_typematches its peers.@propertyin the providers wraps a derived value (display_name).context_typeis stored config, so a plain attribute fits the local idiom; a property would be the first one exposing stored state.Tests
test_context_provider_exposes_context_type(TDD: added red, then implemented).Minor, additive, backward-compatible — suggest a minor release (e.g. 2.20.0) so consumers can rely on it.
🤖 Generated with Claude Code