Q: why hh.a = 2 is not what I expect but b.a = 2 is Okay?
here's the code:
print('this is init')
self.name = ''
self.name = value
a = D()
b = hh()
Descriptor setters are only activated when setting the attribute on an instance of the class that owns the descriptor. They don't apply to the class itself or its subclasses. This is documented in the Python data model.
22.214.171.124. Implementing Descriptors
The following methods only apply when an instance of the class containing the method (a so-called descriptor class) appears in an owner class (the descriptor must be in either the owner’s class dictionary or in the class dictionary for one of its parents).