|
3 | 3 | # pyright: reportMissingParameterType=false |
4 | 4 | # pyright: reportUnknownArgumentType=false |
5 | 5 | # pyright: reportUnknownLambdaType=false |
| 6 | +import typing |
6 | 7 | from collections.abc import Callable |
7 | 8 | from dataclasses import dataclass |
8 | 9 | from typing import TYPE_CHECKING, Annotated, Any, Final, NamedTuple, NotRequired, Required, TypedDict |
@@ -295,6 +296,15 @@ def func_dict_list() -> dict[str, list[int]]: # pragma: no cover |
295 | 296 | "title": "func_dict_listDictOutput", |
296 | 297 | } |
297 | 298 |
|
| 299 | + def func_typing_dict() -> typing.Dict[str, str]: # noqa: UP006 # pragma: no cover |
| 300 | + return {"name": "John"} |
| 301 | + |
| 302 | + assert func_metadata(func_typing_dict).output_schema == { |
| 303 | + "type": "object", |
| 304 | + "additionalProperties": {"type": "string"}, |
| 305 | + "title": "func_typing_dictDictOutput", |
| 306 | + } |
| 307 | + |
298 | 308 | # Test dict[int, str] - should be wrapped since key is not str |
299 | 309 | def func_dict_int_key() -> dict[int, str]: # pragma: no cover |
300 | 310 | return {1: "a", 2: "b"} |
@@ -774,6 +784,19 @@ def func_optional() -> str | None: # pragma: no cover |
774 | 784 | "title": "func_optionalOutput", |
775 | 785 | } |
776 | 786 |
|
| 787 | + UserId = typing.NewType("UserId", int) |
| 788 | + |
| 789 | + def func_new_type() -> UserId: # pragma: no cover |
| 790 | + return UserId(1) |
| 791 | + |
| 792 | + meta = func_metadata(func_new_type) |
| 793 | + assert meta.output_schema == { |
| 794 | + "type": "object", |
| 795 | + "properties": {"result": {"title": "Result", "type": "integer"}}, |
| 796 | + "required": ["result"], |
| 797 | + "title": "func_new_typeOutput", |
| 798 | + } |
| 799 | + |
777 | 800 |
|
778 | 801 | def test_structured_output_dataclass(): |
779 | 802 | """Test structured output with dataclass return types""" |
|
0 commit comments