Show More
@@ -493,12 +493,17 b' def _default_pprint(obj, p, cycle):' | |||||
493 | p.end_group(1, '>') |
|
493 | p.end_group(1, '>') | |
494 |
|
494 | |||
495 |
|
495 | |||
496 | def _seq_pprinter_factory(start, end): |
|
496 | def _seq_pprinter_factory(start, end, basetype): | |
497 | """ |
|
497 | """ | |
498 | Factory that returns a pprint function useful for sequences. Used by |
|
498 | Factory that returns a pprint function useful for sequences. Used by | |
499 | the default pprint for tuples, dicts, lists, sets and frozensets. |
|
499 | the default pprint for tuples, dicts, lists, sets and frozensets. | |
500 | """ |
|
500 | """ | |
501 | def inner(obj, p, cycle): |
|
501 | def inner(obj, p, cycle): | |
|
502 | typ = type(obj) | |||
|
503 | if basetype is not None and typ is not basetype and typ.__repr__ != basetype.__repr__: | |||
|
504 | # If the subclass provides its own repr, use it instead. | |||
|
505 | return p.text(typ.__repr__(obj)) | |||
|
506 | ||||
502 | if cycle: |
|
507 | if cycle: | |
503 | return p.text(start + '...' + end) |
|
508 | return p.text(start + '...' + end) | |
504 | step = len(start) |
|
509 | step = len(start) | |
@@ -515,12 +520,17 b' def _seq_pprinter_factory(start, end):' | |||||
515 | return inner |
|
520 | return inner | |
516 |
|
521 | |||
517 |
|
522 | |||
518 | def _dict_pprinter_factory(start, end): |
|
523 | def _dict_pprinter_factory(start, end, basetype=None): | |
519 | """ |
|
524 | """ | |
520 | Factory that returns a pprint function used by the default pprint of |
|
525 | Factory that returns a pprint function used by the default pprint of | |
521 | dicts and dict proxies. |
|
526 | dicts and dict proxies. | |
522 | """ |
|
527 | """ | |
523 | def inner(obj, p, cycle): |
|
528 | def inner(obj, p, cycle): | |
|
529 | typ = type(obj) | |||
|
530 | if basetype is not None and typ is not basetype and typ.__repr__ != basetype.__repr__: | |||
|
531 | # If the subclass provides its own repr, use it instead. | |||
|
532 | return p.text(typ.__repr__(obj)) | |||
|
533 | ||||
524 | if cycle: |
|
534 | if cycle: | |
525 | return p.text('{...}') |
|
535 | return p.text('{...}') | |
526 | p.begin_group(1, start) |
|
536 | p.begin_group(1, start) | |
@@ -632,12 +642,12 b' _type_pprinters = {' | |||||
632 | float: _repr_pprint, |
|
642 | float: _repr_pprint, | |
633 | str: _repr_pprint, |
|
643 | str: _repr_pprint, | |
634 | unicode: _repr_pprint, |
|
644 | unicode: _repr_pprint, | |
635 | tuple: _seq_pprinter_factory('(', ')'), |
|
645 | tuple: _seq_pprinter_factory('(', ')', tuple), | |
636 | list: _seq_pprinter_factory('[', ']'), |
|
646 | list: _seq_pprinter_factory('[', ']', list), | |
637 | dict: _dict_pprinter_factory('{', '}'), |
|
647 | dict: _dict_pprinter_factory('{', '}', dict), | |
638 | types.DictProxyType: _dict_pprinter_factory('<dictproxy {', '}>'), |
|
648 | types.DictProxyType: _dict_pprinter_factory('<dictproxy {', '}>'), | |
639 | set: _seq_pprinter_factory('set([', '])'), |
|
649 | set: _seq_pprinter_factory('set([', '])', set), | |
640 | frozenset: _seq_pprinter_factory('frozenset([', '])'), |
|
650 | frozenset: _seq_pprinter_factory('frozenset([', '])', frozenset), | |
641 | super: _super_pprint, |
|
651 | super: _super_pprint, | |
642 | _re_pattern_type: _re_pattern_pprint, |
|
652 | _re_pattern_type: _re_pattern_pprint, | |
643 | type: _type_pprint, |
|
653 | type: _type_pprint, |
General Comments 0
You need to be logged in to leave comments.
Login now