Files
pydantic/docs/examples/booleans.py
T
dmontagu 72edca7532 Make bool_validator strict (#617)
* Make bool_validator strict

* incorporate feedback

* Add RelaxedBool

* Fix position in schema.py

* update BoolError message

* Incorporate feedback

* Update history

* Add changes

* Update docs/index.rst

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

* Update docs/index.rst

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

* Update tests/test_types.py

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

* Incorporate feedback

* Update booleans.py

* Remove RelaxedBool

* tweak docs and update changes to new format
2019-08-10 12:00:29 +01:00

34 lines
824 B
Python

from pydantic import BaseModel, StrictBool, ValidationError
class BooleansModel(BaseModel):
standard: bool
strict: StrictBool
print(BooleansModel(standard=False, strict=False))
# BooleansModel standard=False strict=False
print(BooleansModel(standard='False', strict=False))
# BooleansModel standard=False strict=False
try:
BooleansModel(standard='False', strict='False')
except ValidationError as e:
print(str(e))
"""
1 validation error
strict
value is not a valid boolean (type=value_error.strictbool)
"""
print(BooleansModel(standard='False', strict=False))
# BooleansModel standard=False strict=False
try:
BooleansModel(standard=[], strict=False)
except ValidationError as e:
print(str(e))
"""
1 validation error
standard
value could not be parsed to a boolean (type=type_error.bool)
"""