From bbd672e1bcb210622befa0e094a4e17e160ea2ba 2012-03-30 13:25:49 From: Walter Doerwald Date: 2012-03-30 13:25:49 Subject: [PATCH] Don't use getattr() when searching for the _repr_pretty_ method. Using getattr() might find a method in a base class, when a registered printer for a baseclass later in the mro is the better fit. --- diff --git a/IPython/lib/pretty.py b/IPython/lib/pretty.py index b74037e..556a3fa 100644 --- a/IPython/lib/pretty.py +++ b/IPython/lib/pretty.py @@ -353,8 +353,10 @@ class RepresentationPrinter(PrettyPrinter): # Some objects automatically create any requested # attribute. Try to ignore most of them by checking for # callability. - if callable(getattr(obj_class, '_repr_pretty_')): - return obj_class._repr_pretty_(obj, self, cycle) + if '_repr_pretty_' in obj_class.__dict__: + meth = obj_class._repr_pretty_ + if callable(meth): + return meth(obj, self, cycle) return _default_pprint(obj, self, cycle) finally: self.end_group()