Practice ยท 2 of 3
Auto-registering subclasses
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
Difficulty: advanced
Press Submit to check your solution.
Back to lesson: Practice: MRO & Mixin Practice