fix(python): generate body-variant overloads for a body property named request
Draft
2Y
7d ago+91+91+01234567890123456789-14-14-01234567890123456789
Stacked on #189.
Why
With bodyVariantOverloads, pythonv2 flattens each variant of a oneOf-of-objects request body into keyword arguments. A variant property named request became an overload argument request: <type>, while the implementation takes the whole request as request: OptionalNullable[<Request>]. pyright reported Overloaded implementation is not consistent with signature of overload, and generation failed.
What changed
- Body properties named
requestbecomerequest_in the expanded overloads, and the argument is mapped back to the model field before unmarshalling (same mechanism astype_andretries_). The variant gets noUnpack[TypedDict]overload, since its TypedDict key collides withrequest. rewriteMethodLocalsstrips the_suffix from method locals such asrequest_when no argument uses the bare name. It now treats names that body-variant overloads suffix as taken, so the overload argumentrequest_is kept. In those methods the internalrequest_local keeps its suffix.- Overload and implementation docstrings use the overload argument names:
:param request_:, not:param request: The request object to send..templateMethodCommentsandgetMethodParamDescriptionstake an optional list of argument names for this.
Testing
tests/specs/fragments/primary/body-variant-overloads.yaml:ReservedFieldNamesVariantBgains arequestproperty.test_body_variant_overloads.py:request_="r"is sent as"request": "r";- the overload signature has
request_: Optional[str] = ...and the docstring lists:param request_:.
- Without the fix,
TARGET=primary make test-pythonv2fails at generation with the pyright error above. With it: 814 passed, 0 failed. make check-template-pythonv2andmake lintpass.- Not run: other targets. The fixture change adds a string property to a shared schema.
Public-safety check
- This change contains no credentials, customer documents, private repository URLs, private filesystem paths, or unredacted private logs.
- Title, body, comments, and commit messages name no customers or customer-derived identifiers, private paths or trackers, or workflow provenance, and are understandable without private context (
.claude/skills/public-repo-communication/SKILL.md). - Generated fixtures and review SDK changes are public-safe.
- I reviewed
git diff --check.
Summary by cubic
Fixes Python SDK generation failing when a body-variant overload declares a body property named request, which collided with the implementation's whole-request parameter and made pyright reject the overloaded signature.
- The property is renamed to
request_in expanded overloads and mapped back to the request body when sending. - Method-local rewriting keeps the
request_suffix in these methods, and overload docstrings use the renamed argument name. - Adds test fixture and coverage for a body variant with a
requestproperty.