Files
pydantic/docs/examples/models_custom_root_access.py
T
2020-04-15 22:53:19 +01:00

16 lines
338 B
Python

from typing import List, Dict
from pydantic import BaseModel, ValidationError
class Pets(BaseModel):
__root__: List[str]
def __iter__(self):
return iter(self.__root__)
def __getitem__(self, item):
return self.__root__[item]
pets = Pets.parse_obj(['dog', 'cat'])
print(pets[0])
print([pet for pet in pets])