##// END OF EJS Templates
Merge pull request #5568 from takluyver/i5556...
Min RK -
r16389:82e453a3 merge
parent child Browse files
Show More
@@ -723,17 +723,15 b' def _re_pattern_pprint(obj, p, cycle):'
723
723
724 def _type_pprint(obj, p, cycle):
724 def _type_pprint(obj, p, cycle):
725 """The pprint for classes and types."""
725 """The pprint for classes and types."""
726 mod = _safe_getattr(obj, '__module__', None)
727 if mod is None:
728 # Heap allocated types might not have the module attribute,
726 # Heap allocated types might not have the module attribute,
729 # and others may set it to None.
727 # and others may set it to None.
730 return p.text(obj.__name__)
728 mod = _safe_getattr(obj, '__module__', None)
729 name = _safe_getattr(obj, '__qualname__', obj.__name__)
731
730
732 if mod in ('__builtin__', 'builtins', 'exceptions'):
731 if mod in (None, '__builtin__', 'builtins', 'exceptions'):
733 name = obj.__name__
734 else:
735 name = mod + '.' + obj.__name__
736 p.text(name)
732 p.text(name)
733 else:
734 p.text(mod + '.' + name)
737
735
738
736
739 def _repr_pprint(obj, p, cycle):
737 def _repr_pprint(obj, p, cycle):
@@ -743,22 +741,18 b' def _repr_pprint(obj, p, cycle):'
743
741
744 def _function_pprint(obj, p, cycle):
742 def _function_pprint(obj, p, cycle):
745 """Base pprint for all functions and builtin functions."""
743 """Base pprint for all functions and builtin functions."""
746 if obj.__module__ in ('__builtin__', 'builtins', 'exceptions') or not obj.__module__:
744 name = _safe_getattr(obj, '__qualname__', obj.__name__)
747 name = obj.__name__
745 mod = obj.__module__
748 else:
746 if mod and mod not in ('__builtin__', 'builtins', 'exceptions'):
749 name = obj.__module__ + '.' + obj.__name__
747 name = mod + '.' + name
750 p.text('<function %s>' % name)
748 p.text('<function %s>' % name)
751
749
752
750
753 def _exception_pprint(obj, p, cycle):
751 def _exception_pprint(obj, p, cycle):
754 """Base pprint for all exceptions."""
752 """Base pprint for all exceptions."""
755 if obj.__class__.__module__ in ('exceptions', 'builtins'):
753 name = getattr(obj.__class__, '__qualname__', obj.__class__.__name__)
756 name = obj.__class__.__name__
754 if obj.__class__.__module__ not in ('exceptions', 'builtins'):
757 else:
755 name = '%s.%s' % (obj.__class__.__module__, name)
758 name = '%s.%s' % (
759 obj.__class__.__module__,
760 obj.__class__.__name__
761 )
762 step = len(name) + 1
756 step = len(name) + 1
763 p.begin_group(step, name + '(')
757 p.begin_group(step, name + '(')
764 for idx, arg in enumerate(getattr(obj, 'args', ())):
758 for idx, arg in enumerate(getattr(obj, 'args', ())):
@@ -45,6 +45,10 b' class MyDict(dict):'
45 def _repr_pretty_(self, p, cycle):
45 def _repr_pretty_(self, p, cycle):
46 p.text("MyDict(...)")
46 p.text("MyDict(...)")
47
47
48 class MyObj(object):
49 def somemethod(self):
50 pass
51
48
52
49 class Dummy1(object):
53 class Dummy1(object):
50 def _repr_pretty_(self, p, cycle):
54 def _repr_pretty_(self, p, cycle):
@@ -222,3 +226,6 b' def test_long_dict():'
222 last2 = p.rsplit('\n', 2)[-2:]
226 last2 = p.rsplit('\n', 2)[-2:]
223 nt.assert_equal(last2, [' 999: 999,', ' ...}'])
227 nt.assert_equal(last2, [' 999: 999,', ' ...}'])
224
228
229 def test_unbound_method():
230 output = pretty.pretty(MyObj.somemethod)
231 nt.assert_in('MyObj.somemethod', output) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now