mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
18 lines
317 B
Python
18 lines
317 B
Python
from typing import List
|
|
from pydantic import BaseModel
|
|
|
|
|
|
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])
|