mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
e7227db41a
* starting insert prints * working exec_script * remove prints, fix exec_examples.py * more cleanup of examples, better model printing * upgrade netlify runtime * extra docs deps * few more small tweaks
23 lines
460 B
Python
23 lines
460 B
Python
from enum import Enum, IntEnum
|
|
|
|
from pydantic import BaseModel, ValidationError
|
|
|
|
class FruitEnum(str, Enum):
|
|
pear = 'pear'
|
|
banana = 'banana'
|
|
|
|
class ToolEnum(IntEnum):
|
|
spanner = 1
|
|
wrench = 2
|
|
|
|
class CookingModel(BaseModel):
|
|
fruit: FruitEnum = FruitEnum.pear
|
|
tool: ToolEnum = ToolEnum.spanner
|
|
|
|
print(CookingModel())
|
|
print(CookingModel(tool=2, fruit='banana'))
|
|
try:
|
|
CookingModel(fruit='other')
|
|
except ValidationError as e:
|
|
print(e)
|