Given the simple example below, a few strange observations are made:
- The
Parameter.__set__
function is never called - At the line
self.color = Parameter()
the inspector shows color as being of type Parameter - At the conclusion of the program, f.color is of type str, not even aware of once being a Parameter
Why is the descriptor __set__
method not called when color is being assigned to? I'd expect it to be called for both the 'red' and 'blue' assignments.
class Parameter(object):
def __init__(self, value=None):
self.value = value
def __set__(self, instance, value):
print('in __set__')
self.value = value
def __get__(self, instance, owner):
return self.value
def __delete__(self, instance):
pass
class Fruit(object):
def __init__(self):
self.color = Parameter()
class Apple(Fruit):
def __init__(self):
super().__init__()
self.color = 'red'
f = Apple()
f.color = 'blue'
print(f.color)