From f09f06064af445a34440edb405592cb513bddb0e 2014-10-16 17:44:25 From: Remi Rampin Date: 2014-10-16 17:44:25 Subject: [PATCH] Checks for metaclass's __repr__ in _type_pprint RepresentationPrinter has a type pprinter for 'type' subclasses. It will thus be called to print a class object (instance of 'type), avoiding the __repr__ of the metaclass. This patch checks for an overridden __repr__ before using the custom type-representation logic. --- diff --git a/IPython/lib/pretty.py b/IPython/lib/pretty.py index ee67787..1df0573 100644 --- a/IPython/lib/pretty.py +++ b/IPython/lib/pretty.py @@ -682,6 +682,12 @@ def _type_pprint(obj, p, cycle): """The pprint for classes and types.""" # Heap allocated types might not have the module attribute, # and others may set it to None. + + # Checks for a __repr__ override in the metaclass + if type(obj).__repr__ is not type.__repr__: + p.text(repr(obj)) + return + mod = _safe_getattr(obj, '__module__', None) name = _safe_getattr(obj, '__qualname__', obj.__name__)