Coverage for pydantic / _internal / _schema_gather.py: 100.00%
14 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-11-21 11:56 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-11-21 11:56 +0000
1from __future__ import annotations 1abcdefghijklmnopqrs
3from typing import TypedDict 1abcdefghijklmnopqrs
5from pydantic_core._pydantic_core import _schema_gather 1abcdefghijklmnopqrs
6from pydantic_core.core_schema import CoreSchema, DefinitionReferenceSchema 1abcdefghijklmnopqrs
8__all__ = [ 1abcdefghijklmnopqrs
9 'GatherResult',
10 'MissingDefinitionError',
11 'gather_schemas_for_cleaning',
12]
14MissingDefinitionError = _schema_gather.MissingDefinitionError 1abcdefghijklmnopqrs
17class GatherResult(TypedDict): 1abcdefghijklmnopqrs
18 """Schema traversing result."""
20 collected_references: dict[str, DefinitionReferenceSchema | None] 1abcdefghijklmnopqrs
21 """The collected definition references. 1abcdefghijklmnopqrs
23 If a definition reference schema can be inlined, it means that there is
24 only one in the whole core schema. As such, it is stored as the value.
25 Otherwise, the value is set to `None`.
26 """
28 deferred_discriminator_schemas: list[CoreSchema] 1abcdefghijklmnopqrs
29 """The list of core schemas having the discriminator application deferred.""" 1abcdefghijklmnopqrs
32def gather_schemas_for_cleaning(schema: CoreSchema, definitions: dict[str, CoreSchema]) -> GatherResult: 1abcdefghijklmnopqrs
33 """Traverse the core schema and definitions and return the necessary information for schema cleaning.
35 During the core schema traversing, any `'definition-ref'` schema is:
37 - Validated: the reference must point to an existing definition. If this is not the case, a
38 `MissingDefinitionError` exception is raised.
39 - Stored in the context: the actual reference is stored in the context. Depending on whether
40 the `'definition-ref'` schema is encountered more that once, the schema itself is also
41 saved in the context to be inlined (i.e. replaced by the definition it points to).
42 """
43 collected_references, deferred_discriminator_schemas = _schema_gather.gather_schemas_for_cleaning( 1abcdefghijklmnopqrs
44 schema, definitions
45 )
46 return { 1abcdefghijklmnopqrs
47 'collected_references': collected_references,
48 'deferred_discriminator_schemas': deferred_discriminator_schemas,
49 }