feat: Generate a status-discriminated action attempt union - #632
Merged
Conversation
Bump @seamapi/blueprint to 1.10.0 and consume the new actionAttemptStatuses property annotation. Each action attempt now generates one dataclass per status from its status enum: the status field is typed as the status literal, a property whose annotation lists the status keeps its schema-declared requiredness (so the success class exposes a non-optional result and the error class a non-optional error), and a property whose annotation does not list the status is typed None. action_attempt_from_dict dispatches on the (action_type, status) pair, and per-action-type and per-status Union aliases (e.g. LockDoorActionAttempt, SuccessActionAttempt, PendingActionAttempt, ErrorActionAttempt) cover each single discriminator value. poll_until_ready returns the success union, and the action attempt failed and timeout errors take the error and pending unions. Code that dereferences error or result without narrowing on status stops typechecking; runtime API behavior is unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EdWS7o3htQ9cNxhCWL5Frp
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EdWS7o3htQ9cNxhCWL5Frp
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EdWS7o3htQ9cNxhCWL5Frp
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.
What this means for SDK users
Every action attempt now parses to a class for its exact
(action_type, status)pair, so mypy knows whenerrorandresultare real and when they areNone:Waiting for completion is typed as the success union, no cast needed:
Runtime behavior is unchanged — the API always sent
null; the types just stopped lying about it.How
Bumps
@seamapi/blueprintto ^1.10.0, which annotates each action-attempt property with the statuses that populate it. The existing generated-union mechanism (per-variant dataclasses,Literaldiscriminators, dispatch dict) gains a second axis: 21 action types × 3 statuses = 63 classes, dispatched on the(action_type, status)tuple, with the sameDeepAttrDictfallback for unknown values. Union aliases keep old names importable (LockDoorActionAttempt) and addPendingActionAttempt/SuccessActionAttempt/ErrorActionAttempt. Nothing is keyed off the nameserror/result.Verification
mypy-checked tests cover every snippet above; pytest covers parsing pending/success/error payloads and unknown-status fallback. 185 tests passed, mypy clean (120 files), pylint 10/10. Regeneration from a clean install reproduces the diff exactly; only
seam/resources/action_attempt.pyandseam/resources/__init__.pychanged among generated files.🤖 Generated with Claude Code
https://claude.ai/code/session_01EdWS7o3htQ9cNxhCWL5Frp