Problem Statement
Which methods form the core descriptor protocol?
Explanation
A descriptor is an object attribute with binding behavior defined by dunder get, dunder set, and dunder delete. Properties and functions use descriptors under the hood.
Use descriptors to implement reusable managed attributes such as validation or type enforcement.
Code Solution
SolutionRead Only
class NonEmpty:
def __set__(self, obj, val):
if not val: raise ValueError('empty')
obj.__dict__['name']=val
def __get__(self, obj, owner):
return obj.__dict__['name']