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
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
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
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
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 | |
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 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 datetime import datetime | |
from pydantic import BaseModel | |
class Event: | |
"""Represents an event""" | |
class Login(BaseModel, Event): |
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 State: | |
"""Represents a possible Circuit Breaker state""" | |
@dataclass | |
class Open(State): | |
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 dataclasses import dataclass | |
class Expression: | |
"""Represents an ADT expression""" | |
@dataclass | |
class Literal(Expression): | |
value: float |