|
1 | 1 | from collections.abc import Generator |
2 | | -from typing import TYPE_CHECKING, Any, Callable, Protocol, TypeVar, overload |
| 2 | +from typing import TYPE_CHECKING, Any, Callable, Protocol, TypeVar |
| 3 | +from typing_extensions import TypeForm |
3 | 4 |
|
4 | 5 | from pydantic import VERSION |
5 | 6 |
|
@@ -36,24 +37,10 @@ class GitHubModel(BaseModel): |
36 | 37 | class ExtraGitHubModel(GitHubModel): |
37 | 38 | model_config = ConfigDict(extra="allow") |
38 | 39 |
|
39 | | - # Remove the overload once [PEP747](https://peps.python.org/pep-0747/) is accepted |
40 | | - # We should use TypeForm here |
41 | | - @overload |
42 | | - def type_validate_python(type_: type[T], data: Any) -> T: ... |
43 | | - |
44 | | - @overload |
45 | | - def type_validate_python(type_: Any, data: Any) -> Any: ... |
46 | | - |
47 | | - def type_validate_python(type_: type[T], data: Any) -> T: |
| 40 | + def type_validate_python(type_: TypeForm[T], data: Any) -> T: |
48 | 41 | return TypeAdapter(type_).validate_python(data) |
49 | 42 |
|
50 | | - @overload |
51 | | - def type_validate_json(type_: type[T], data: Any) -> T: ... |
52 | | - |
53 | | - @overload |
54 | | - def type_validate_json(type_: Any, data: Any) -> Any: ... |
55 | | - |
56 | | - def type_validate_json(type_: type[T], data: Any) -> T: |
| 43 | + def type_validate_json(type_: TypeForm[T], data: Any) -> T: |
57 | 44 | return TypeAdapter(type_).validate_json(data) |
58 | 45 |
|
59 | 46 | def model_dump(model: BaseModel, by_alias: bool = True) -> dict[str, Any]: |
@@ -97,22 +84,10 @@ class ExtraGitHubModel(BaseModel): |
97 | 84 | class Config: |
98 | 85 | extra = Extra.allow |
99 | 86 |
|
100 | | - @overload |
101 | | - def type_validate_python(type_: type[T], data: Any) -> T: ... |
102 | | - |
103 | | - @overload |
104 | | - def type_validate_python(type_: Any, data: Any) -> Any: ... |
105 | | - |
106 | | - def type_validate_python(type_: type[T], data: Any) -> T: |
| 87 | + def type_validate_python(type_: TypeForm[T], data: Any) -> T: |
107 | 88 | return parse_obj_as(type_, data) |
108 | 89 |
|
109 | | - @overload |
110 | | - def type_validate_json(type_: type[T], data: Any) -> T: ... |
111 | | - |
112 | | - @overload |
113 | | - def type_validate_json(type_: Any, data: Any) -> Any: ... |
114 | | - |
115 | | - def type_validate_json(type_: type[T], data: Any) -> T: |
| 90 | + def type_validate_json(type_: TypeForm[T], data: Any) -> T: |
116 | 91 | return parse_raw_as(type_, data) |
117 | 92 |
|
118 | 93 | def to_jsonable_python(obj: Any) -> Any: |
|
0 commit comments