Skip to content

Commit

Permalink
tweaks and history
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Jul 8, 2017
1 parent 89c5f26 commit 2fa1275
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ v0.4.0 (2017-XX-XX)
* show length in string validation error
* fix aliases in config during inheritance #55
* use unicode ellipsis in ``truncate``
* add ``parse_obj``, ``parse_raw`` and ``parse_file`` helper functions #58

v0.3.0 (2017-06-21)
...................
Expand Down
14 changes: 7 additions & 7 deletions docs/examples/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ class User(BaseModel):
print(m)
# > User id=123 name='James' signup_ts=None

try:
User.parse_obj(['not', 'a', 'dict'])
except ValidationError as e:
print(e)
# > 1 error validating input
# > User expected dict not list (error_type=TypeError)

m = User.parse_raw('{"id": 123, "name": "James"}') # assumes json as no content type passed
print(m)
# > User id=123 name='James' signup_ts=None
Expand All @@ -34,10 +41,3 @@ class User(BaseModel):
m = User.parse_file('/tmp/data.mp')
print(m)
# > User id=123 name='James' signup_ts=datetime.datetime(2017, 7, 14, 2, 40, tzinfo=datetime.timezone.utc)

try:
User.parse_obj(['not', 'a', 'dict'])
except ValidationError as e:
print(e)
# 1 error validating input
# User expected dict not list (error_type=TypeError)
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ Helper Functions

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

Expand Down
1 change: 1 addition & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jsonmodels
pydantic
pypi
metadata
msgpack
schemas
timestamp
travis
Expand Down

0 comments on commit 2fa1275

Please sign in to comment.