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 dataclasses import dataclass | |
class Expression: | |
"""Represents an ADT expression""" | |
@dataclass | |
class Literal(Expression): | |
value: int |
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 dataclasses import dataclass | |
from typing import Any, Generic, TypeVar | |
T = TypeVar("T") | |
class Option(Generic[T]): | |
pass |
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 abc import ABC, abstractmethod | |
from dataclasses import dataclass | |
class Bool(ABC): | |
@abstractmethod | |
def __bool__(self): | |
"""True/False depends on the type""" | |
@dataclass |
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 dataclasses import dataclass | |
class User: | |
pass | |
@dataclass | |
class AuthenticatedUser(User): | |
id_: str |
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
sealed trait User | |
case class AuthenticatedUser(id: String, email: String, password: String) extends User | |
case class AnonymousUser(name: String) extends User |
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 os | |
from typing import Union | |
import pytest | |
from pydantic import BaseSettings, HttpUrl, ValidationError, parse_obj_as | |
from typing_extensions import Literal | |
class LocalContext(BaseSettings): # 1 | |
env: Literal["local"] # 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
def test_hobbies_names_is_reliant_on_hobbies_to_have_names(): | |
employee = { | |
"name": "John", | |
"age": 42, | |
"hobbies": [ | |
{"name": "Rock Climbing", "_id": "1234"}, | |
{"name": "Acrobatics", "_id": "5678"}, | |
], | |
} |
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 typing import List, Set | |
import attr | |
@attr.s(auto_attribs=True) | |
class Employee: | |
name: str | |
age: int | |
hobbies: List[dict] # 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 dataclasses import dataclass | |
from typing import List | |
# Users have: | |
# a name which is a non-empty string | |
# an age which is a positive int | |
# at least one hobbie (which is a non empty list) | |
@dataclass |
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 dataclasses import dataclass | |
from typing import List | |
import pytest | |
# User's name != '' and age > 0 and hobbies > [] | |
# and a none empty list of hobbies | |
# example: {'name': 'John', 'age': 30, hobbies: ['Rock Climbing', 'Books']} | |