Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'ideally': 0.04; 'attribute': 0.05; 'see.': 0.07; 'semantic': 0.07; 'ugly': 0.07; 'python': 0.09; '(it': 0.09; 'alternatives': 0.09; 'cached': 0.09; 'descriptor': 0.09; 'happen.': 0.09; 'refresh': 0.09; 'violates': 0.09; 'itself.': 0.11; 'attribute,': 0.16; 'attributes.': 0.16; 'confusion': 0.16; 'lazily': 0.16; 'namespace.': 0.16; 'properties,': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; 'value:': 0.16; 'wrote:': 0.17; 'deleted.': 0.17; 'instance': 0.17; 'replacing': 0.17; 'thu,': 0.17; '+0000': 0.20; 'to:name:python- list@python.org': 0.20; 'skip:- 40': 0.21; "haven't": 0.23; 'to:2**1': 0.23; 'pass': 0.25; 'least': 0.25; 'header:In-Reply- To:1': 0.25; '(e.g.': 0.27; 'there.': 0.28; '-0700,': 0.29; '>>>>': 0.29; 'faster,': 0.29; 'steven': 0.29; 'date:': 0.29; 'url:mailman': 0.29; "i'm": 0.29; 'fri,': 0.30; 'function': 0.30; 'towards': 0.32; 'url:python': 0.32; 'could': 0.32; 'url:listinfo': 0.32; 'from:addr:live.com': 0.33; 'like:': 0.33; 'to:addr:python-list': 0.33; 'that,': 0.34; "can't": 0.34; 'nov': 0.35; "won't": 0.35; 'something': 0.35; 'subject:': 0.36; 'but': 0.36; 'url:org': 0.36; 'email addr:python.org': 0.36; 'should': 0.36; 'possible': 0.37; 'does': 0.37; 'being': 0.37; 'item': 0.37; 'subject:: ': 0.38; 'from:': 0.38; 'object': 0.38; 'skip:o 20': 0.38; 'some': 0.38; 'delete': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'url:mail': 0.40; 'your': 0.60; 'lost': 0.60; 'easy': 0.60; 'remove': 0.61; 'email name:python-list': 0.62; 'different': 0.63; 'ever': 0.63; 'believe': 0.69; 'entry,': 0.84; 'do:': 0.91; 'relate': 0.91; '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 13:46:43 +0300 Importance: Normal In-Reply-To: <50a6156e$0$29978$c3e8da3$5496439d@news.astraweb.com> References: , , <50a6156e$0$29978$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset="windows-1251" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 16 Nov 2012 10:46:43.0637 (UTC) FILETIME=[AAF09E50:01CDC3E7] 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: 68 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1353062869 news.xs4all.nl 6945 [2001:888:2000:d::a6]:32966 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33429 I believe it is not valid relate a lazy attribute as something `cached` sin= ce it cause confusion (e.g. delete of attribute cause cached item to be re-= evaluated...)=2C `cached` and `lazy` have completely different semantic mea= ning... however might overlap=2C as we see. Andriy ---------------------------------------- > From: steve+comp.lang.python@pearwood.info > Subject: Re: Lazy Attribute > Date: Fri=2C 16 Nov 2012 10:29:03 +0000 > To: python-list@python.org > > On Thu=2C 15 Nov 2012 15:46:19 -0700=2C Ian Kelly wrote: > > > Although you don't go into it in the blog entry=2C what I like about yo= ur > > approach of replacing the descriptor with an attribute is that=2C in > > addition to being faster=2C it makes it easy to force the object to laz= ily > > reevaluate the attribute=2C just by deleting it. > > You just lost me right there. That's a poor UI design -- it violates the > principle of least surprise. If I delete something=2C it should be delete= d. > Consider your example: > > >>>> del p.display_name > >>>> p.display_name > > 'Eliza Smith' > > That's very surprising. I am not aware of any other name in Python where > deleting it does not remove the name from the namespace. (It is possible > with properties=2C but I haven't ever come across someone who does that.) > > I don't have a good solution for invaliding 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 > lookup=2C not the lazy attribute itself. This won't do: > > obj.__class__.attr.refresh() > > because it won't know which instance to invalidate=2C although this could > work: > > obj.__class__.attr.refresh(obj) # but it's ugly > > I'm very vaguely leaning towards this as the least-worst solution to > invalidating the cached value: > > refresh(obj=2C 'attr') # pass the instance and the name > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list =