field_meta¶
- class polyfactory.field_meta.Constraints[source]¶
Bases:
TypedDictMetadata regarding a type constraints, if any
- class polyfactory.field_meta.FieldMeta[source]¶
Bases:
objectFactory field metadata container. This class is used to store the data about a field of a factory’s model.
- __init__(*, name: str, annotation: type, default: ~typing.Any = <class 'polyfactory.field_meta.Null'>, children: list[~polyfactory.field_meta.FieldMeta] | None = None, constraints: ~polyfactory.field_meta.Constraints | None = None, examples: list[~typing.Any] | None = None, required: bool = True) None[source]¶
Create a factory field metadata instance.
- property type_args: tuple[Any, ...][source]¶
Return the normalized type args of the annotation, if any.
- Returns:
a tuple of types.
- classmethod from_type(annotation: Any, name: str = '', default: Any = <class 'polyfactory.field_meta.Null'>, constraints: Constraints | None = None, children: list[FieldMeta] | None = None, required: bool = True, examples: list[Any] | None = None) Self[source]¶
Builder method to create a FieldMeta from a type annotation.
- classmethod parse_examples(metadata: Sequence[Any]) list[Any] | None[source]¶
Get the example values from the given annotation metadata.
Any metadata object with a non-empty
exampleslist attribute is supported, e.g.msgspec.Metaorpydantic.Field. If several are given, the last one wins.- Parameters:
metadata¶ – A list of annotation metadata.
- Returns:
A list of example values, if any.