[Python-3000-checkins] r45652 - in python/branches/p3yk
Walter Dörwald
walter at livinglogic.de
Tue Apr 25 20:53:34 CEST 2006
Guido van Rossum wrote:
> On 4/22/06, Neil Schemenauer <nas at arctrix.com> wrote:
>> On Sun, Apr 23, 2006 at 01:28:06AM +0200, guido.van.rossum wrote:
>>> +bytes_nohash(PyObject *self)
>>> +{
>>> + PyErr_SetString(PyExc_TypeError, "bytes objects are unhashable");
>>> + return -1;
>>> +}
>> I think we might need to have a frozenbytes object too.
>
> I believe YAGNI. Also, I'm not keen on all these frozen variants.
> Hands up who's ever used a frozen set or needed a frozen dict?
When implementing a decorator that caches return values based on the
function arguments it's useful (but of course a workaround can use
tuple(sorted(kwargs.iteritems())):
def cache(func):
cache = {}
def wrapper(*args, **kwargs):
cacheargs = (args, tuple(sorted(kwargs.iteritems())))
try:
return cache[cacheargs]
except KeyError:
result = func(*args, **kwargs)
cache[cacheargs] = result
return result
return wrapper
This can e.g. be used in CherryPy, where arguments are guaranteed to be
strings.
Servus,
Walter
More information about the Python-3000-checkins
mailing list