[Python] Modifyl build() method of a polyfactory ModelFactory while ensuring that missing...

Discussão em 'Python' iniciado por Stack, Fevereiro 13, 2025.

  1. Stack

    Stack Membro Participativo

    I have a Pedantic model as below:

    class ModelA(BaseModel):
    field1: str
    field2: Optional[float]
    field3: Optional[Dict[str, Dict[str, float]]] = {}
    field4: Optional[Dict[str, Dict[str, float]]] = {}
    field5: Optional[Dict[str, Dict[str, float]]] = {}


    I want to write a model factory:

    class ModelAFactory(ModelFactory[Any]):
    __model__ = ModelA

    @classmethod
    def build(cls, **kwargs):
    """Use this method to assign default value as {} for fields 3,4 and 5. For other fields model factory can assign random values."""

    Continue reading...

Compartilhe esta Página