Skip to content

Feature Request: generic/parameterized models #556

Description

@DrPyser

Feature Request

It would be nice to be able construct models by composition, instead of just static descriptions and inheritance-based extension. What I mean by "composition", is being able to define a partial, parameterized model, which can yield new, complete models/validators by combining with other models/validators. This could be done by exploiting something like typing.Generic, e.g.:

import typing
import pydantic

T = typing.TypeVar("T")

class Response(pydantic.GenericModel[T]):
    data: T = ...
    total_count: int = None

and then, one could use Response[MyModel] or Response[List[MyModel]] as validators.

I think support for generic is mentioned in #380.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions