Skip to content

feat: accept Pydantic models as alternatives to dicts in resource client methods#663

Draft
vdusek wants to merge 2 commits intomasterfrom
feat/union-dict-model-types
Draft

feat: accept Pydantic models as alternatives to dicts in resource client methods#663
vdusek wants to merge 2 commits intomasterfrom
feat/union-dict-model-types

Conversation

@vdusek
Copy link
Contributor

@vdusek vdusek commented Mar 6, 2026

Summary

  • Resource client methods that accept dict input parameters now also accept the corresponding Pydantic model from _models.py as a union type (dict | Model)
  • This gives users IDE hints about expected fields without requiring them to import models
  • When a dict is passed, it is validated through the model; when a model is passed, it is serialized to dict for the API call
  • encode_webhook_list_to_base64 updated to accept WebhookCreate models and None directly (with @overload for proper typing)

Changed parameters

File Method Parameter New type
task.py update, start, call, update_input task_input dict | TaskInput
task.py start, call webhooks list[dict | WebhookCreate]
task_collection.py create task_input dict | TaskInput
request_queue.py add_request request dict | RequestDraft
request_queue.py update_request request dict | Request
request_queue.py batch_add_requests requests list[dict | RequestDraft]
actor.py start, call webhooks list[dict | WebhookCreate]

Not changed (no matching model in _models.py)

  • schema: dict in DatasetCollectionClient / KeyValueStoreCollectionClient — JSON Schema, no model
  • batch_delete_requests(requests: list[dict]) — delete only needs IDs, no matching input model

Test plan

  • All 234 unit tests pass
  • Lint, type-check, async docstring sync all pass
  • Verify IDE autocomplete shows model fields when hovering over union types

🤖 Generated with Claude Code

…ent methods

Update resource client methods to accept union types `dict | Model` for
input parameters, giving users IDE hints about expected fields without
requiring model imports. When a Pydantic model is passed, it is serialized
to dict for the API call. When a dict is passed, it is validated through
the model first.

Changes:
- task.py: `task_input: dict | TaskInput`, `webhooks: list[dict | WebhookCreate]`
- task_collection.py: `task_input: dict | TaskInput`
- request_queue.py: `request: dict | RequestDraft` (add), `dict | Request` (update),
  `requests: list[dict | RequestDraft]` (batch_add)
- actor.py: `webhooks: list[dict | WebhookCreate]`
- _utils.py: `encode_webhook_list_to_base64` accepts `WebhookCreate` models and
  `None` via @overload

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vdusek vdusek added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Mar 6, 2026
@vdusek vdusek self-assigned this Mar 6, 2026
@github-actions github-actions bot added this to the 135th sprint - Tooling team milestone Mar 6, 2026
@vdusek vdusek changed the title Accept Pydantic models as alternatives to dicts in resource client methods feat: accept Pydantic models as alternatives to dicts in resource client methods Mar 6, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@danpoletaev danpoletaev force-pushed the feat/union-dict-model-types branch from ac60efe to a1715c9 Compare March 6, 2026 21:55
@B4nan B4nan force-pushed the feat/union-dict-model-types branch from a1715c9 to ac60efe Compare March 6, 2026 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant