Skip to main content

Practice · 2 of 3

Auto-registering subclasses

CHALLENGE
Difficulty: advanced+25 XP

Implement class Registered whose subclasses are collected automatically: - use __init_subclass__ (no metaclass) - each subclass registers itself in Registered.registry (a dict) keyed by a class attribute key if present, else its lowercase class name - the base class itself must NOT appear in the registry - Registered.get(key) returns the class or raises KeyError

Back to lesson: Practice: MRO & Mixin Practice