Skip to main content

Practice · 1 of 2

Validated handler registry

CHALLENGE
Difficulty: advanced+25 XP

Implement class Handler with __init_subclass__ that auto-registers subclasses and VALIDATES them at class-creation time: - subclass must define scheme (a nonempty str) and handle(value) — raise TypeError at class definition otherwise - duplicate scheme values raise ValueError at class definition - Handler.dispatch(scheme, value) calls the right handler's handle and returns its result; unknown scheme raises KeyError - the base class itself is not registered

Back to lesson: Practice: Registry Mechanics