Skip to content

Instantly share code, notes, and snippets.

@gidgid
Last active November 20, 2020 14:00
Show Gist options
  • Save gidgid/10164014d8d3bc7965fafd09d2440301 to your computer and use it in GitHub Desktop.
Save gidgid/10164014d8d3bc7965fafd09d2440301 to your computer and use it in GitHub Desktop.
Ambiguity when using type coercion
from pydantic import BaseModel, PositiveInt
class UserResponse(BaseModel):
user_input: bool # 1
def test_what_did_the_user_mean():
assert UserResponse(user_input='yes').user_input is True # 2
class Summary(BaseModel):
score: PositiveInt # 3
def test_summaries_with_different_scores_are_equal():
assert Summary(score=4.3) == Summary(score=4.4) # 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment