MCPcopy
hub / github.com/pydantic/pydantic / enum_process_schema

Function enum_process_schema

pydantic/v1/schema.py:655–678  ·  view source on GitHub ↗

Take a single `enum` and generate its schema. This is similar to the `model_process_schema` function, but applies to ``Enum`` objects.

(enum: Type[Enum], *, field: Optional[ModelField] = None)

Source from the content-addressed store, hash-verified

653
654
655def enum_process_schema(enum: Type[Enum], *, field: Optional[ModelField] = None) -> Dict[str, Any]:
656 """
657 Take a single `enum` and generate its schema.
658
659 This is similar to the `model_process_schema` function, but applies to ``Enum`` objects.
660 """
661 import inspect
662
663 schema_: Dict[str, Any] = {
664 'title': enum.__name__,
665 # Python assigns all enums a default docstring value of 'An enumeration', so
666 # all enums will have a description field even if not explicitly provided.
667 'description': inspect.cleandoc(enum.__doc__ or 'An enumeration.'),
668 # Add enum values and the enum field type to the schema.
669 'enum': [item.value for item in cast(Iterable[Enum], enum)],
670 }
671
672 add_field_type_to_schema(enum, schema_)
673
674 modify_schema = getattr(enum, '__modify_schema__', None)
675 if modify_schema:
676 _apply_modify_schema(modify_schema, field, schema_)
677
678 return schema_
679
680
681def field_singleton_sub_fields_schema(

Callers 2

model_process_schemaFunction · 0.85
field_singleton_schemaFunction · 0.85

Calls 2

add_field_type_to_schemaFunction · 0.85
_apply_modify_schemaFunction · 0.85

Tested by

no test coverage detected