|
2 | 2 | import uuid |
3 | 3 | from datetime import date, datetime, timedelta |
4 | 4 | from ipaddress import IPv4Address |
5 | | -from typing import Annotated, Any, List, Sequence, Tuple, TypeVar, Union |
| 5 | +from typing import Annotated, Any, List, Sequence, Tuple, TypeVar, Union, get_type_hints |
6 | 6 |
|
7 | 7 | from annotated_types import Len |
8 | 8 | from pydantic import BaseModel, Field, WithJsonSchema |
@@ -37,6 +37,20 @@ def _check_instance(self): |
37 | 37 | assert isinstance(self.union_field, str) |
38 | 38 | assert self.union_field == "my-string" |
39 | 39 |
|
| 40 | + assert get_type_hints(self) == { |
| 41 | + "ip_field": IPv4Address, |
| 42 | + "string_field_assigned_field": str, |
| 43 | + "string_field_with_default": str, |
| 44 | + "annotated_list_of_str": List[str], |
| 45 | + "str_short_sequence": List[str], |
| 46 | + # TODO: why not |
| 47 | + # "annotated_list_of_str": Annotated[ |
| 48 | + # List[str], Field(), WithJsonSchema({"extra": "data"}) |
| 49 | + # ], |
| 50 | + # "str_short_sequence": ShortSequence[List[str]], |
| 51 | + "union_field": Union[int, str], |
| 52 | + } |
| 53 | + |
40 | 54 |
|
41 | 55 | class PydanticDatetimeModel(BaseModel): |
42 | 56 | datetime_field: datetime |
|
0 commit comments