field_meta¶
- class polyfactory.field_meta.Constraints[source]¶
Bases:
TypedDict
Metadata regarding a type constraints, if any
- class polyfactory.field_meta.FieldMeta[source]¶
Bases:
object
Factory field metadata container. This class is used to store the data about a field of a factory’s model.
- __init__(*, name: str, annotation: type, random: Random | None = None, default: Any = <class 'polyfactory.field_meta.Null'>, children: list[FieldMeta] | None = None, constraints: Constraints | None = None) None [source]¶
Create a factory field metadata instance.
- property type_args: tuple[Any, ...]¶
Return the normalized type args of the annotation, if any.
- Returns:
a tuple of types.
- classmethod from_type(annotation: Any, random: Random = <random.Random object>, name: str = '', default: Any = <class 'polyfactory.field_meta.Null'>, constraints: Constraints | None = None, randomize_collection_length: bool | None = None, min_collection_length: int | None = None, max_collection_length: int | None = None, children: list[FieldMeta] | None = None) Self [source]¶
Builder method to create a FieldMeta from a type annotation.
- Parameters:
annotation¶ – A type annotation.
random¶ – An instance of random.Random.
name¶ – Field name
default¶ – Default value, if any.
constraints¶ – A dictionary of constraints, if any.
randomize_collection_length¶ – A boolean flag whether to randomize collections lengths
min_collection_length¶ – Minimum number of elements in randomized collection
max_collection_length¶ – Maximum number of elements in randomized collection
- Returns:
A field meta instance.