Message from discussion
Lazy Attribute
Received: by 10.66.85.166 with SMTP id i6mr3909116paz.13.1353486795584;
Wed, 21 Nov 2012 00:33:15 -0800 (PST)
Path: 6ni3051pbd.1!nntp.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.glorb.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path: <ste...@epy.co.at>
X-Original-To: python-l...@python.org
Delivered-To: python-l...@mail.python.org
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'attribute': 0.05;
'@property': 0.09; 'cached': 0.09; 'immutable': 0.09; 'objects.':
0.09; 'refresh': 0.09; ';-)': 0.11; 'anyway': 0.11; 'assume':
0.11; 'to:name:python-list': 0.15; 'advocating': 0.16; 'value:':
0.16; 'wrote:': 0.17; 'instance': 0.17; 'mechanism': 0.17;
'stefan': 0.17; 'tests.': 0.17; 'handles': 0.18; 'solution.':
0.18; '>>>': 0.18; 'cc:2**0': 0.23; 'pass': 0.25; 'header:In-
Reply-To:1': 0.25; '+0100': 0.27; 'reply.': 0.28; "d'aprano":
0.29; 'received:192.168.1.3': 0.29; 'steven': 0.29; 'date:': 0.29;
"i'm": 0.29; 'fri,': 0.30; 'implement': 0.32; 'towards': 0.32;
'to:addr:python-list': 0.33; 'nov': 0.35; 'something': 0.35;
'subject:': 0.36; 'wanted': 0.36; 'url:org': 0.36; 'email
addr:python.org': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36;
'subject:: ': 0.38; 'from:': 0.38; 'url:en': 0.38;
'to:addr:python.org': 0.39; 'received:192': 0.39;
'received:192.168': 0.40; 'header:Message-Id:1': 0.62; 'email name
:python-list': 0.62; 'evaluate': 0.62; 'confirm': 0.64; 'decided':
0.65; 'received:at': 0.71; 'arise.': 0.84
Subject: Re: Lazy Attribute
Mime-Version: 1.0 (Apple Message framework v1085)
From: "Stefan H. Holek" <ste...@epy.co.at>
In-Reply-To: <DUB117-W1382A140FEE822A755FE2C691510@phx.gbl>
Date: Fri, 16 Nov 2012 13:46:01 +0100
References: <DUB117-W881D7D74D529D159D8B33F91520@phx.gbl>,
<mailman.3729.1353019611.27098.python-list@python.org>,
<50a6156e$0$29978$c3e8da3$5496439d@news.astraweb.com>,
<F1457CC9-913B-4437-A9C7-7775706DC...@epy.co.at>
<DUB117-W1382A140FEE822A755FE2C691...@phx.gbl>
To: python-list <python-l...@python.org>
X-Mailer: Apple Mail (2.1085)
X-BeenThere: python-l...@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-requ...@python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-l...@python.org>
List-Help: <mailto:python-list-requ...@python.org?subject=help>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-requ...@python.org?subject=subscribe>
Newsgroups: comp.lang.python
Message-ID: <mailman.3748.1353069963.27098.python-l...@python.org>
Lines: 36
NNTP-Posting-Host: 2001:888:2000:d::a6
X-Trace: 1353069963 news.xs4all.nl 6880 [2001:888:2000:d::a6]:39239
X-Complaints-To: ab...@xs4all.nl
Bytes: 4131
X-Received-Bytes: 4179
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
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-l...@python.org
>>=20
>> On 16.11.2012, at 11:29, Steven D'Aprano wrote:
>>=20
>>> I'm very vaguely leaning towards this as the least-worst solution to
>>> invalidating the cached value:
>>>=20
>>> refresh(obj, 'attr') # pass the instance and the name
>>=20
>> This it exactly how lazy handles invalidation. =
http://lazy.readthedocs.org/en/latest/
>=20
> @property is a solution to evaluate something that is dynamic. =
@attribute is good for immutable objects. Even if we assume refresh is a =
good idea... how I would know when it is valid to `refresh`? What is =
criteria?
>=20
> Andriy
I had to implement invalidation anyway in order to write tests. I =
decided to expose the mechanism to keep users from having to invent =
their own SHOULD the need arise. I was not advocating invalidation in =
any way with my reply. All I wanted was to confirm the "least bad" =
solution. ;-)
Stefan
--=20
Stefan H. Holek
ste...@epy.co.at