Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/_bentoml_sdk/io_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ def from_output(cls, func: t.Callable[..., t.Any]) -> type[IODescriptor]:
)
media_type: str | None = None
if is_iterator_type(return_annotation):
return_annotation = get_args(return_annotation)[0]
args = get_args(return_annotation)
return_annotation = args[0] if args else t.Any
elif is_annotated(return_annotation):
content_type = next(
(a for a in get_args(return_annotation) if isinstance(a, ContentType)),
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/_bentoml_sdk/test_io_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from __future__ import annotations

import typing as t

from _bentoml_sdk.io_models import IODescriptor


def test_from_output_bare_iterator_does_not_raise():
"""Bare Iterator/Generator with no type args must not raise IndexError."""

def fn() -> t.Iterator:
yield 1

spec = IODescriptor.from_output(fn)
assert spec is not None