##// 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 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 501 Factory that returns a pprint function useful for sequences. Used by
502 502 the default pprint for tuples, dicts, lists, sets and frozensets.
503 503 """
504 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 510 if cycle:
506 511 return p.text(start + '...' + end)
507 512 step = len(start)
@@ -518,12 +523,17 b' def _seq_pprinter_factory(start, end):'
518 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 528 Factory that returns a pprint function used by the default pprint of
524 529 dicts and dict proxies.
525 530 """
526 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 537 if cycle:
528 538 return p.text('{...}')
529 539 p.begin_group(1, start)
@@ -635,12 +645,12 b' _type_pprinters = {'
635 645 float: _repr_pprint,
636 646 str: _repr_pprint,
637 647 unicode: _repr_pprint,
638 tuple: _seq_pprinter_factory('(', ')'),
639 list: _seq_pprinter_factory('[', ']'),
640 dict: _dict_pprinter_factory('{', '}'),
648 tuple: _seq_pprinter_factory('(', ')', tuple),
649 list: _seq_pprinter_factory('[', ']', list),
650 dict: _dict_pprinter_factory('{', '}', dict),
641 651 types.DictProxyType: _dict_pprinter_factory('<dictproxy {', '}>'),
642 set: _seq_pprinter_factory('set([', '])'),
643 frozenset: _seq_pprinter_factory('frozenset([', '])'),
652 set: _seq_pprinter_factory('set([', '])', set),
653 frozenset: _seq_pprinter_factory('frozenset([', '])', frozenset),
644 654 super: _super_pprint,
645 655 _re_pattern_type: _re_pattern_pprint,
646 656 type: _type_pprint,
General Comments 0
You need to be logged in to leave comments. Login now