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 Age(BaseModel): | |
__root__: int | |
def divide_age(x: Age, y: int): # 1 | |
'''implementation irrelevant''' |
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 Age(BaseModel): | |
__root__: int | |
def age_in_days(age: Age) -> int: | |
return age.__root__ * 365 # 1 |
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 Age(BaseModel): | |
__root__: int # 1 | |
def test_specialized_models_are_not_equal_to_their_primitives(): | |
age = Age(__root__=42) | |
assert age != 42 # 2 |
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 Age(BaseModel): | |
__root__: int | |
def test_specialized_models_are_not_equal_to_their_primitives(): | |
age = Age(__root__=42) | |
assert age != 42 |
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
import pytest | |
from pydantic import BaseModel, ValidationError | |
class StrictPizza(BaseModel): | |
toppings_count: int | |
size: str | |
class Config: | |
validate_assignment = True # enforces 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
import pytest | |
from pydantic import BaseModel, ValidationError | |
class Pizza(BaseModel): | |
toppings_count: int | |
size: str | |
def test_field_set_doesnt_perform_conversion_either(): |
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_copy_with_update_doesnt_perform_conversion(): | |
pizza = Pizza(toppings_count='4', size='XL') |
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 CamelCaseItem(BaseModel): | |
id: str | |
isAvailable: bool | |
def test_python_camel_case_names_are_weird_in_python(): | |
item = CamelCaseItem(id='test-item-id', isAvailable=True) |
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
vf() { | |
# note that you need to extract the absolute path in order to get this to work | |
ls -d ~/.virtualenv/*/ | fzf | while read file; do source $file/bin/activate; done | |
} |
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
# source relevant env files via fzf | |
# note that sf() can also be used without Kubectl | |
sf() { | |
find ~/.envs -type f | fzf | while read filename; do source $filename; done | |
} |