1. Dependency injection with a Protocol
medium25 XPDefine a Clock Protocol with def now(self) -> float. Write class RateLimiter taking max_calls: int, per_seconds: float, and a clock: Clock. Its allow() -> bool returns True if fewer than max_calls calls were allowed in the last per_seconds (sliding window), recording the call when allowed. Then write a FakeClock with a settable t attribute for tests.
Ctrl/⌘ + Enter runs the tests · Esc then Tab leaves the editor