MCPcopy
hub / github.com/pydantic/pydantic / _annotated_schema

Method _annotated_schema

pydantic/_internal/_generate_schema.py:2195–2208  ·  view source on GitHub ↗

Generate schema for an Annotated type, e.g. `Annotated[int, Field(...)]` or `Annotated[int, Gt(0)]`.

(self, annotated_type: Any)

Source from the content-addressed store, hash-verified

2193 )
2194
2195 def _annotated_schema(self, annotated_type: Any) -> core_schema.CoreSchema:
2196 """Generate schema for an Annotated type, e.g. `Annotated[int, Field(...)]` or `Annotated[int, Gt(0)]`."""
2197 FieldInfo = import_cached_field_info()
2198 source_type, *annotations = self._get_args_resolving_forward_refs(
2199 annotated_type,
2200 required=True,
2201 )
2202 schema = self._apply_annotations(source_type, annotations)
2203 # put the default validator last so that TypeAdapter.get_default_value() works
2204 # even if there are function validators involved
2205 for annotation in annotations:
2206 if isinstance(annotation, FieldInfo):
2207 schema = wrap_default(annotation, schema)
2208 return schema
2209
2210 def _apply_annotations(
2211 self,

Callers 1

Calls 4

_apply_annotationsMethod · 0.95
import_cached_field_infoFunction · 0.85
wrap_defaultFunction · 0.85

Tested by

no test coverage detected