feat: accept Pydantic models as alternatives to dicts in resource client methods#663
Draft
feat: accept Pydantic models as alternatives to dicts in resource client methods#663
Conversation
…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>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ac60efe to
a1715c9
Compare
a1715c9 to
ac60efe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dictinput parameters now also accept the corresponding Pydantic model from_models.pyas a union type (dict | Model)encode_webhook_list_to_base64updated to acceptWebhookCreatemodels andNonedirectly (with@overloadfor proper typing)Changed parameters
task.pyupdate,start,call,update_inputtask_inputdict | TaskInputtask.pystart,callwebhookslist[dict | WebhookCreate]task_collection.pycreatetask_inputdict | TaskInputrequest_queue.pyadd_requestrequestdict | RequestDraftrequest_queue.pyupdate_requestrequestdict | Requestrequest_queue.pybatch_add_requestsrequestslist[dict | RequestDraft]actor.pystart,callwebhookslist[dict | WebhookCreate]Not changed (no matching model in
_models.py)schema: dictinDatasetCollectionClient/KeyValueStoreCollectionClient— JSON Schema, no modelbatch_delete_requests(requests: list[dict])— delete only needs IDs, no matching input modelTest plan
🤖 Generated with Claude Code