Splice decorator out of exception stack trace?

Chris Rebert clp2 at rebertia.com
Wed Apr 22 14:27:25 EDT 2009


On Wed, Apr 22, 2009 at 11:19 AM, Ben Weaver <ben.e.weaver at gmail.com> wrote:
> Hi,
>
> Is there any way to "splice" a decorator out of an exception stack
> trace?  For example:
>
>>>> def decorator(proc):
> ...     def internal(*args, **kwargs):
> ...         return proc(*args, **kwargs)
> ...     return internal
>
>>>> @decorator
> ... def foo():
> ...     assert False, 'simulate failure'
>
>>>> foo()
> Traceback (most recent call last):
>  ...
>  File "<...>", line 1, in <module>
>  File "<...>", line 3, in internal
>  File "<...>", line 3, in foo
> AssertionError: simulate failure
>
> I would like to know if it's possible to somehow end up with this
> stack trace instead:
>
>  File "<...>", line 1, in <module>
>  File "<...>", line 3, in foo

You can probably do it by fiddling with the `traceback` module
(http://docs.python.org/library/traceback.html), although without any
context regarding your situation, it seems like it's more trouble than
it's worth to bother doing so.

Cheers,
Chris
-- 
I have a blog:
http://blog.rebertia.com



More information about the Python-list mailing list