Skip to main content

Practice ยท 1 of 2

Validated handler registry

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

Difficulty: advanced

Back to lesson: Practice: Registry Mechanics