MCPcopy Create free account
hub / github.com/livekit/agents / _build_patch_cache

Function _build_patch_cache

tests/virtual_time.py:135–150  ·  view source on GitHub ↗

Construct, once, a virtual-clock validator for every model with a captured real clock.

()

Source from the content-addressed store, hash-verified

133
134
135def _build_patch_cache() -> None:
136 """Construct, once, a virtual-clock validator for every model with a captured real clock."""
137 if _PATCHED:
138 return
139 from pydantic_core import SchemaValidator
140
141 for model, fields in _discover_factory_patches().items():
142 schema = _to_plain(model.__pydantic_core_schema__)
143 node = _model_node(schema)
144 field_schemas = node["schema"]["fields"]
145 for name, factory in fields.items():
146 field_schemas[name]["schema"]["default_factory"] = factory
147 # _use_prebuilt=False forces a build from our edited schema instead of reusing the
148 # validator cached on the class.
149 patched = SchemaValidator(schema, node.get("config"), _use_prebuilt=False)
150 _PATCHED[model] = (patched, model.__pydantic_validator__)
151
152
153@contextlib.contextmanager

Callers 1

_patched_model_clocksFunction · 0.85

Calls 5

_to_plainFunction · 0.85
_model_nodeFunction · 0.85
itemsMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected