Title: fix(types): codegen multi-emission of Creative/Package/etc. breaks Sequence covariant override on required response fields · Issue #642 · adcontextprotocol/adcp-client-python · GitHub
Open Graph Title: fix(types): codegen multi-emission of Creative/Package/etc. breaks Sequence covariant override on required response fields · Issue #642 · adcontextprotocol/adcp-client-python
X Title: fix(types): codegen multi-emission of Creative/Package/etc. breaks Sequence covariant override on required response fields · Issue #642 · adcontextprotocol/adcp-client-python
Description: Problem datamodel-codegen emits subordinate types (`Creative`, `Package`, `MediaBuyDelivery`, etc.) once per response file. The public alias in `adcp.types` resolves to one specific emission, but the response type's field references a di...
Open Graph Description: Problem datamodel-codegen emits subordinate types (`Creative`, `Package`, `MediaBuyDelivery`, etc.) once per response file. The public alias in `adcp.types` resolves to one specific emission, but t...
X Description: Problem datamodel-codegen emits subordinate types (`Creative`, `Package`, `MediaBuyDelivery`, etc.) once per response file. The public alias in `adcp.types` resolves to one specific emission, but t...
Opengraph URL: https://github.com/adcontextprotocol/adcp-client-python/issues/642
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"fix(types): codegen multi-emission of Creative/Package/etc. breaks Sequence covariant override on required response fields","articleBody":"## Problem\n\ndatamodel-codegen emits subordinate types (\\`Creative\\`, \\`Package\\`, \\`MediaBuyDelivery\\`, etc.) **once per response file**. The public alias in \\`adcp.types\\` resolves to one specific emission, but the response type's field references a *different* local emission with the same name.\n\nExample:\n\n\\`\\`\\`python\nfrom adcp.types import Creative\n# → adcp.types.generated_poc.creative.get_creative_delivery_response.Creative\n\nfrom adcp.types.generated_poc.creative.list_creatives_response import (\n ListCreativesResponse,\n)\n# ListCreativesResponse.creatives: Sequence[Creative]\n# ↑ this Creative is adcp.types.generated_poc.creative.list_creatives_response.Creative\n# — a DIFFERENT class with the same name\n\\`\\`\\`\n\nThese two \\`Creative\\` classes are nominally identical but type-distinct from mypy's perspective. So an adopter pattern:\n\n\\`\\`\\`python\nfrom adcp.types import Creative\n\nclass _Ext(Creative):\n extra: str | None = Field(default=None, exclude=True)\n\nclass _ExtListResp(ListCreativesResponse):\n creatives: list[_Ext] # mypy [assignment] — type-identity mismatch\n\\`\\`\\`\n\n…fails under mypy --strict regardless of #624's Sequence widening, because \\`_Ext\\` is a subclass of one \\`Creative\\` and the parent expects a different one.\n\n## Affected response types (likely incomplete)\n\nEach of these has a field whose element type is locally re-emitted rather than imported from the canonical module:\n\n- \\`ListCreativesResponse.creatives\\` → \\`Creative\\`\n- \\`GetCreativeDeliveryResponse.creatives\\` → \\`Creative\\`\n- \\`GetMediaBuyDeliveryResponse.media_buy_deliveries\\` → \\`MediaBuyDelivery\\`\n- \\`GetMediaBuysResponse.media_buys\\` → \\`MediaBuy\\`\n- \\`GetSignalsResponse.signals\\` → \\`Signal\\`\n\n(These are the same response types where #624's Sequence widening produces incomplete coverage — the widening is necessary but not sufficient because of this codegen-side issue.)\n\n## Proposed fix\n\nTwo paths:\n\n**A) Codegen-side: prefer cross-file import over local re-emission.** When datamodel-codegen sees that \\`Creative\\` is already defined in a sibling module (e.g. \\`creative/creative_item.py\\` or \\`core/creative.py\\`), import it rather than re-emit. Same shape, same type identity, override compatibility restored.\n\n**B) Post-processor: rewrite all \\`X\\` references in a generated file to import from the canonical module.** A new function in \\`scripts/post_generate_fixes.py\\` that, for each multi-emitted type on an allowlist, replaces local class definitions with \\`from .canonical_module import X\\` and keeps the rest of the file pointing at the imported reference.\n\nApproach A is structurally cleaner; approach B is more contained and safer if the canonical-module mapping is unambiguous.\n\n## Companion to #624\n\nThis issue tracks the type-identity half of the adopter override-pattern friction. #624 (Sequence widening) is required first — without it, even cases where the type identity *is* correct would still hit list-invariance \\`[assignment]\\` errors. After both land, the full Critical Pattern #1 override should typecheck cleanly under mypy --strict with zero \\`# type: ignore\\` lines.\n\n## How surfaced\n\nWhile extending the regression test for #624 to cover required-list overrides (\\`tests/type_checks/extend_response_with_sequence.py\\`), the override of \\`ListCreativesResponse.creatives: list[_InternalCreative]\\` still failed with \\`[assignment]\\` even after Sequence widening. Spike traced the failure to type identity, not variance.\n\n## Related\n\n- #624 — Sequence covariant widening (lands first)\n- salesagent's existing \\`# type: ignore[assignment]\\` lines on \\`creatives\\` overrides remain warranted until this lands","author":{"url":"https://github.com/bokelley","@type":"Person","name":"bokelley"},"datePublished":"2026-05-10T16:58:55Z","url":"https://github.com/adcontextprotocol/adcp-client-python/issues/642"}
| 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:9eb85e5e-ca72-64e2-ffe0-1df40ed0076d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BB1A:1EC9BC:9B9576:C7A90A:6B00F19B |
| html-safe-nonce | e7edd7da8be813917bde155eb3bb949b39d376e66280848e7497761196081fd5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjFBOjFFQzlCQzo5Qjk1NzY6QzdBOTBBOjZCMDBGMTlCIiwidmlzaXRvcl9pZCI6Ijg2MjY0MDY4MTYxMjI3Mjg4NTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | fc1440b6d8d4b31bfff0a46635f1408e1d30e2b27909b2ca745006d6820637fc |
| hovercard-subject-tag | issue:4416241302 |
| 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/642/issue_layout |
| twitter:image | https://opengraph.githubassets.com/70f494e96cf59784c04c1a6e486c5ce6e6da7a073db8e22b20c7f3d872157bf9/adcontextprotocol/adcp-client-python/issues/642 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/70f494e96cf59784c04c1a6e486c5ce6e6da7a073db8e22b20c7f3d872157bf9/adcontextprotocol/adcp-client-python/issues/642 |
| og:image:alt | Problem datamodel-codegen emits subordinate types (`Creative`, `Package`, `MediaBuyDelivery`, etc.) once per response file. The public alias in `adcp.types` resolves to one specific emission, but t... |
| 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