2
2
3
3
import sys
4
4
from datetime import date , datetime , time
5
- from typing import Any , Callable , Dict , List , Sequence , Union
5
+ from typing import Any , Callable , Dict , List , Union
6
6
7
7
if sys .version_info < (3 , 11 ):
8
8
from typing_extensions import NotRequired , Required
9
9
else :
10
- from typing import NotRequired
10
+ from typing import NotRequired , Required
11
11
12
12
if sys .version_info < (3 , 8 ):
13
13
from typing_extensions import Literal , TypedDict
@@ -19,9 +19,10 @@ class AnySchema(TypedDict):
19
19
type : Literal ['any' ]
20
20
21
21
22
- class BoolSchema (TypedDict ):
23
- type : Literal ['bool' ]
24
- strict : NotRequired [bool ]
22
+ class BoolSchema (TypedDict , total = False ):
23
+ type : Required [Literal ['bool' ]]
24
+ strict : bool
25
+ ref : str
25
26
26
27
27
28
class ConfigSchema (TypedDict , total = False ):
@@ -39,6 +40,7 @@ class DictSchema(TypedDict, total=False):
39
40
min_items : int
40
41
max_items : int
41
42
strict : bool
43
+ ref : str
42
44
43
45
44
46
class FloatSchema (TypedDict , total = False ):
@@ -49,20 +51,22 @@ class FloatSchema(TypedDict, total=False):
49
51
lt : float
50
52
gt : float
51
53
strict : bool
52
- default : float
54
+ ref : str
53
55
54
56
55
57
class FunctionSchema (TypedDict ):
56
58
type : Literal ['function' ]
57
59
mode : Literal ['before' , 'after' , 'wrap' ]
58
60
function : Callable [..., Any ]
59
61
schema : Schema
62
+ ref : NotRequired [str ]
60
63
61
64
62
65
class FunctionPlainSchema (TypedDict ):
63
66
type : Literal ['function' ]
64
67
mode : Literal ['plain' ]
65
68
function : Callable [..., Any ]
69
+ ref : NotRequired [str ]
66
70
67
71
68
72
class IntSchema (TypedDict , total = False ):
@@ -73,6 +77,7 @@ class IntSchema(TypedDict, total=False):
73
77
lt : int
74
78
gt : int
75
79
strict : bool
80
+ ref : str
76
81
77
82
78
83
class ListSchema (TypedDict , total = False ):
@@ -81,17 +86,20 @@ class ListSchema(TypedDict, total=False):
81
86
min_items : int
82
87
max_items : int
83
88
strict : bool
89
+ ref : str
84
90
85
91
86
92
class LiteralSchema (TypedDict ):
87
93
type : Literal ['literal' ]
88
- expected : Sequence [Any ]
94
+ expected : List [Any ]
95
+ ref : NotRequired [str ]
89
96
90
97
91
98
class ModelClassSchema (TypedDict ):
92
99
type : Literal ['model-class' ]
93
100
class_type : type
94
101
schema : TypedDictSchema
102
+ ref : NotRequired [str ]
95
103
96
104
97
105
class TypedDictField (TypedDict , total = False ):
@@ -102,33 +110,30 @@ class TypedDictField(TypedDict, total=False):
102
110
aliases : List [List [Union [str , int ]]]
103
111
104
112
105
- class TypedDictSchema (TypedDict ):
106
- type : Literal ['typed-dict' ]
107
- fields : Dict [str , TypedDictField ]
108
- extra_validator : NotRequired [Schema ]
109
- config : NotRequired [ConfigSchema ]
110
- return_fields_set : NotRequired [bool ]
113
+ class TypedDictSchema (TypedDict , total = False ):
114
+ type : Required [Literal ['typed-dict' ]]
115
+ fields : Required [Dict [str , TypedDictField ]]
116
+ extra_validator : Schema
117
+ config : ConfigSchema
118
+ return_fields_set : bool
119
+ ref : str
111
120
112
121
113
122
class NoneSchema (TypedDict ):
114
123
type : Literal ['none' ]
124
+ ref : NotRequired [str ]
115
125
116
126
117
- class NullableSchema (TypedDict ):
118
- type : Literal ['nullable' ]
119
- schema : Schema
120
- strict : NotRequired [bool ]
127
+ class NullableSchema (TypedDict , total = False ):
128
+ type : Required [Literal ['nullable' ]]
129
+ schema : Required [Schema ]
130
+ strict : bool
131
+ ref : str
121
132
122
133
123
134
class RecursiveReferenceSchema (TypedDict ):
124
135
type : Literal ['recursive-ref' ]
125
- name : str
126
-
127
-
128
- class RecursiveContainerSchema (TypedDict ):
129
- type : Literal ['recursive-container' ]
130
- name : str
131
- schema : Schema
136
+ schema_ref : str
132
137
133
138
134
139
class SetSchema (TypedDict , total = False ):
@@ -137,6 +142,7 @@ class SetSchema(TypedDict, total=False):
137
142
min_items : int
138
143
max_items : int
139
144
strict : bool
145
+ ref : str
140
146
141
147
142
148
class FrozenSetSchema (TypedDict , total = False ):
@@ -145,6 +151,7 @@ class FrozenSetSchema(TypedDict, total=False):
145
151
min_items : int
146
152
max_items : int
147
153
strict : bool
154
+ ref : str
148
155
149
156
150
157
class StringSchema (TypedDict , total = False ):
@@ -156,20 +163,22 @@ class StringSchema(TypedDict, total=False):
156
163
to_lower : bool
157
164
to_upper : bool
158
165
strict : bool
166
+ ref : str
159
167
160
168
161
- class UnionSchema (TypedDict ):
162
- type : Literal ['union' ]
163
- choices : List [Schema ]
164
- strict : NotRequired [ bool ]
165
- default : NotRequired [ Any ]
169
+ class UnionSchema (TypedDict , total = False ):
170
+ type : Required [ Literal ['union' ] ]
171
+ choices : Required [ List [Schema ] ]
172
+ strict : bool
173
+ ref : str
166
174
167
175
168
176
class BytesSchema (TypedDict , total = False ):
169
177
type : Required [Literal ['bytes' ]]
170
178
max_length : int
171
179
min_length : int
172
180
strict : bool
181
+ ref : str
173
182
174
183
175
184
class DateSchema (TypedDict , total = False ):
@@ -179,7 +188,7 @@ class DateSchema(TypedDict, total=False):
179
188
ge : date
180
189
lt : date
181
190
gt : date
182
- default : date
191
+ ref : str
183
192
184
193
185
194
class TimeSchema (TypedDict , total = False ):
@@ -189,7 +198,7 @@ class TimeSchema(TypedDict, total=False):
189
198
ge : time
190
199
lt : time
191
200
gt : time
192
- default : time
201
+ ref : str
193
202
194
203
195
204
class DatetimeSchema (TypedDict , total = False ):
@@ -199,13 +208,14 @@ class DatetimeSchema(TypedDict, total=False):
199
208
ge : datetime
200
209
lt : datetime
201
210
gt : datetime
202
- default : datetime
211
+ ref : str
203
212
204
213
205
- class TupleFixLenSchema (TypedDict ):
206
- type : Literal ['tuple-fix-len' ]
207
- items_schema : List [Schema ]
208
- strict : NotRequired [bool ]
214
+ class TupleFixLenSchema (TypedDict , total = False ):
215
+ type : Required [Literal ['tuple-fix-len' ]]
216
+ items_schema : Required [List [Schema ]]
217
+ strict : bool
218
+ ref : str
209
219
210
220
211
221
class TupleVarLenSchema (TypedDict , total = False ):
@@ -214,6 +224,7 @@ class TupleVarLenSchema(TypedDict, total=False):
214
224
min_items : int
215
225
max_items : int
216
226
strict : bool
227
+ ref : str
217
228
218
229
219
230
# pydantic allows types to be defined via a simple string instead of dict with just `type`, e.g.
@@ -256,7 +267,6 @@ class TupleVarLenSchema(TypedDict, total=False):
256
267
ModelClassSchema ,
257
268
NoneSchema ,
258
269
NullableSchema ,
259
- RecursiveContainerSchema ,
260
270
RecursiveReferenceSchema ,
261
271
SetSchema ,
262
272
FrozenSetSchema ,
0 commit comments