From 9b115234316b1c822fc6bc55dff6ed3a2caf6894 2012-12-15 00:44:21 From: Bradley M. Froehle Date: 2012-12-15 00:44:21 Subject: [PATCH] Fix pretty print of types when `__module__` is not available. In Python 3, heap allocated types -- for example those created using PyType_FromSpec -- lack the `__module__` attribute. Closes #2684 --- diff --git a/IPython/lib/pretty.py b/IPython/lib/pretty.py index c8d71aa..d5f71c9 100644 --- a/IPython/lib/pretty.py +++ b/IPython/lib/pretty.py @@ -604,10 +604,16 @@ def _re_pattern_pprint(obj, p, cycle): def _type_pprint(obj, p, cycle): """The pprint for classes and types.""" - if obj.__module__ in ('__builtin__', 'exceptions'): + try: + mod = obj.__module__ + except AttributeError: + # Heap allocated types might not have the module attribute. + return p.text(obj.__name__) + + if mod in ('__builtin__', 'exceptions'): name = obj.__name__ else: - name = obj.__module__ + '.' + obj.__name__ + name = mod + '.' + obj.__name__ p.text(name)