From bc4a676a99af3879c79ae657461c13b604c6e409 2006-02-11 23:20:05 From: fperez Date: 2006-02-11 23:20:05 Subject: [PATCH] Fix http://www.scipy.net/roundup/ipython/issue53, test added (though it must be run manually, so I named it differently so it's not picked up automatically. --- diff --git a/IPython/ultraTB.py b/IPython/ultraTB.py index d05b6cc..b0b1676 100644 --- a/IPython/ultraTB.py +++ b/IPython/ultraTB.py @@ -60,7 +60,7 @@ You can implement other color schemes easily, the syntax is fairly self-explanatory. Please send back new schemes you develop to the author for possible inclusion in future releases. -$Id: ultraTB.py 1005 2006-01-12 08:39:26Z fperez $""" +$Id: ultraTB.py 1154 2006-02-11 23:20:05Z fperez $""" #***************************************************************************** # Copyright (C) 2001 Nathaniel Gray @@ -394,12 +394,38 @@ class VerboseTB(TBTools): Colors = self.Colors # just a shorthand + quicker name lookup ColorsNormal = Colors.Normal # used a lot indent = ' '*INDENT_SIZE - text_repr = pydoc.text.repr exc = '%s%s%s' % (Colors.excName, str(etype), ColorsNormal) em_normal = '%s\n%s%s' % (Colors.valEm, indent,ColorsNormal) undefined = '%sundefined%s' % (Colors.em, ColorsNormal) # some internal-use functions + def text_repr(value): + """Hopefully pretty robust repr equivalent.""" + # this is pretty horrible but should always return *something* + try: + return pydoc.text.repr(value) + except KeyboardInterrupt: + raise + except: + try: + return repr(value) + except KeyboardInterrupt: + raise + except: + try: + # all still in an except block so we catch + # getattr raising + name = getattr(value, '__name__', None) + if name: + # ick, recursion + return text_repr(name) + klass = getattr(value, '__class__', None) + if klass: + return '%s instance' % text_repr(klass) + except KeyboardInterrupt: + raise + except: + return 'UNRECOVERABLE REPR FAILURE' def eqrepr(value, repr=text_repr): return '=%s' % repr(value) def nullrepr(value, repr=text_repr): return '' diff --git a/doc/ChangeLog b/doc/ChangeLog index 70c053d..12a29b3 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,9 @@ +2006-02-11 Fernando Perez + + * IPython/ultraTB.py (VerboseTB.text.text_repr): Added patch + contributed by marienz to close + http://www.scipy.net/roundup/ipython/issue53. + 2006-02-10 Ville Vainio * genutils.py: getoutput now works in win32 too diff --git a/test/manualtest_repr_tb.py b/test/manualtest_repr_tb.py new file mode 100644 index 0000000..93dff69 --- /dev/null +++ b/test/manualtest_repr_tb.py @@ -0,0 +1,16 @@ +"""This should be run directly from ipython, and it should NOT crash. + +It can't currently be run via runtests b/c exception handling changes there, +and this is precisely testing exception handling problems.""" + +ipmagic('xmode verbose') + +src = """ +class suck(object): + def __repr__(self): + raise ValueError("who needs repr anyway") + +suck() +""" + +__IPYTHON__.runlines(src)