mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
21 lines
436 B
Python
21 lines
436 B
Python
from pydantic import BaseModel, ValidationError
|
|
|
|
class BooleanModel(BaseModel):
|
|
bool_value: bool
|
|
|
|
print(BooleanModel(bool_value=False))
|
|
#> BooleansModel bool_value=False
|
|
|
|
print(BooleanModel(bool_value='False'))
|
|
#> BooleansModel bool_value=False
|
|
|
|
try:
|
|
BooleanModel(bool_value=[])
|
|
except ValidationError as e:
|
|
print(str(e))
|
|
"""
|
|
1 validation error
|
|
bool_value
|
|
value could not be parsed to a boolean (type=type_error.bool)
|
|
"""
|