Descriptor: class name precedence over instance name

Veek. M vek.m1234 at gmail.com
Sat Jul 2 00:27:41 EDT 2016


Trying to make sense of this para:

--------------------------------------------------
Also, the attribute name used by the class to hold a descriptor takes
prece- dence over attributes stored on instances. 

In the previous example,
this is why the descriptor object takes a name parameter and why the
name is changed slightly by inserting a leading underscore. In order
for the descriptor to store a value on the instance, it has to pick a
name that is different than that being used by the descriptor itself
---------------------------------------------
Under normal circumstances, when I do an attribute lookup:
x = Foo()
x.a
he will first check 'x' then Foo.

Is he say that Descriptors are a special case where Foo is checked 
first, then what - Base classes..? or does he hop back to look in the 
instance? How is C3 Linearization altered?


Additionally,
class Foo:
   def __init__(self, name, value):
     self.name = name

cannot be done because
x = Foo('bar', 10)

x.bar will..? attribute in class takes precedence.. great, isn't that 
what we want?



More information about the Python-list mailing list