Skip to content

feat: expose ContextProvider.context_type as a public attribute#244

Merged
lesnik512 merged 1 commit into
mainfrom
feat/context-provider-context-type
Jun 26, 2026
Merged

feat: expose ContextProvider.context_type as a public attribute#244
lesnik512 merged 1 commit into
mainfrom
feat/context-provider-context-type

Conversation

@lesnik512

Copy link
Copy Markdown
Member

What

ContextProvider stored its context type privately (_context_type) with no accessor. Expose it as a public plain attribute context_type.

provider = ContextProvider(scope=Scope.REQUEST, context_type=fastapi.Request)
provider.context_type  # -> fastapi.Request

Why

Integrations (modern-di-fastapi, and the same pattern in -litestar / -faststream / -typer) build a connection→scope→context-key mapping. Without a public context_type they re-state, in an isinstance ladder, the very type they passed into the provider — the knowledge is split across two places. Exposing context_type lets an integration drive that dispatch off the provider objects themselves, single-sourcing the mapping.

Design choice — attribute, not property

  • context_type is the sibling of bound_type (both come from the same constructor arg; bound_type defaults to context_type). bound_type and scope are public plain slots on the base provider — so context_type matches its peers.
  • Every @property in the providers wraps a derived value (display_name). context_type is stored config, so a plain attribute fits the local idiom; a property would be the first one exposing stored state.

Tests

  • New test_context_provider_exposes_context_type (TDD: added red, then implemented).
  • Full suite green at 100% coverage; ruff / format / ty clean.

Minor, additive, backward-compatible — suggest a minor release (e.g. 2.20.0) so consumers can rely on it.

🤖 Generated with Claude Code

`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 lesnik512 merged commit 51196d1 into main Jun 26, 2026
7 checks passed
@lesnik512 lesnik512 deleted the feat/context-provider-context-type branch June 26, 2026 18:54
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>
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