Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'attribute': 0.05; 'error:': 0.05; 'none,': 0.05; 'skip:` 10': 0.05; 'present,': 0.07; 'welcome.': 0.07; 'python': 0.09; '(it': 0.09; '@property': 0.09; 'descriptor': 0.09; 'itself,': 0.09; 'satisfy': 0.09; 'def': 0.10; 'cases': 0.15; '33,': 0.16; 'attribute,': 0.16; 'class:': 0.16; 'descriptors': 0.16; 'object).': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'thu,': 0.17; '>>>': 0.18; 'to:name:python- list@python.org': 0.20; 'skip:- 40': 0.21; 'trying': 0.21; 'import': 0.21; 'thanks.': 0.21; 'do.': 0.21; '"",': 0.22; '15,': 0.23; 'to:2**1': 0.23; 'properties': 0.24; 'thus': 0.24; 'header :In-Reply-To:1': 0.25; '(most': 0.27; 'post': 0.28; 'cases.': 0.29; 'once.': 0.29; 'date:': 0.29; 'url:mailman': 0.29; 'class': 0.29; 'url:2012': 0.30; 'url:python': 0.32; 'file': 0.32; 'url:listinfo': 0.32; 'comments': 0.33; 'from:addr:live.com': 0.33; 'shorter': 0.33; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'nature': 0.35; 'nov': 0.35; 'pm,': 0.35; 'something': 0.35; 'there': 0.35; 'subject:': 0.36; 'url:org': 0.36; 'email addr:python.org': 0.36; 'thank': 0.36; 'itself': 0.37; 'being': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'from:': 0.38; 'object': 0.38; 'some': 0.38; 'shows': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'url:mail': 0.40; 'your': 0.60; 'email name :python-list': 0.62; 'relatively': 0.62; 'email addr:gmail.com': 0.63; 'url:blogspot': 0.64; 'results': 0.65; 'url:11': 0.71; 'special': 0.73; '99.9%': 0.84; 'demand,': 0.84; 'forced': 0.84; 'ian,': 0.84; 'candidate,': 0.95; 'demand': 0.96; 'charset:windows-1251': 0.97 X-Originating-IP: [194.44.213.194] From: Andriy Kornatskyy To: , "python-list@python.org" Subject: RE: Lazy Attribute Date: Fri, 16 Nov 2012 10:49:07 +0300 Importance: Normal In-Reply-To: References: , Content-Type: text/plain; charset="windows-1251" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 16 Nov 2012 07:49:06.0925 (UTC) FILETIME=[DB0B69D0:01CDC3CE] X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 91 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1353052215 news.xs4all.nl 6916 [2001:888:2000:d::a6]:39499 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33415 Ian=2C Thank you for the comments. > The name "attribute" is not very descriptive. Why not "lazy_attribute" in= stead? It just shorter and still descriptive. > If accessing the descriptor on the class object has no special > meaning=2C then the custom is to return the descriptor object itself=2C a= s > properties do. The lazy attribute=2C as a pattern=2C is designed to calculate something on= demand=2C that being said means some `dynamic` nature must present=2C thus= a class instance - object is a good candidate=2C while class itself is con= sidered relatively `immutable`... of cause there might be extreme cases. > If accessing the descriptor on the class object has no special > meaning=2C then the custom is to return the descriptor object itself=2C a= s > properties do. If I would satisfy this=2C I will be forced to check for None 99.9% of the = use cases (it is not None=2C being applied to an object). Thus it behaves a= s designed. Thanks. Andriy Kornatskyy ---------------------------------------- > From: ian.g.kelly@gmail.com > Date: Thu=2C 15 Nov 2012 15:24:40 -0700 > Subject: Re: Lazy Attribute > To: python-list@python.org > > On Thu=2C Nov 15=2C 2012 at 12:33 PM=2C 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 clas= s: > > > > http://mindref.blogspot.com/2012/11/python-lazy-attribute.html > > > > Comments or suggestions are welcome. > > The name "attribute" is not very descriptive. Why not "lazy_attribute" in= stead? > > I note that trying to access the descriptor on the class object > results in an error: > > >>> from descriptors import attribute > >>> class Foo: > ... @attribute > ... def forty_two(self): > ... return 6 * 9 > ... > >>> Foo().forty_two > 54 > >>> Foo.forty_two > Traceback (most recent call last): > File ""=2C line 1=2C in > File ".\descriptors.py"=2C line 33=2C in __get__ > setattr(obj=2C f.__name__=2C val) > AttributeError: 'NoneType' object has no attribute 'forty_two' > > If accessing the descriptor on the class object has no special > meaning=2C then the custom is to return the descriptor object itself=2C a= s > properties do. > > >>> class Foo: > ... @property > ... def forty_two(self): > ... return 6 * 9 > ... > >>> Foo().forty_two > 54 > >>> Foo.forty_two > > -- > http://mail.python.org/mailman/listinfo/python-list =