Skip to content

fix(_transform): guard bare dict annotation to avoid IndexError#1629

Open
devteamaegis wants to merge 1 commit into
anthropics:mainfrom
devteamaegis:fix/indexerror-on-unparameterized-bare-dict-
Open

fix(_transform): guard bare dict annotation to avoid IndexError#1629
devteamaegis wants to merge 1 commit into
anthropics:mainfrom
devteamaegis:fix/indexerror-on-unparameterized-bare-dict-

Conversation

@devteamaegis
Copy link
Copy Markdown

What's broken

transform({"key": "value"}, dict) raises IndexError: tuple index out of range in _transform_recursive (line 183) and _async_transform_recursive (line 349). Both branches unconditionally access get_args(stripped_type)[1] to get the value type. When the annotation is a bare dict rather than Dict[K, V], get_args(dict) returns (), so the index fails.

IndexError: tuple index out of range
  File "_transform.py", line 183, in _transform_recursive
    items_type = get_args(stripped_type)[1]

Why it happens

get_args on an unparameterized dict returns an empty tuple, and the code assumed at least two type arguments were always present.

Fix

Added a len(args) >= 2 guard before indexing. Falls back to Any for 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_error which calls transform({"key": "value"}, dict) for both sync and async paths and asserts no exception and correct output.

Fixes #1628

…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>
@devteamaegis devteamaegis requested a review from a team as a code owner June 1, 2026 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexError on bare (unparameterized) dict annotation in _transform_recursive

1 participant