mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
72edca7532
* 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
34 lines
824 B
Python
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)
|
|
"""
|