Checkpoint: Typing
advanced30 min readLesson 120 of 169
Design a generic Repository protocol and its in-memory implementation.
Checkpoint — a typed repository
Build:
class Repository(Protocol[T])withadd(item: T) -> None,get(key: str) -> Optional[T],all() -> List[T](protocol bodies use...).class MemoryRepository(Generic[T])implementing it, constructed with akey_fnused to derive each item's key.seed(repo, users)adding every user.
Contract detail: add keeps the FIRST item for a key (later duplicates are
ignored — get() and all() still return the first).