Practice ยท 1 of 2
Build a Validated field
Implement a data descriptor Validated(min_value, max_value) usable as a class attribute:
- stores the value under a mangled name chosen in __set_name__
- __set__ raises ValueError when the value is not an int or is outside [min_value, max_value]
- __get__ on the class (obj is None) returns the descriptor itself
- the class access must expose the declared bounds: Model.age.min_value == 0
Difficulty: advanced
Press Submit to check your solution.
Back to lesson: Practice: Descriptor Practice