mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
c81ec9aeec
* add support for annotation only fields, fix #34 * adding tests with mypy * adding docs for mypy usage * adding mypy failure test * adding alias tests * tweak mypy tests
31 lines
599 B
Python
31 lines
599 B
Python
from pydantic import ValidationError
|
|
try:
|
|
User(signup_ts='broken', friends=[1, 2, 'not number'])
|
|
except ValidationError as e:
|
|
print(e.json())
|
|
|
|
"""
|
|
{
|
|
"friends": [
|
|
{
|
|
"error_msg": "invalid literal for int() with base 10: 'not number'",
|
|
"error_type": "ValueError",
|
|
"index": 2,
|
|
"track": "int"
|
|
}
|
|
],
|
|
"id": {
|
|
"error_msg": "field required",
|
|
"error_type": "Missing",
|
|
"index": null,
|
|
"track": null
|
|
},
|
|
"signup_ts": {
|
|
"error_msg": "Invalid datetime format",
|
|
"error_type": "ValueError",
|
|
"index": null,
|
|
"track": "datetime"
|
|
}
|
|
}
|
|
"""
|