renaming docs examples (#972)

* renaming docs examples

* tweaks
This commit is contained in:
Samuel Colvin
2019-11-07 14:40:44 +00:00
committed by GitHub
parent 1d3f7824ec
commit 17b5ff42c1
85 changed files with 86 additions and 84 deletions
+27
View File
@@ -0,0 +1,27 @@
from pydantic import BaseModel
class User(BaseModel):
id: int
age: int
name: str = 'John Doe'
original_user = User(id=123, age=32)
user_data = original_user.dict()
print(user_data)
fields_set = original_user.__fields_set__
print(fields_set)
# ...
# pass user_data and fields_set to RPC or save to the database etc.
# ...
# you can then create a new instance of User without
# re-running validation which would be unnecessary at this point:
new_user = User.construct(_fields_set=fields_set, **user_data)
print(repr(new_user))
print(new_user.__fields_set__)
# construct can be dangerous, only use it with validated data!:
bad_user = User.construct(id='dog')
print(repr(bad_user))