How to pop the interpreter's stack?

Carl Banks pavlovevidence at gmail.com
Sun Dec 26 21:55:39 EST 2010


On Dec 26, 11:09 am, kj <no.em... at please.post> wrote:
> In <mailman.280.1293287106.6505.python-list at python Robert Kern <robert.k... at gmail.com> writes:
>
> >Except that the *caller* never gets the traceback (unless if it deliberately
> >inspects the stack for some metaprogramming reason). It gets the exception, and
> >that is the same no matter what you do. The developer/user gets the traceback,
> >and those implementation details *are* often important to them.
>
> Just look at what Python shows you if you pass the wrong number of
> arguments to a function:
>
> >>> def spam(x, y, z): pass
> ...
> >>> spam(1, 2)
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: spam() takes exactly 3 arguments (2 given)
>
> That's it.  The traceback stops at the point of the error.  Python
> doesn't show you all the underlying C-coded machinery that went
> into detecting the error and emitting the error message.  *No one*
> needs this information at this point.  All I'm saying is that I
> want to do the same thing with my argument validation code as Python
> does with its argument validation code: keep it out of sight.  When
> my argument validation code fires an exception ***there's no bug
> in **my** code***.  It's doing exactly what it's supposed to do.
> Therefore, there's no need for me to debug anything, and certainly
> no need for me to inspect the traceback all the way to the exception.
> The bug is in the code that called my function with the wrong
> arguments.  The developer of that code has no more use for seeing
> the traceback all the way to where my code raises the exception
> than I have for seeing the traceback of Python's underlying C code
> when I get an error like the one shown above.

Python makes no attempt to hide its machinery in tracebacks (that I'm
aware of); in fact stack points from internal Python functions,
classes, and modules appear in tracebacks all the time.  The reason
you don't see traceback lines for Python's argument validation is it's
written in C.  If it bothers you that much, you're welcome to write
you own argument validation in C, too.


Carl Banks



More information about the Python-list mailing list