Something went wrong. Try again.
a fork of EvalEx by ezylang with a handful of breaking changes
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243from dataclasses import dataclass, fieldfrom typing import TypeVar
from cross.attachments import Attachmentfrom cross.tokens import Token
T = TypeVar("T", bound=Attachment)
class AttachmentKeeper: def __init__(self) -> None: self._map: dict[type, Attachment] = {}
def put(self, attachment: Attachment) -> None: self._map[attachment.__class__] = attachment
def get(self, cls: type[T]) -> T | None: instance = self._map.get(cls) if instance is None: return None if not isinstance(instance, cls): raise TypeError(f"Expected {cls.__name__}, got {type(instance).__name__}") return instance
def __repr__(self) -> str: return f"AttachmentKeeper(_map={self._map.values()})"
@dataclass(kw_only=True)class PostRef: id: str author: str service: str
@dataclass(kw_only=True)class Post(PostRef): parent_id: str | None tokens: list[Token] text_type: str = "text/plain" attachments: AttachmentKeeper = field(default_factory=AttachmentKeeper)