@@ -161,27 +161,30 @@ def normalize_value(value: Any) -> Any:
161161 return value
162162
163163 normalized_value = normalize_value (value )
164- return handler (normalized_value )
164+ obj = handler (normalized_value )
165+ assert isinstance (obj , cls )
166+ return obj
165167
166168 @model_validator (mode = "wrap" )
167169 @classmethod
168170 def check_response_attributes_returnability (
169171 cls , value : Any , handler : ValidatorFunctionWrapHandler , info : ValidationInfo
170172 ) -> Self :
171173 """Check that the fields returnability is expected according to the responses validation context, as defined in :rfc:`RFC7643 §7 <7653#section-7>`."""
172- value = handler (value )
174+ obj = handler (value )
175+ assert isinstance (obj , cls )
173176
174177 if (
175178 not info .context
176179 or not info .context .get ("scim" )
177180 or not Context .is_response (info .context ["scim" ])
178181 ):
179- return value
182+ return obj
180183
181184 for field_name in cls .model_fields :
182185 returnability = cls .get_field_annotation (field_name , Returned )
183186
184- if returnability == Returned .always and getattr (value , field_name ) is None :
187+ if returnability == Returned .always and getattr (obj , field_name ) is None :
185188 raise PydanticCustomError (
186189 "returned_error" ,
187190 "Field '{field_name}' has returnability 'always' but value is missing or null" ,
@@ -190,10 +193,7 @@ def check_response_attributes_returnability(
190193 },
191194 )
192195
193- if (
194- returnability == Returned .never
195- and getattr (value , field_name ) is not None
196- ):
196+ if returnability == Returned .never and getattr (obj , field_name ) is not None :
197197 raise PydanticCustomError (
198198 "returned_error" ,
199199 "Field '{field_name}' has returnability 'never' but value is set" ,
@@ -202,15 +202,16 @@ def check_response_attributes_returnability(
202202 },
203203 )
204204
205- return value
205+ return obj
206206
207207 @model_validator (mode = "wrap" )
208208 @classmethod
209209 def check_response_attributes_necessity (
210210 cls , value : Any , handler : ValidatorFunctionWrapHandler , info : ValidationInfo
211211 ) -> Self :
212212 """Check that the required attributes are present in creations and replacement requests."""
213- value = handler (value )
213+ obj = handler (value )
214+ assert isinstance (obj , cls )
214215
215216 if (
216217 not info .context
@@ -221,12 +222,12 @@ def check_response_attributes_necessity(
221222 Context .RESOURCE_REPLACEMENT_REQUEST ,
222223 )
223224 ):
224- return value
225+ return obj
225226
226227 for field_name in cls .model_fields :
227228 necessity = cls .get_field_annotation (field_name , Required )
228229
229- if necessity == Required .true and getattr (value , field_name ) is None :
230+ if necessity == Required .true and getattr (obj , field_name ) is None :
230231 raise PydanticCustomError (
231232 "required_error" ,
232233 "Field '{field_name}' is required but value is missing or null" ,
@@ -235,7 +236,7 @@ def check_response_attributes_necessity(
235236 },
236237 )
237238
238- return value
239+ return obj
239240
240241 @model_validator (mode = "wrap" )
241242 @classmethod
@@ -245,7 +246,8 @@ def check_replacement_request_mutability(
245246 """Check if 'immutable' attributes have been mutated in replacement requests."""
246247 from scim2_models .rfc7643 .resource import Resource
247248
248- value = handler (value )
249+ obj = handler (value )
250+ assert isinstance (obj , cls )
249251
250252 context = info .context .get ("scim" ) if info .context else None
251253 original = info .context .get ("original" ) if info .context else None
@@ -254,8 +256,8 @@ def check_replacement_request_mutability(
254256 and issubclass (cls , Resource )
255257 and original is not None
256258 ):
257- cls .check_mutability_issues (original , value )
258- return value
259+ cls .check_mutability_issues (original , obj )
260+ return obj
259261
260262 @classmethod
261263 def check_mutability_issues (
@@ -403,7 +405,7 @@ def model_serializer_exclude_none(
403405 @classmethod
404406 def model_validate (
405407 cls ,
406- * args ,
408+ * args : Any ,
407409 scim_ctx : Optional [Context ] = Context .DEFAULT ,
408410 original : Optional ["BaseModel" ] = None ,
409411 ** kwargs : Any ,
@@ -443,6 +445,3 @@ def get_attribute_urn(self, field_name: str) -> str:
443445 else f"{ main_schema } :{ alias } "
444446 )
445447 return full_urn
446-
447-
448- BaseModelType : type = type (BaseModel )
0 commit comments