Hello, here I extend the idea of the smart help I've discussed
recently.
When I receive an error like:
TypeError: fun() takes exactly 2 arguments (1 given)
I'd also like to see that method/function parameters (or the first line
of its docstring).[color=blue]
>From a discussion with gentle programmers in another newsgroup, I've[/color]
see that this problem can probably be solved with something like:
.. import sys, exceptions, difflib, inspect
..
.. def excepthook(type , value, tb):
.. extra = ""
.. if sys.last_type == exceptions.Type Error:
.. # extra = string of function/method +
.. # parameters inspect.getargs pec(function or method)
.. import traceback
.. tblines = traceback.forma t_exception(typ e, value, tb)
.. tblines.append( extra)
.. print "".join( map(str, tblines) )
.. sys.exit(1)
..
.. sys.excepthook = excepthook
inspect.getargs pec is useful, but how can I find there the class+method
or (function name) of the raised error? I can find the function name
with something like this, but it doesn't look like a nice solution, and
it cannot be used to find the class of the method:
extra = str(sys.last_va lue)
extra = extra[:extra.find("() ")]
Thank you,
Bearophile
recently.
When I receive an error like:
TypeError: fun() takes exactly 2 arguments (1 given)
I'd also like to see that method/function parameters (or the first line
of its docstring).[color=blue]
>From a discussion with gentle programmers in another newsgroup, I've[/color]
see that this problem can probably be solved with something like:
.. import sys, exceptions, difflib, inspect
..
.. def excepthook(type , value, tb):
.. extra = ""
.. if sys.last_type == exceptions.Type Error:
.. # extra = string of function/method +
.. # parameters inspect.getargs pec(function or method)
.. import traceback
.. tblines = traceback.forma t_exception(typ e, value, tb)
.. tblines.append( extra)
.. print "".join( map(str, tblines) )
.. sys.exit(1)
..
.. sys.excepthook = excepthook
inspect.getargs pec is useful, but how can I find there the class+method
or (function name) of the raised error? I can find the function name
with something like this, but it doesn't look like a nice solution, and
it cannot be used to find the class of the method:
extra = str(sys.last_va lue)
extra = extra[:extra.find("() ")]
Thank you,
Bearophile
Comment