fix(python): generate body-variant overloads for a body property named request

Draft
2Y
7d ago
+91-14

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 request become request_ in the expanded overloads, and the argument is mapped back to the model field before unmarshalling (same mechanism as type_ and retries_). The variant gets no Unpack[TypedDict] overload, since its TypedDict key collides with request.
  • rewriteMethodLocals strips the _ suffix from method locals such as request_ when no argument uses the bare name. It now treats names that body-variant overloads suffix as taken, so the overload argument request_ is kept. In those methods the internal request_ local keeps its suffix.
  • Overload and implementation docstrings use the overload argument names: :param request_:, not :param request: The request object to send.. templateMethodComments and getMethodParamDescriptions take an optional list of argument names for this.

Testing

  • tests/specs/fragments/primary/body-variant-overloads.yaml: ReservedFieldNamesVariantB gains a request property.
  • 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-pythonv2 fails at generation with the pyright error above. With it: 814 passed, 0 failed.
  • make check-template-pythonv2 and make lint pass.
  • 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 request property.