Practice ยท 2 of 2
A metaclass, when it is the right tool
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__
Difficulty: advanced
Press Submit to check your solution.
Back to lesson: Practice: Registry Mechanics