()
| 267 | |
| 268 | |
| 269 | def 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 = ( |
nothing calls this directly
no test coverage detected