Practice · 2 of 2
A metaclass, when it is the right tool
CHALLENGE
Difficulty: advanced+25 XP
Implement class FrozenMeta(type) enforcing that instances only ever set the attributes DECLARED in the class body annotations:
- setting an undeclared attribute raises AttributeError at ANY time (init or later)
- declared attributes are freely settable and readable
- Vec.brand must equal 'frozen' on every class using the metaclass (the metaclass itself may set class attributes)
- this must apply to subclasses too — that is why it is a metaclass, not __init_subclass__
Press Submit to check your solution.
Back to lesson: Practice: Registry Mechanics