fix(_transform): guard bare dict annotation to avoid IndexError#1629
Open
devteamaegis wants to merge 1 commit into
Open
fix(_transform): guard bare dict annotation to avoid IndexError#1629devteamaegis wants to merge 1 commit into
devteamaegis wants to merge 1 commit into
Conversation
…xError When `_transform_recursive` (sync and async) receives a bare `dict` annotation (not `Dict[K, V]`), `get_args(dict)` returns `()` so indexing `[1]` raises `IndexError: tuple index out of range`. Guard the index with `len(args) >= 2`, falling back to `Any` for unparameterized dicts — matching the pattern already used in `_models.py`. Co-Authored-By: claude-flow <ruv@ruv.net>
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's broken
transform({"key": "value"}, dict)raisesIndexError: tuple index out of rangein_transform_recursive(line 183) and_async_transform_recursive(line 349). Both branches unconditionally accessget_args(stripped_type)[1]to get the value type. When the annotation is a baredictrather thanDict[K, V],get_args(dict)returns(), so the index fails.Why it happens
get_argson an unparameterizeddictreturns an empty tuple, and the code assumed at least two type arguments were always present.Fix
Added a
len(args) >= 2guard before indexing. Falls back toAnyfor bare dicts, matching the same pattern already used in_models.py. Both sync and async variants are fixed.Test
Added
test_transform_recursive_bare_dict_no_index_errorwhich callstransform({"key": "value"}, dict)for both sync and async paths and asserts no exception and correct output.Fixes #1628