##// END OF EJS Templates
Merge pull request #452 from rkern/pretty-subtype-repr...
Brian E. Granger -
r3884:0bdf51b6 merge
parent child Browse files
Show More
@@ -496,12 +496,17 b' def _default_pprint(obj, p, cycle):'
496 p.end_group(1, '>')
496 p.end_group(1, '>')
497
497
498
498
499 def _seq_pprinter_factory(start, end):
499 def _seq_pprinter_factory(start, end, basetype):
500 """
500 """
501 Factory that returns a pprint function useful for sequences. Used by
501 Factory that returns a pprint function useful for sequences. Used by
502 the default pprint for tuples, dicts, lists, sets and frozensets.
502 the default pprint for tuples, dicts, lists, sets and frozensets.
503 """
503 """
504 def inner(obj, p, cycle):
504 def inner(obj, p, cycle):
505 typ = type(obj)
506 if basetype is not None and typ is not basetype and typ.__repr__ != basetype.__repr__:
507 # If the subclass provides its own repr, use it instead.
508 return p.text(typ.__repr__(obj))
509
505 if cycle:
510 if cycle:
506 return p.text(start + '...' + end)
511 return p.text(start + '...' + end)
507 step = len(start)
512 step = len(start)
@@ -518,12 +523,17 b' def _seq_pprinter_factory(start, end):'
518 return inner
523 return inner
519
524
520
525
521 def _dict_pprinter_factory(start, end):
526 def _dict_pprinter_factory(start, end, basetype=None):
522 """
527 """
523 Factory that returns a pprint function used by the default pprint of
528 Factory that returns a pprint function used by the default pprint of
524 dicts and dict proxies.
529 dicts and dict proxies.
525 """
530 """
526 def inner(obj, p, cycle):
531 def inner(obj, p, cycle):
532 typ = type(obj)
533 if basetype is not None and typ is not basetype and typ.__repr__ != basetype.__repr__:
534 # If the subclass provides its own repr, use it instead.
535 return p.text(typ.__repr__(obj))
536
527 if cycle:
537 if cycle:
528 return p.text('{...}')
538 return p.text('{...}')
529 p.begin_group(1, start)
539 p.begin_group(1, start)
@@ -635,12 +645,12 b' _type_pprinters = {'
635 float: _repr_pprint,
645 float: _repr_pprint,
636 str: _repr_pprint,
646 str: _repr_pprint,
637 unicode: _repr_pprint,
647 unicode: _repr_pprint,
638 tuple: _seq_pprinter_factory('(', ')'),
648 tuple: _seq_pprinter_factory('(', ')', tuple),
639 list: _seq_pprinter_factory('[', ']'),
649 list: _seq_pprinter_factory('[', ']', list),
640 dict: _dict_pprinter_factory('{', '}'),
650 dict: _dict_pprinter_factory('{', '}', dict),
641 types.DictProxyType: _dict_pprinter_factory('<dictproxy {', '}>'),
651 types.DictProxyType: _dict_pprinter_factory('<dictproxy {', '}>'),
642 set: _seq_pprinter_factory('set([', '])'),
652 set: _seq_pprinter_factory('set([', '])', set),
643 frozenset: _seq_pprinter_factory('frozenset([', '])'),
653 frozenset: _seq_pprinter_factory('frozenset([', '])', frozenset),
644 super: _super_pprint,
654 super: _super_pprint,
645 _re_pattern_type: _re_pattern_pprint,
655 _re_pattern_type: _re_pattern_pprint,
646 type: _type_pprint,
656 type: _type_pprint,
General Comments 0
You need to be logged in to leave comments. Login now