feat(types): export EffortLevel as a named type alias#953
Open
bugbubug wants to merge 1 commit into
Open
Conversation
The effort field's Literal["low", "medium", "high", "xhigh", "max"] was inlined at every use site in types.py. Promote it to a named alias EffortLevel, mirroring the existing pattern used for PermissionMode, SdkBeta, SettingSource, etc. - Add EffortLevel alias near the other top-level aliases in types.py - Reuse it in AgentDefinition.effort and ClaudeAgentOptions thinking effort - Export EffortLevel from the package __init__ so downstream wrappers can import it and stay in sync when the literal expands (e.g. "xhigh" added between 0.1.71 and 0.1.77, see anthropics#834) Closes anthropics#938
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
Promote the inlined
Literal["low", "medium", "high", "xhigh", "max"]used by theeffortfield into a named aliasEffortLevel, mirroring the existing pattern used forPermissionMode,SdkBeta,SettingSource, etc.Closes #938.
Motivation
The
effortliteral is currently inlined at two sites intypes.py:AgentDefinition.effort(line 99)ClaudeAgentOptionsthinkingeffort(line 1867)Every other small literal of the same shape in this file is already exported as a named alias. Inlining
effortmakes the SDK inconsistent with itself and forces downstream wrappers (e.g. internal agent frameworks, third-party libraries) to either duplicate the literal or maintain a private alias that drifts on every SDK release.The literal is in fact moving:
"xhigh"was added between0.1.71and0.1.77(see #834). A named alias makes any future expansion propagate automatically to all downstream consumers viafrom claude_agent_sdk import EffortLevel.Changes
src/claude_agent_sdk/types.pyEffortLevel = Literal["low", "medium", "high", "xhigh", "max"]near the other top-level aliases.EffortLevel.src/claude_agent_sdk/__init__.pyEffortLevelfrom the package alongsidePermissionMode,SettingSource,SdkBeta, etc.The alias follows the same
Name = Literal[...]style asPermissionMode/SdkBeta/SettingSourcerather than the explicit: TypeAliasannotation, to stay consistent with the surrounding file.Verification
Ran the full local quality gate per
CLAUDE.md:The 2 failing tests (
test_transcript_mirror.py::TestBuildMirrorBatcherFlushMode::test_eager_mode_flushes_per_frameandTestReceiveLoopFramePeeling::test_eager_flush_mode_appends_per_frame_before_result) also fail onmainat the current HEAD without these changes, so they are pre-existing and unrelated.Also smoke-tested the new public export:
Notes
No runtime behavior changes — this is a pure type-only refactor. No tests were added since the change is a structural rename of an existing
Literaland is covered bymypy strictonsrc/.