Last active
October 4, 2020 18:38
-
-
Save gidgid/b078233488bc67ab23351d32ad397898 to your computer and use it in GitHub Desktop.
Pydantic setter doesnt validate input types
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 | |
class Pizza(BaseModel): | |
toppings_count: int | |
size: str | |
def test_set_field_doesnt_perform_coercion(): | |
pizza = Pizza(toppings_count='4', size='XL') # 1 | |
assert pizza.toppings_count == 4 # 1 | |
pizza.toppings_count = 'no coercion' # 2 | |
assert pizza.toppings_count == 'no coercion' # 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment