[python] gate TypedDict body overloads behind models-mode typeddict#6
[python] gate TypedDict body overloads behind models-mode typeddict#6l0lawrence wants to merge 1 commit into
Conversation
…mode typeddict In dpg mode the preprocessor inserted a TypedDict body overload (_types.X) for every dpg-model body, but the matching TypedDict was never rendered into types.py for mgmt/autorest libraries. This produced Union[_models.X, _types.X, IO[bytes]] annotations that failed at import time with AttributeError: module '...types' has no attribute 'X'. Restore the historical dpg-mode behavior (accept the model or a raw JSON object via any-object) and only insert TypedDict body overloads when models-mode is typeddict. Update the overload regression tests and changelog accordingly. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
❌ There is undocummented changes. Run The following packages have changes but are not documented.
The following packages have already been documented:
Show changes
|
Why
Stacked on microsoft#10439 (
iscai-msft:python/addTypedDict). That PR introducedmodels-mode: typeddict, but it also turned on part of the TypedDict machinery in the defaultdpgmode: the preprocessor inserted a TypedDict body overload for every dpg-model body. For mgmt/autorest-sourced libraries the matching TypedDict was never rendered intotypes.py, so generated operations ended up annotated as:and importing the module blew up at runtime:
This regressed
azure-mgmt-netapp(breaking-change check failure).What changed
Scope the TypedDict body overload insertion to
models-mode: typeddictonly, inPreProcessPlugin.add_body_param_type:any-object). No_types.Xreference is emitted, so there is nothing to dangle._types.XTypedDict; spread (json-base) bodies still get their TypedDict overload.Because no TypedDict copies are inserted in dpg mode,
is_typed_dict_onlystaysFalse,types.pyis not generated, and no_types.Xreferences can be produced.Notes for reviewers
models-modefor Python HTTP client emitter microsoft/typespec#10439; the substantive change here is confined togenerator/pygen/preprocess/__init__.py, its overload regression tests, and the changelog wording.dpg-> body members['dpg', 'any-object', 'binary'], no typeddict copy in the type listtypeddict-> collapses to single_types.Xtest_dpg_mode_emits_no_typeddict_referenceand updated the dpg regression guard. All 16 typeddict unit tests pass; the broader codegen unit suite is green.models-mode: typeddict(was "Always generate...").