Title: feat(types): cross-class entity overrides on response schemas — Protocol bounds or Generic response types · Issue #710 · adcontextprotocol/adcp-client-python · GitHub
Open Graph Title: feat(types): cross-class entity overrides on response schemas — Protocol bounds or Generic response types · Issue #710 · adcontextprotocol/adcp-client-python
X Title: feat(types): cross-class entity overrides on response schemas — Protocol bounds or Generic response types · Issue #710 · adcontextprotocol/adcp-client-python
Description: Problem PR #635 widened response-only list fields to Sequence[T], which solved subclass overrides — adopters subclassing Creative with MyCreative can now assign list[MyCreative] to Sequence[Creative] cleanly. But the more common adopter ...
Open Graph Description: Problem PR #635 widened response-only list fields to Sequence[T], which solved subclass overrides — adopters subclassing Creative with MyCreative can now assign list[MyCreative] to Sequence[Creativ...
X Description: Problem PR #635 widened response-only list fields to Sequence[T], which solved subclass overrides — adopters subclassing Creative with MyCreative can now assign list[MyCreative] to Sequence[Creativ...
Opengraph URL: https://github.com/adcontextprotocol/adcp-client-python/issues/710
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"feat(types): cross-class entity overrides on response schemas — Protocol bounds or Generic response types","articleBody":"## Problem\n\nPR #635 widened response-only list fields to `Sequence[T]`, which solved **subclass** overrides — adopters subclassing `Creative` with `MyCreative` can now assign `list[MyCreative]` to `Sequence[Creative]` cleanly.\n\nBut the more common adopter pattern in salesagent (and likely other production deployments) is **cross-class** overrides: substituting a *shape-compatible but distinct* entity class for the canonical one. `Sequence[T]` doesn't help these because `MyDeliveryView` is not a subclass of `Creative`.\n\n## Verified cases in salesagent after 5.3.0 bump\n\nStripped every `# type: ignore[assignment]` from the schema modules and re-ran mypy against adcp 5.3.0. **12 errors came back. All 12 are cross-class, not subclass.**\n\n| File:Line | Override | Parent expects | Cross-class because |\n|---|---|---|---|\n| `_base.py:874-877` | `list[GeoCountry]` (+ 3 siblings) | `Sequence[GeoCountriesExcludeItem]` | `GeoCountry` is the *inclusion* variant; spec uses distinct `GeoCountriesExcludeItem` for exclusion |\n| `_base.py:1322` | `list[Creative]` (salesagent) | `Sequence[CreativeAsset]` | `Creative` extends `LibraryCreative`, not `CreativeAsset` |\n| `_base.py:1939` | `list[SignalDeployment]` | `Sequence[Deployments \\| Deployments3]` | `SignalDeployment` extends `PlatformDeployment`, not `Deployments` |\n| `_base.py:2407` | `list[GetMediaBuysMediaBuy]` | `Sequence[MediaBuy]` | `GetMediaBuysMediaBuy` is a delivery-context view, not a `MediaBuy` subclass |\n| `delivery.py:251` | `list[MediaBuyDeliveryData]` | `Sequence[MediaBuyDelivery]` | Different class, same shape |\n| `delivery.py:440` | `list[CreativeDeliveryData]` | `Sequence[Creative]` | Different class, same shape |\n| `creative.py:407` | `list[CreativeAsset]` (local) | `list[CreativeAsset]` (library) | Same name, **different class** — local wraps with internal fields |\n| `creative.py:677` | `QuerySummary` (local) | `QuerySummary` (library) | Same name, different class |\n\nThis is exactly the pattern your own docs at #644 (\\\"Picking the Right Base Class — Context-Specific Schema Variants\\\") explicitly acknowledges as legitimate and documents how to type:ignore correctly. So the SDK has admitted these aren't bugs in adopter code — they're the intended pattern. But the type system has no way to express \\\"this field accepts any class with the shape of X\\\" without giving up on the safety entirely.\n\n## Proposed\n\nPick one. Listed in order of escalating invasiveness.\n\n### (a) Document the pattern + provide a typed escape hatch\n\nSmallest change. Ship a `SchemaVariant` mixin / decorator that marks the override as intentional and silences mypy without `# type: ignore`. Effectively codifies what PR #644's docs already say.\n\n```python\nclass GetMediaBuyDeliveryResponse(LibraryGetMediaBuyDeliveryResponse):\n media_buy_deliveries: SchemaVariant[list[MediaBuyDeliveryData]]\n```\n\nThe type alias resolves to the field type at runtime; mypy treats it as `Any`-bounded. Loses precise inference inside the override but kills the ignores.\n\n### (b) Generate response types as Generic over their entity items\n\n```python\nclass GetCreativeDeliveryResponse(Generic[CreativeT], ...):\n creatives: Sequence[CreativeT]\n```\n\nThen:\n\n```python\nclass GetCreativeDeliveryResponse(LibraryGetCreativeDeliveryResponse[CreativeDeliveryData]):\n ... # no override needed; the Generic specialization handles it\n```\n\nMechanically clean, fully type-safe, but requires the codegen path to emit Generic classes — bigger change.\n\n### (c) Use structural Protocol bounds in response types\n\n```python\nclass CreativeLike(Protocol):\n creative_id: str\n # ... minimum shape\n\nclass GetCreativeDeliveryResponse(...):\n creatives: Sequence[CreativeLike]\n```\n\nAny class with the right shape satisfies the type. No subclass relation needed. Closest to what the adopter pattern actually means. But: structural typing in Pydantic-generated types is unusual and requires careful codegen.\n\n## What I'd push for\n\n**(b) is the cleanest** if the codegen pipeline can absorb it. Generic response types specialize cleanly, give adopters full inference inside their overrides, and don't require the SDK to predict which fields adopters will override.\n\n**(a) is the smallest reasonable step** if (b) is too invasive — it at least removes the visual noise and centralizes the pattern so reviewers know what they're seeing.\n\n## Acceptance\n\n- Salesagent can remove all 12 `# type: ignore[assignment]` comments listed above without changing override behavior\n- mypy `--strict` passes on the resulting schema modules\n- An example in `examples/` showing the documented adopter pattern\n- PR #644's docs guidance gets a \\\"prefer this over type:ignore\\\" pointer to the new mechanism\n\n## Real-world demand\n\nSame audit as #709. This was the single largest category of \\\"workarounds we hoped 5.3.0 would let us delete\\\" that turned out not to be addressed by PR #635.","author":{"url":"https://github.com/bokelley","@type":"Person","name":"bokelley"},"datePublished":"2026-05-12T22:56:44Z","url":"https://github.com/adcontextprotocol/adcp-client-python/issues/710"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8b67be51-7766-4ea8-8340-859d4186e3f1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E6BC:26ECEB:D5E660:11338CA:6B00F247 |
| html-safe-nonce | 471e160292b9bba0031aa7971950a8ca5281c77be5f0c47f911fd71a424ffcf8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNkJDOjI2RUNFQjpENUU2NjA6MTEzMzhDQTo2QjAwRjI0NyIsInZpc2l0b3JfaWQiOiI1NTE1ODM5Njc3NTYwNTgyNzI3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f0e219ee9e25cd8f76d5676c55863aae8c2c2948a4bda37608177abb5ed9ad89 |
| hovercard-subject-tag | issue:4433203546 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/adcontextprotocol/adcp-client-python/710/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ced7f4dea299adaf6ce5bc6cbc3dd0c0360aeb01bd9cb6b05d428d6581b37110/adcontextprotocol/adcp-client-python/issues/710 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ced7f4dea299adaf6ce5bc6cbc3dd0c0360aeb01bd9cb6b05d428d6581b37110/adcontextprotocol/adcp-client-python/issues/710 |
| og:image:alt | Problem PR #635 widened response-only list fields to Sequence[T], which solved subclass overrides — adopters subclassing Creative with MyCreative can now assign list[MyCreative] to Sequence[Creativ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bokelley |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| turbo-cache-control | no-preview |
| go-import | github.com/adcontextprotocol/adcp-client-python git https://github.com/adcontextprotocol/adcp-client-python.git |
| octolytics-dimension-user_id | 221690821 |
| octolytics-dimension-user_login | adcontextprotocol |
| octolytics-dimension-repository_id | 1090305973 |
| octolytics-dimension-repository_nwo | adcontextprotocol/adcp-client-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1090305973 |
| octolytics-dimension-repository_network_root_nwo | adcontextprotocol/adcp-client-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width