This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients ezio.melotti, rhettinger
Date 2011-10-14.13:27:21
SpamBayes Score 8.753863e-09
Marked as misclassified No
Message-id <1318598842.26.0.635257036215.issue13177@psf.upfronthosting.co.za>
In-reply-to
Content
Here's an example (copied from msg142063) of what the traceback is without the patch:
>>> from functools import lru_cache
>>> @lru_cache()
... def func(arg): raise ValueError()
... 
>>> func(3)
Traceback (most recent call last):
  File "/home/wolf/dev/py/3.2/Lib/functools.py", line 176, in wrapper
    result = cache[key]
KeyError: (3,)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/wolf/dev/py/3.2/Lib/functools.py", line 180, in wrapper
    result = user_function(*args, **kwds)
  File "<stdin>", line 2, in func
ValueError

The patch gets rid of the first traceback (the one before "During handling...").
I should also mention that my second point might not be valid if the cache hits are mostly successful.  I haven't done any specific benchmark, and I don't know how fast is 'key in dict' compared to raising an exception.  If it's e.g. 10 times faster, it should make lru_cache faster when the hits:miss ratio is lower than 10:1.
History
Date User Action Args
2011-10-14 13:27:22ezio.melottisetrecipients: + ezio.melotti, rhettinger
2011-10-14 13:27:22ezio.melottisetmessageid: <1318598842.26.0.635257036215.issue13177@psf.upfronthosting.co.za>
2011-10-14 13:27:21ezio.melottilinkissue13177 messages
2011-10-14 13:27:21ezio.melotticreate