##// END OF EJS Templates
Backport PR #2685: Fix pretty print of types when `__module__` is not available....
MinRK -
Show More
@@ -602,10 +602,16 b' def _re_pattern_pprint(obj, p, cycle):'
602 602
603 603 def _type_pprint(obj, p, cycle):
604 604 """The pprint for classes and types."""
605 if obj.__module__ in ('__builtin__', 'exceptions'):
605 try:
606 mod = obj.__module__
607 except AttributeError:
608 # Heap allocated types might not have the module attribute.
609 return p.text(obj.__name__)
610
611 if mod in ('__builtin__', 'exceptions'):
606 612 name = obj.__name__
607 613 else:
608 name = obj.__module__ + '.' + obj.__name__
614 name = mod + '.' + obj.__name__
609 615 p.text(name)
610 616
611 617
@@ -18,6 +18,7 b' import nose.tools as nt'
18 18
19 19 # Our own imports
20 20 from IPython.lib import pretty
21 from IPython.testing.decorators import skip_without
21 22
22 23 #-----------------------------------------------------------------------------
23 24 # Classes and functions
@@ -63,3 +64,12 b' def test_dispatch():'
63 64 expectedoutput = "MyDict(...)"
64 65
65 66 nt.assert_equals(gotoutput, expectedoutput)
67
68 @skip_without('xxlimited')
69 def test_pprint_heap_allocated_type():
70 """
71 Test that pprint works for heap allocated types.
72 """
73 import xxlimited
74 output = pretty.pretty(xxlimited.Null)
75 nt.assert_equal(output, 'xxlimited.Null')
General Comments 0
You need to be logged in to leave comments. Login now