Re: [Python-Dev] Cached Property Pattern

2006-12-29 Thread Calvin Spealman
It may have been discussed before, but there does not seem to have
been any resolution on the issue. Am I missing something or did the
discussion just kind of stop, with no solution or agreement ever
reached? In which case, reviving the question is not a bad idea, is
it?

On 12/29/06, Oleg Broytmann [EMAIL PROTECTED] wrote:
 http://mail.python.org/pipermail/python-dev/2005-September/056782.html

 On Fri, Dec 29, 2006 at 02:40:05AM -0500, Calvin Spealman wrote:
  To this end, should a cachedproperty builtin be included to do this

The issue was discussed a year ago:

 http://mail.python.org/pipermail/python-dev/2005-September/056782.html
 http://mail.python.org/pipermail/python-dev/2005-October/057120.html

 Oleg.
 --
  Oleg Broytmannhttp://phd.pp.ru/[EMAIL PROTECTED]
Programmers don't die, they just GOSUB without RETURN.
 ___
 Python-Dev mailing list
 Python-Dev@python.org
 http://mail.python.org/mailman/listinfo/python-dev
 Unsubscribe: 
 http://mail.python.org/mailman/options/python-dev/ironfroggy%40gmail.com



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Cached Property Pattern

2006-12-29 Thread Oleg Broytmann
On Fri, Dec 29, 2006 at 09:55:46AM -0500, Calvin Spealman wrote:
 It may have been discussed before, but there does not seem to have
 been any resolution on the issue. Am I missing something or did the
 discussion just kind of stop, with no solution or agreement ever
 reached? In which case, reviving the question is not a bad idea, is
 it?

   I don't remember any resolution. I think submitting a small module to
the patch tracker would be the simplest way to revive the discussion.

 On 12/29/06, Oleg Broytmann [EMAIL PROTECTED] wrote:
  http://mail.python.org/pipermail/python-dev/2005-September/056782.html
  http://mail.python.org/pipermail/python-dev/2005-October/057120.html

Oleg.
-- 
 Oleg Broytmannhttp://phd.pp.ru/[EMAIL PROTECTED]
   Programmers don't die, they just GOSUB without RETURN.
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Cached Property Pattern

2006-12-29 Thread Fred L. Drake, Jr.
On Friday 29 December 2006 10:50, Oleg Broytmann wrote:
 I don't remember any resolution. I think submitting a small module to
  the patch tracker would be the simplest way to revive the discussion.

We have a handful of interesting descriptors we use for Zope 3 development:

http://svn.zope.org/Zope3/trunk/src/zope/cachedescriptors/

I find I use the Lazy property quite a bit in short-lived contexts (a single 
web request); this sounds very much like what's being described here.  The 
readproperty is probably better when the computation isn't so expensive and 
the value may need to be re-computed frequently anyway.


  -Fred

-- 
Fred L. Drake, Jr.   fdrake at acm.org
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Cached Property Pattern

2006-12-28 Thread Calvin Spealman
A very common pattern in using properties is as follows:

class Foo(object):
@property
def c(self):
if not hasattr(self, '_c'):
self._c = some_operation(self.a, self.b)
return self._c

Basically, the common usage is to only calculate a properties value
once, and to reuse the result for every lookup after that. This is so
common, that it seems most of my uses of property come in this form.
To this end, should a cachedproperty builtin be included to do this
automatically? Optionally, it might automatically include a default
fset (change the cached value) and fdel (remove the cached value, to
be regenerated next time). I will contribute code, if such a patch
would be accepted.

PS - It seems I am taking over the python-dev summaries, but the
holidays have interfered with those duties! I apologize, and promise
they will come shortly.

-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com