Python Descriptor as Instance Attribute

2012-01-18 Thread Hua Yanghao
Hi all, Currently descriptors only work as class attribute, and doesn't work as a descriptor when it is an instance attribute. e.g. if we have descriptor class DescriptorTest, class Dummy(object): d = DescriptorTest() class Dummy2(object): def __init__(self): self.d = DescriptorTe

Re: Python Descriptor as Instance Attribute

2012-01-18 Thread Ian Kelly
On Wed, Jan 18, 2012 at 10:55 PM, Hua Yanghao wrote: > I just do not understand, why such behavior is not a default in python. > Or, is there a better design pattern here? The behavior is by design. First, keeping object behavior in the class definition simplifies the implementation and also mak

Re: Python Descriptor as Instance Attribute

2012-01-31 Thread Hua Yanghao
Thanks Ian for the explanation. Please see my comments below: > The behavior is by design.  First, keeping object behavior in the > class definition simplifies the implementation and also makes instance > checks more meaningful.  To borrow your Register example, if the "M" > descriptor is defined