Last active
November 20, 2020 14:00
-
-
Save gidgid/10164014d8d3bc7965fafd09d2440301 to your computer and use it in GitHub Desktop.
Ambiguity when using type coercion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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