Skip to content

Commit 2fa1275

Browse files
committed
tweaks and history
1 parent 89c5f26 commit 2fa1275

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ v0.4.0 (2017-XX-XX)
88
* show length in string validation error
99
* fix aliases in config during inheritance #55
1010
* use unicode ellipsis in ``truncate``
11+
* add ``parse_obj``, ``parse_raw`` and ``parse_file`` helper functions #58
1112

1213
v0.3.0 (2017-06-21)
1314
...................

docs/examples/parse.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ class User(BaseModel):
1313
print(m)
1414
# > User id=123 name='James' signup_ts=None
1515

16+
try:
17+
User.parse_obj(['not', 'a', 'dict'])
18+
except ValidationError as e:
19+
print(e)
20+
# > 1 error validating input
21+
# > User expected dict not list (error_type=TypeError)
22+
1623
m = User.parse_raw('{"id": 123, "name": "James"}') # assumes json as no content type passed
1724
print(m)
1825
# > User id=123 name='James' signup_ts=None
@@ -34,10 +41,3 @@ class User(BaseModel):
3441
m = User.parse_file('/tmp/data.mp')
3542
print(m)
3643
# > User id=123 name='James' signup_ts=datetime.datetime(2017, 7, 14, 2, 40, tzinfo=datetime.timezone.utc)
37-
38-
try:
39-
User.parse_obj(['not', 'a', 'dict'])
40-
except ValidationError as e:
41-
print(e)
42-
# 1 error validating input
43-
# User expected dict not list (error_type=TypeError)

docs/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ Helper Functions
142142

143143
:parse_obj: this is almost identical to the ``__init__`` method of the model except if the object passed is not
144144
a dict ``ValidationError`` will be raised (rather than python raising a ``TypeError``).
145-
:parse_raw: takes a ``str`` or ``bytes`` parses it as ``json``, ``msgpack`` or ``pickle`` data and then passes
145+
:parse_raw: takes a *str* or *bytes* parses it as *json*, *msgpack* or *pickle* data and then passes
146146
the result to ``parse_obj``. The data type is inferred from the ``content_type`` argument,
147-
otherwise ``json`` is assumed.
147+
otherwise *json* is assumed.
148148
:parse_file: reads a file and passes the contents to ``parse_raw``, if ``content_type`` is omitted it is inferred
149149
from the file's extension.
150150

docs/spelling_wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jsonmodels
1212
pydantic
1313
pypi
1414
metadata
15+
msgpack
1516
schemas
1617
timestamp
1718
travis

0 commit comments

Comments
 (0)