MCPcopy
hub / github.com/pydantic/pydantic / test_fastapi_compatibility_hack

Function test_fastapi_compatibility_hack

tests/test_fields.py:269–284  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

267
268
269def test_fastapi_compatibility_hack() -> None:
270 class Body(FieldInfo):
271 """A reproduction of the FastAPI's `Body` param."""
272
273 field = Body()
274 # Assigning after doesn't update `_attributes_set`, which is currently
275 # relied on to merge `FieldInfo` instances during field creation.
276 # This is also what the FastAPI code is doing in some places.
277 # The FastAPI compatibility hack makes it so that it still works.
278 field.default = 1
279
280 Model = create_model('Model', f=(int, field))
281 model_field = Model.model_fields['f']
282
283 assert isinstance(model_field, Body)
284 assert not model_field.is_required()
285
286
287_unsupported_standalone_fieldinfo_attributes = (

Callers

nothing calls this directly

Calls 3

create_modelFunction · 0.90
BodyClass · 0.85
is_requiredMethod · 0.80

Tested by

no test coverage detected