11
11
from collections .abc import Callable
12
12
from datetime import date , datetime , time , timedelta
13
13
from pathlib import Path
14
- from typing import TYPE_CHECKING , Any , Dict , ForwardRef , List , Set , Type , TypeVar , Union
14
+ from typing import TYPE_CHECKING , Any , Dict , ForwardRef , List , Set , Type , Union
15
15
16
- from typing_extensions import TypeVar as TeTypeVar
17
16
from typing_extensions import get_args , get_origin , is_typeddict
18
17
19
18
TypingUnionType = Type [Union [str , int ]]
44
43
schema_ref_validator = {'type' : 'definition-ref' , 'schema_ref' : 'root-schema' }
45
44
46
45
47
- def get_schema (obj ) -> core_schema .CoreSchema : # noqa: C901
46
+ def get_schema (obj ) -> core_schema .CoreSchema :
48
47
if isinstance (obj , str ):
49
48
return {'type' : obj }
50
49
elif obj in (datetime , timedelta , date , time , bool , int , float , str ):
@@ -53,18 +52,13 @@ def get_schema(obj) -> core_schema.CoreSchema: # noqa: C901
53
52
return type_dict_schema (obj )
54
53
elif obj == Any or obj == type :
55
54
return {'type' : 'any' }
56
- elif isinstance (obj , (TypeVar , TeTypeVar )):
57
- return {'type' : 'any' }
58
55
if isinstance (obj , type ) and issubclass (obj , core_schema .Protocol ):
59
56
return {'type' : 'callable' }
60
57
61
58
origin = get_origin (obj )
62
59
assert origin is not None , f'origin cannot be None, obj={ obj } , you probably need to fix generate_self_schema.py'
63
60
if origin is Union :
64
61
return union_schema (obj )
65
- elif is_typeddict (origin ):
66
- # a generic typeddict
67
- return get_schema (origin )
68
62
elif obj is Callable or origin is Callable :
69
63
return {'type' : 'callable' }
70
64
elif origin is core_schema .Literal :
0 commit comments