[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Extending property using a Subclass - single method - why Super(Baz, Baz).name.__set__ ?

class Foo(object):
    def name(self):
        if hasattr(self, '_name'):
            print('Foo name', self._name)
            return self._name
            return 'default'

    def name(self, value):
        print('Foo', self)
        self._name = value
    def name(self):
        self._name = None
    print('Foo', name)

class Baz(Foo):
    def name(self):
        print('Baz wrapper around getter')
        return super().name
    def name(self, value):
        print('Baz wrapper around setter')
        print(super(Baz,Baz).name, value)
        return super(Baz, Baz).name.__set__(self, value)
b = Baz()
print('print', b.name)
b.name = 'v'

Why do we user super(Baz, Baz) - are we setting a class variable called 
Baz.name which would trigger Baz._name = value?

We are essentially doing:
Foo.name.__set__(Baz, value) ?

How come 'self' is not used.. like in the traditional property way where 
we pass an instance reference instead of a class?