Showing the method's class in expection's traceback

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon May 19 05:56:20 EDT 2008


En Sun, 18 May 2008 17:31:44 -0300, Diez B. Roggisch <deets at nospam.web.de> escribió:
> Agustin Villena schrieb:

>> is there anyway to show the class of a method in an exception's
>> traceback?
>>
>> I want to improve the line
>> File "G:\dev\exceptions\sample.py", line 3, in foo
>>
>> to
>> File "G:\dev\exceptions\sample.py", line 3, in Some.foo
>>
>> Is this improvement feasible
>
> It should be. You can get a dictionary of the locals of an exception
> stack frame, of which you could extract the self-parameter's class.

That by itself is not enough, the method could be inherited; one should walk the base classes in the MRO to find the right one. And deal with classmethods and staticmethods. And decorators that don't preserve meta information... Hmmm, I think it isn't so trivial as it seems.

-- 
Gabriel Genellina




More information about the Python-list mailing list