fix(client): handle bare dict/list annotations in construct_type and transform#1731
Open
kazuki-netizen wants to merge 1 commit into
Open
fix(client): handle bare dict/list annotations in construct_type and transform#1731kazuki-netizen wants to merge 1 commit into
kazuki-netizen wants to merge 1 commit into
Conversation
…transform Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes #1619, #1626, #1628.
Problem
construct_type()and_transform_recursive/_async_transform_recursiveindex the result ofget_args()unconditionally. For an unparameterized annotation,get_args(dict)andget_args(list)return(), so the index access fails whenever a field is annotated as a baredictorlistinstead ofDict[K, V]/List[T]:construct_type(value={"k": "v"}, type_=dict)→ValueError: not enough values to unpack (expected 2, got 0)(_models.py)construct_type(value=["a", "b"], type_=list)→IndexError: tuple index out of range(_models.py)transform({"k": "v"}, dict)/async_transform({"k": "v"}, dict)→IndexError: tuple index out of range(_utils/_transform.py)Fix
Guard each access and fall back to
objectas the item type when no type parameter is present. This matches the semantics ofDict[str, object]/List[object]: items are returned as-is with no further coercion. Parameterized annotations and the non-mapping / non-list passthrough branches are unchanged.Verification
tests/test_models.pyandtests/test_transform.py(sync + async). They fail onmainand pass with this change.tests/test_models.py+tests/test_transform.py: 122 passed.ruff checkandruff format --checkclean.🤖 Generated with Claude Code