MCPcopy
hub / github.com/pydantic/pydantic / _wrapper2

Function _wrapper2

pydantic/_internal/_decorators_v1.py:153–172  ·  view source on GitHub ↗
(fields_tuple: RootValidatorFieldsTuple, _: core_schema.ValidationInfo)

Source from the content-addressed store, hash-verified

151
152 # mode='after' for pydantic-core
153 def _wrapper2(fields_tuple: RootValidatorFieldsTuple, _: core_schema.ValidationInfo) -> RootValidatorFieldsTuple:
154 if len(fields_tuple) == 2:
155 # dataclass, this is easy
156 values, init_vars = fields_tuple
157 values = validator(values)
158 return values, init_vars
159 else:
160 # ugly hack: to match v1 behaviour, we merge values and model_extra, then split them up based on fields
161 # afterwards
162 model_dict, model_extra, fields_set = fields_tuple
163 if model_extra:
164 fields = set(model_dict.keys())
165 model_dict.update(model_extra)
166 model_dict_new = validator(model_dict)
167 for k in list(model_dict_new.keys()):
168 if k not in fields:
169 model_extra[k] = model_dict_new.pop(k)
170 else:
171 model_dict_new = validator(model_dict)
172 return model_dict_new, model_extra, fields_set
173
174 return _wrapper2

Callers

nothing calls this directly

Calls 3

keysMethod · 0.80
validatorFunction · 0.50
updateMethod · 0.45

Tested by

no test coverage detected