Re: Lazy Attribute

2012-11-16 Thread Demian Brecht
> There is a ready made and well tested lazy decorator at > http://pypi.python.org/pypi/lazy. I even has a better name. ;-) I was ignorantly unaware of this module. You've saved me a few lines of code every time I want to achieve lazy loading - thanks :) > Since people seem to come up with the

Re: Lazy Attribute

2012-11-16 Thread Stefan H. Holek
On 16.11.2012, at 11:54, Andriy Kornatskyy wrote: >> Subject: Re: Lazy Attribute >> From: ste...@epy.co.at >> Date: Fri, 16 Nov 2012 11:45:32 +0100 >> To: python-list@python.org >> >> On 16.11.2012, at 11:29, Steven D'Aprano wrote: >> >>>

Re: Lazy Attribute

2012-11-16 Thread Stefan H. Holek
On 15.11.2012, at 20:33, Andriy Kornatskyy wrote: > A lazy attribute is an attribute that is calculated on demand and only once. > > The post below shows how you can use lazy attribute in your Python class: > > http://mindref.blogspot.com/2012/11/python-lazy-attribute.html > > Comments or sugge

RE: Lazy Attribute

2012-11-16 Thread Andriy Kornatskyy
> From: steve+comp.lang.pyt...@pearwood.info > Subject: Re: Lazy Attribute > Date: Fri, 16 Nov 2012 10:29:03 + > To: python-list@python.org > > On Thu, 15 Nov 2012 15:46:19 -0700, Ian Kelly wrote: > > > Although you don't go into it in the bl

Re: Lazy Attribute

2012-11-16 Thread Stefan H. Holek
On 16.11.2012, at 11:29, Steven D'Aprano wrote: > I'm very vaguely leaning towards this as the least-worst solution to > invalidating the cached value: > > refresh(obj, 'attr') # pass the instance and the name This it exactly how lazy handles invalidation. http://lazy.readthedocs.org/en/lates

Re: Lazy Attribute

2012-11-16 Thread Steven D'Aprano
On Thu, 15 Nov 2012 15:46:19 -0700, Ian Kelly wrote: > Although you don't go into it in the blog entry, what I like about your > approach of replacing the descriptor with an attribute is that, in > addition to being faster, it makes it easy to force the object to lazily > reevaluate the attribute,

RE: Lazy Attribute

2012-11-16 Thread Andriy Kornatskyy
This is very minor use case. Unlikely useful to add any checks for None, or translate one exception to the other... with pretty much the same outcome: it makes sense in objects only. Thanks. Andriy > From: rousl...@msn.com > Subject: Re

RE: Lazy Attribute

2012-11-16 Thread Andriy Kornatskyy
Same applies to properties... they are seen as an object attributes. Thanks. Andriy > From: steve+comp.lang.pyt...@pearwood.info > Subject: Re: Lazy Attribute > Date: Fri, 16 Nov 2012 09:04:39 + > To: python-list@python.org > > O

RE: Lazy Attribute

2012-11-16 Thread Andriy Kornatskyy
from wheezy.core.descriptors import attribute as lazy @lazy def display_name... Thanks. Andriy Kornatskyy > Date: Fri, 16 Nov 2012 09:56:41 +0200 > From: s...@mweb.co.za > To: python-list@python.org > Subject: Re: Lazy Attribute > >

Re: Lazy Attribute

2012-11-16 Thread Rouslan Korneychuk
On 11/16/2012 04:32 AM, Rouslan Korneychuk wrote: On 11/16/2012 02:49 AM, Andriy Kornatskyy wrote: If accessing the descriptor on the class object has no special meaning, then the custom is to return the descriptor object itself, as properties do. If I would satisfy this, I will be forced to c

Re: Lazy Attribute

2012-11-16 Thread Rouslan Korneychuk
On 11/16/2012 02:49 AM, Andriy Kornatskyy wrote: If accessing the descriptor on the class object has no special meaning, then the custom is to return the descriptor object itself, as properties do. If I would satisfy this, I will be forced to check for None 99.9% of the use cases (it is not No

Re: Lazy Attribute

2012-11-16 Thread Steven D'Aprano
On Fri, 16 Nov 2012 10:49:07 +0300, Andriy Kornatskyy wrote: > Ian, > > Thank you for the comments. > >> The name "attribute" is not very descriptive. Why not "lazy_attribute" >> instead? > > It just shorter and still descriptive. It is not descriptive. EVERYTHING accessed used dot notation ob

Re: Lazy Attribute

2012-11-16 Thread Alex Strickland
On 2012/11/16 09:49 AM, Andriy Kornatskyy wrote: The name "attribute" is not very descriptive. Why not "lazy_attribute" instead? It just shorter and still descriptive. Shorter, but not descriptive. -- Regards Alex -- http://mail.python.org/mailman/listinfo/python-list

RE: Lazy Attribute

2012-11-15 Thread Andriy Kornatskyy
Ian, Thank you for mentioning about this research, really appreciate that. Thanks. Andriy Kornatskyy > From: ian.g.ke...@gmail.com > Date: Thu, 15 Nov 2012 15:46:19 -0700 > Subject: Re: Lazy Attribute > To: python-list@python.org > &

RE: Lazy Attribute

2012-11-15 Thread Andriy Kornatskyy
(it is not None, being applied to an object). Thus it behaves as designed. Thanks. Andriy Kornatskyy > From: ian.g.ke...@gmail.com > Date: Thu, 15 Nov 2012 15:24:40 -0700 > Subject: Re: Lazy Attribute > To: python-list@python.org > >

Re: Lazy Attribute

2012-11-15 Thread Ian Kelly
On Thu, Nov 15, 2012 at 12:33 PM, Andriy Kornatskyy wrote: > > A lazy attribute is an attribute that is calculated on demand and only once. > > The post below shows how you can use lazy attribute in your Python class: > > http://mindref.blogspot.com/2012/11/python-lazy-attribute.html > > Comments

Re: Lazy Attribute

2012-11-15 Thread Ian Kelly
On Thu, Nov 15, 2012 at 12:33 PM, Andriy Kornatskyy wrote: > > A lazy attribute is an attribute that is calculated on demand and only once. > > The post below shows how you can use lazy attribute in your Python class: > > http://mindref.blogspot.com/2012/11/python-lazy-attribute.html > > Comments