Show More
@@ -723,17 +723,15 b' def _re_pattern_pprint(obj, p, cycle):' | |||
|
723 | 723 | |
|
724 | 724 | def _type_pprint(obj, p, cycle): |
|
725 | 725 | """The pprint for classes and types.""" |
|
726 | mod = _safe_getattr(obj, '__module__', None) | |
|
727 | if mod is None: | |
|
728 | 726 |
|
|
729 | 727 |
|
|
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'): | |
|
733 | name = obj.__name__ | |
|
734 | else: | |
|
735 | name = mod + '.' + obj.__name__ | |
|
731 | if mod in (None, '__builtin__', 'builtins', 'exceptions'): | |
|
736 | 732 | p.text(name) |
|
733 | else: | |
|
734 | p.text(mod + '.' + name) | |
|
737 | 735 | |
|
738 | 736 | |
|
739 | 737 | def _repr_pprint(obj, p, cycle): |
@@ -743,22 +741,18 b' def _repr_pprint(obj, p, cycle):' | |||
|
743 | 741 | |
|
744 | 742 | def _function_pprint(obj, p, cycle): |
|
745 | 743 | """Base pprint for all functions and builtin functions.""" |
|
746 | if obj.__module__ in ('__builtin__', 'builtins', 'exceptions') or not obj.__module__: | |
|
747 |
|
|
|
748 | else: | |
|
749 |
name = |
|
|
744 | name = _safe_getattr(obj, '__qualname__', obj.__name__) | |
|
745 | mod = obj.__module__ | |
|
746 | if mod and mod not in ('__builtin__', 'builtins', 'exceptions'): | |
|
747 | name = mod + '.' + name | |
|
750 | 748 | p.text('<function %s>' % name) |
|
751 | 749 | |
|
752 | 750 | |
|
753 | 751 | def _exception_pprint(obj, p, cycle): |
|
754 | 752 | """Base pprint for all exceptions.""" |
|
755 | if obj.__class__.__module__ in ('exceptions', 'builtins'): | |
|
756 | name = obj.__class__.__name__ | |
|
757 | else: | |
|
758 | name = '%s.%s' % ( | |
|
759 | obj.__class__.__module__, | |
|
760 | obj.__class__.__name__ | |
|
761 | ) | |
|
753 | name = getattr(obj.__class__, '__qualname__', obj.__class__.__name__) | |
|
754 | if obj.__class__.__module__ not in ('exceptions', 'builtins'): | |
|
755 | name = '%s.%s' % (obj.__class__.__module__, name) | |
|
762 | 756 | step = len(name) + 1 |
|
763 | 757 | p.begin_group(step, name + '(') |
|
764 | 758 | for idx, arg in enumerate(getattr(obj, 'args', ())): |
@@ -45,6 +45,10 b' class MyDict(dict):' | |||
|
45 | 45 | def _repr_pretty_(self, p, cycle): |
|
46 | 46 | p.text("MyDict(...)") |
|
47 | 47 | |
|
48 | class MyObj(object): | |
|
49 | def somemethod(self): | |
|
50 | pass | |
|
51 | ||
|
48 | 52 | |
|
49 | 53 | class Dummy1(object): |
|
50 | 54 | def _repr_pretty_(self, p, cycle): |
@@ -222,3 +226,6 b' def test_long_dict():' | |||
|
222 | 226 | last2 = p.rsplit('\n', 2)[-2:] |
|
223 | 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