Skip to content

Commit baf9863

Browse files
committed
test type hints
1 parent 0b4f096 commit baf9863

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tests/contrib/test_pydantic.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import uuid
33
from datetime import date, datetime, timedelta
44
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
66

77
from annotated_types import Len
88
from pydantic import BaseModel, Field, WithJsonSchema
@@ -37,6 +37,20 @@ def _check_instance(self):
3737
assert isinstance(self.union_field, str)
3838
assert self.union_field == "my-string"
3939

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+
4054

4155
class PydanticDatetimeModel(BaseModel):
4256
datetime_field: datetime

0 commit comments

Comments
 (0)