Skip to content

fix: handle bare list annotations in construct_type - #3414

Closed
paksh1 wants to merge 1 commit into
openai:mainfrom
paksh1:paksh/handle-bare-list-construct-type
Closed

fix: handle bare list annotations in construct_type#3414
paksh1 wants to merge 1 commit into
openai:mainfrom
paksh1:paksh/handle-bare-list-construct-type

Conversation

@paksh1

@paksh1 paksh1 commented Jun 21, 2026

Copy link
Copy Markdown

Summary

Fix construct_type() so bare list annotations preserve list values instead of indexing into an empty typing.get_args(list) tuple and raising IndexError.

This mirrors the existing loose-construction behavior: if there is no inner type information to recursively construct, return the value as-is.

Repro

from openai._models import construct_type

construct_type(value=[{"hello": "world"}], type_=list)

Before this change, this raises:

IndexError: tuple index out of range

After this change, it returns the original list.

Tests

  • python -m ruff format src\openai\_models.py tests\test_models.py
  • python -m ruff check src\openai\_models.py tests\test_models.py
  • $env:PYTHONPATH='src'; python -m pytest tests\test_models.py -q -o addopts=""

Copy link
Copy Markdown
Contributor

Thank you for the contribution. The missing type arguments for bare list annotations are now handled in model construction by #3760, which is merged into main.

Closing this PR because the merged change resolves the same crash. Please use a release containing #3760 when available; the fix is not included in v3.11.0.

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.

2 participants