Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33429
| From | Andriy Kornatskyy <andriy.kornatskyy@live.com> |
|---|---|
| Subject | RE: Lazy Attribute |
| Date | 2012-11-16 13:46 +0300 |
| References | <50a6156e$0$29978$c3e8da3$5496439d@news.astraweb.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3746.1353062869.27098.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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