MCPcopy
hub / github.com/pydantic/pydantic / bench

Function bench

tests/benchmarks/test_fastapi_startup_generics.py:102–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

100 assert len(data_models) == INNER_DATA_MODEL_COUNT + OUTER_DATA_MODEL_COUNT
101
102 def bench():
103 concrete_api_models = []
104 adapters = []
105 for outer_api_model in api_models:
106 for data_model in data_models:
107 concrete_api_model = outer_api_model[
108 data_model
109 ] # Would be used eg as request or response body in FastAPI
110 concrete_api_models.append(concrete_api_model)
111
112 # Emulate FastAPI creating its TypeAdapters
113 adapt = TypeAdapter(Annotated[concrete_api_model, FieldInfo(description='foo')])
114 adapters.append(adapt)
115 adapt = TypeAdapter(Annotated[concrete_api_model, FieldInfo(description='bar')])
116 adapters.append(adapt)
117
118 assert len(concrete_api_models) == len(data_models) * len(api_models)
119 assert len(adapters) == len(concrete_api_models) * 2
120
121 benchmark(bench)
122

Callers

nothing calls this directly

Calls 2

TypeAdapterClass · 0.90
FieldInfoClass · 0.90

Tested by

no test coverage detected