30
30
TypesUnionType = TypingUnionType
31
31
UnionType = TypingUnionType
32
32
33
+ try :
34
+ import annotationlib
35
+
36
+ def get_annotations (obj ):
37
+ return {k : annotationlib .ForwardRef (v ) for k , v in annotationlib .get_annotations (obj , format = annotationlib .Format .STRING ).items ()}
38
+
39
+
40
+ except ImportError :
41
+ def get_annotations (obj ):
42
+ return obj .__annotations__
43
+
33
44
34
45
THIS_DIR = Path (__file__ ).parent
35
46
SAVE_PATH = THIS_DIR / 'src' / 'self_schema.py'
@@ -121,7 +132,7 @@ def type_dict_schema( # noqa: C901
121
132
required_keys = getattr (typed_dict , '__required_keys__' , set ())
122
133
fields = {}
123
134
124
- for field_name , field_type in typed_dict . __annotations__ .items ():
135
+ for field_name , field_type in get_annotations ( typed_dict ) .items ():
125
136
required = field_name in required_keys
126
137
schema = None
127
138
fr_arg = None
@@ -194,7 +205,9 @@ def all_literal_values(type_: type[core_schema.Literal]) -> list[any]:
194
205
195
206
196
207
def eval_forward_ref (type_ : Any ) -> Any :
197
- if sys .version_info < (3 , 12 , 4 ):
208
+ if sys .version_info >= (3 , 14 , 0 ):
209
+ return type_ .evaluate (globals = core_schema .__dict__ )
210
+ elif sys .version_info < (3 , 12 , 4 ):
198
211
return type_ ._evaluate (core_schema .__dict__ , None , recursive_guard = set ())
199
212
else :
200
213
return type_ ._evaluate (core_schema .__dict__ , None , type_params = set (), recursive_guard = set ())
@@ -208,7 +221,7 @@ def main() -> None:
208
221
209
222
choices = {}
210
223
for s in schema_union .__args__ :
211
- type_ = s . __annotations__ ['type' ]
224
+ type_ = get_annotations ( s ) ['type' ]
212
225
m = re .search (r"Literal\['(.+?)']" , type_ .__forward_arg__ )
213
226
assert m , f'Unknown schema type: { type_ } '
214
227
key = m .group (1 )
0 commit comments