Created
July 13, 2023 08:24
-
-
Save Kludex/1d8c1458d4d9f2e0db56ad6e62792ba9 to your computer and use it in GitHub Desktop.
How to create an `NonEmpty` type with Pydantic by Adrian
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Any, Collection, List, TypeVar, Annotated | |
from annotated_types import MinLen | |
from pydantic import BaseModel | |
_CollectionT = TypeVar("_CollectionT", bound=Collection[Any]) | |
NonEmpty = Annotated[_CollectionT, MinLen(1)] | |
class Book(BaseModel): | |
title: str | |
source_records: NonEmpty[List[NonEmpty[str]]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment