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 &

RE: Lazy Attribute

2012-11-16 Thread Andriy Kornatskyy
I believe it is not valid relate a lazy attribute as something `cached` since it cause confusion (e.g. delete of attribute cause cached item to be re-evaluated...), `cached` and `lazy` have completely different semantic meaning... however might overlap, as we see. Andriy

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
ing such lazy attributes. Ideally we could have a new statement: refresh obj.attr # or some other name like "invalidate" but that won't happen. Other alternatives like: obj.attr.refresh() refresh(obj.attr) can't work because the function will see the result of the attribute l

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
urn the descriptor object itself, as > properties do. The lazy attribute, as a pattern, is designed to calculate something on demand, that being said means some `dynamic` nature must present, thus a class instance - object is a good candidate, while class itself is considered relatively `im

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

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

Lazy Attribute

2012-11-15 Thread Andriy Kornatskyy
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 suggestions are welcome. Thanks. Andriy Kornatskyy