How to pop the interpreter's stack?

Ethan Furman ethan at stoneleaf.us
Thu Dec 16 10:29:25 EST 2010


Tim Arnold wrote:
> "Ethan Furman" <ethan at stoneleaf.us> wrote in message 
> news:mailman.4.1292379995.6505.python-list at python.org...
>> kj wrote:
>>> The one thing I don't like about this strategy is that the tracebacks
>>> of exceptions raised during the execution of __pre_spam include one
>>> unwanted stack level (namely, the one corresponding to __pre_spam
>>> itself).
>>>
>>> __pre_spam should be completely invisible and unobtrusive
>> I am unaware of any way to accomplish what you desire.  I also think this 
>> is one of those things that's not worth fighting -- how often are you 
>> going to see such a traceback?  When somebody makes a coding mistake?  I 
>> would say change the name (assuming yours was a real example) to something 
>> more meaningful like _spam_arg_verifier and call it good.
>>
>> Alternatively, perhaps you could make a more general arg_verifier that 
>> could be used for all such needs, and then your traceback would have:
>>
>> caller
>>
>> spam
>>
>> arg_verifier
>>
>> and that seems useful to me (it is, in fact, how I have mine set up).
>>
>> Hope this helps!
>>
>> ~Ethan~
> 
> I thought people would advise using a decorator for this one. Wouldn't that 
> work?
> thanks,
> --Tim 

A decorator was one of the items kj explicity didn't want.  Also, while 
it would have a shallower traceback for exceptions raised during the 
__pre_spam portion, any exceptions raised during spam itself would then 
be one level deeper than desired... while that could be masked by 
catching and (re-?)raising the exception in the decorator, Steven had a 
very good point about why that is a bad idea -- namely, tracebacks 
shouldn't lie about where the error is.

~Ethan~



More information about the Python-list mailing list