Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33429

RE: Lazy Attribute

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 <andriy.kornatskyy@live.com>
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 <andriy.kornatskyy@live.com>
To <steve+comp.lang.python@pearwood.info>, "python-list@python.org" <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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3746.1353062869.27098.python-list@python.org> (permalink)
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

Show key headers only | View raw


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


----------------------------------------
> From: steve+comp.lang.python@pearwood.info
> Subject: Re: Lazy Attribute
> Date: Fri, 16 Nov 2012 10:29:03 +0000
> 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 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, 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, it should be deleted.
> 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, 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, not the lazy attribute itself. This won't do:
>
> obj.__class__.attr.refresh()
>
> because it won't know which instance to invalidate, 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, 'attr') # pass the instance and the name
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list
 		 	   		  

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Lazy Attribute Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-15 15:46 -0700
  Re: Lazy Attribute Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-16 10:29 +0000
    Re: Lazy Attribute "Stefan H. Holek" <stefan@epy.co.at> - 2012-11-16 11:45 +0100
    RE: Lazy Attribute Andriy Kornatskyy <andriy.kornatskyy@live.com> - 2012-11-16 13:46 +0300
    Re: Lazy Attribute "Stefan H. Holek" <stefan@epy.co.at> - 2012-11-16 13:46 +0100

csiph-web