Skip to content

Instantly share code, notes, and snippets.

@gidgid
Last active September 29, 2020 19:17
Show Gist options
  • Save gidgid/3d1f7752fe9f4097307b2b2484a7b1f3 to your computer and use it in GitHub Desktop.
Save gidgid/3d1f7752fe9f4097307b2b2484a7b1f3 to your computer and use it in GitHub Desktop.
Basic non key-value models
from pydantic import BaseModel
class Age(BaseModel):
__root__: int # 1
def test_specialized_models_are_not_equal_to_their_primitives():
age = Age(__root__=42)
assert age != 42 # 2
def test_age_can_also_be_parsed():
age = Age.parse_obj(42) # 3
assert age != 42
def test_specialized_models_can_ensure_we_represent_the_correct_types():
age = Age(__root__='43')
assert age.__root__ == 43 # 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment