You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
types: ergonomics after the RootModel change (cached union validation, list roots, alias names) #1437
Three small type ergonomics we hit moving the Embedded Sales Agent from 8.0.0 to 9.0.0b1. docs/types-9-migration.md covers the semantics; these are about day-to-day use.
Validating a union root needs a hand-rolled cached TypeAdapter. The guide says to use TypeAdapter(X).validate_python(...) for unions such as WholesaleFeedEvent or VendorPricingOptionUnion. Building a TypeAdapter per call is expensive, so every adopter ends up writing the same functools.cache wrapper (we added validate_adcp_union(union, payload)). A public helper (for example adcp.types.validate_union(X, payload) with a cached adapter), or a module-level X_ADAPTER exported beside each union alias, would remove that.
List roots are still RootModel. Scalar roots became str/int subclasses, but list-valued roots still need .root. Two we hit: the delivery status_filter (RootModel[list[MediaBuyStatus]]) and the signal forecast point's dimensions. Code now mixes "read it directly" and "unwrap .root" depending on the root's JSON type. Converting list roots too (as list subclasses or plain list[...] aliases), or listing which roots stay RootModel in the types guide, would make the rule predictable. Related to codegen: a $ref into another file's properties generates a RootModel wrapper, so 27 of TargetingOverlayInput's 37 fields disagree with TargetingOverlay #1362.
Union alias naming is inconsistent between import paths.adcp.types exports VendorPricingOptionUnion, while the generated module calls the same union VendorPricingOption, and adcp.types has no VendorPricingOption. Pick one name, or export both.
Summary
Three small type ergonomics we hit moving the Embedded Sales Agent from 8.0.0 to 9.0.0b1.
docs/types-9-migration.mdcovers the semantics; these are about day-to-day use.TypeAdapter. The guide says to useTypeAdapter(X).validate_python(...)for unions such asWholesaleFeedEventorVendorPricingOptionUnion. Building aTypeAdapterper call is expensive, so every adopter ends up writing the samefunctools.cachewrapper (we addedvalidate_adcp_union(union, payload)). A public helper (for exampleadcp.types.validate_union(X, payload)with a cached adapter), or a module-levelX_ADAPTERexported beside each union alias, would remove that.RootModel. Scalar roots becamestr/intsubclasses, but list-valued roots still need.root. Two we hit: the deliverystatus_filter(RootModel[list[MediaBuyStatus]]) and the signal forecast point'sdimensions. Code now mixes "read it directly" and "unwrap.root" depending on the root's JSON type. Converting list roots too (aslistsubclasses or plainlist[...]aliases), or listing which roots stayRootModelin the types guide, would make the rule predictable. Related to codegen: a$refinto another file'spropertiesgenerates aRootModelwrapper, so 27 ofTargetingOverlayInput's 37 fields disagree withTargetingOverlay#1362.adcp.typesexportsVendorPricingOptionUnion, while the generated module calls the same unionVendorPricingOption, andadcp.typeshas noVendorPricingOption. Pick one name, or export both.