@@ -46,6 +46,7 @@ def create_partial_model(
46
46
base_cls : type [SelfT ],
47
47
* fields : str ,
48
48
recursive : bool = False ,
49
+ partial_cls_name : Optional [str ] = None ,
49
50
) -> type [SelfT ]:
50
51
# Convert one type to being partial - if possible
51
52
def _partial_annotation_arg (field_name_ : str , field_annotation : type ) -> type :
@@ -128,9 +129,12 @@ def _partial_annotation_arg(field_name_: str, field_annotation: type) -> type:
128
129
if not optional_fields :
129
130
return base_cls
130
131
132
+ if partial_cls_name is None :
133
+ partial_cls_name = f"{ base_cls .__name__ } Partial"
134
+
131
135
# Generate new subclass model with those optional fields
132
136
return pydantic .create_model (
133
- f" { base_cls . __name__ } Partial" ,
137
+ partial_cls_name ,
134
138
__base__ = base_cls ,
135
139
** optional_fields ,
136
140
)
@@ -147,21 +151,23 @@ def model_as_partial(
147
151
cls : type [ModelSelfT ],
148
152
* fields : str ,
149
153
recursive : bool = False ,
154
+ partial_cls_name : Optional [str ] = None ,
150
155
) -> type [ModelSelfT ]:
151
156
return cast (
152
157
type [ModelSelfT ],
153
- create_partial_model (cls , * fields , recursive = recursive ),
158
+ create_partial_model (cls , * fields , recursive = recursive , partial_cls_name = partial_cls_name ),
154
159
)
155
160
156
161
@classmethod
157
162
def as_partial (
158
163
cls : type [ModelSelfT ],
159
164
* fields : str ,
160
165
recursive : bool = False ,
166
+ partial_cls_name : Optional [str ] = None ,
161
167
) -> type [ModelSelfT ]:
162
168
warnings .warn (
163
169
"as_partial(...) is deprecated, use model_as_partial(...) instead" ,
164
170
DeprecationWarning ,
165
171
stacklevel = 2 ,
166
172
)
167
- return cls .model_as_partial (* fields , recursive = recursive )
173
+ return cls .model_as_partial (* fields , recursive = recursive , partial_cls_name = partial_cls_name )
0 commit comments