RE: Implementing append within a descriptor

2014-01-21 Thread Joseph L. Casale
> You're going to have to subclass list if you want to intercept its > methods. As I see it, there are two ways you could do that: when it's > set, or when it's retrieved. I'd be inclined to do it in __set__, but > either could work. In theory, you could make it practically invisible > - just check

Re: Implementing append within a descriptor

2014-01-20 Thread Chris Angelico
On Tue, Jan 21, 2014 at 12:07 PM, Joseph L. Casale wrote: > foo = MyClass() > # This calls __set__ > foo.some_property = [x for x in range(5)] > # This bypasses __set__ obviously. > foo.some_property.append(5) > > So re-implementing my own list class has the draw back for the user that he > must

Implementing append within a descriptor

2014-01-20 Thread Joseph L. Casale
I have a caching non data descriptor that stores values in the implementing class instances __dict__. Something like: class Descriptor: def __init__(self, func, name=None, doc=None): self.__name__ = name or func.__name__ self.__module__ = func.__module__ self.__doc__