Show More
@@ -493,12 +493,17 b' def _default_pprint(obj, p, cycle):' | |||
|
493 | 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 | 498 | Factory that returns a pprint function useful for sequences. Used by |
|
499 | 499 | the default pprint for tuples, dicts, lists, sets and frozensets. |
|
500 | 500 | """ |
|
501 | 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 | 507 | if cycle: |
|
503 | 508 | return p.text(start + '...' + end) |
|
504 | 509 | step = len(start) |
@@ -515,12 +520,17 b' def _seq_pprinter_factory(start, end):' | |||
|
515 | 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 | 525 | Factory that returns a pprint function used by the default pprint of |
|
521 | 526 | dicts and dict proxies. |
|
522 | 527 | """ |
|
523 | 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 | 534 | if cycle: |
|
525 | 535 | return p.text('{...}') |
|
526 | 536 | p.begin_group(1, start) |
@@ -632,12 +642,12 b' _type_pprinters = {' | |||
|
632 | 642 | float: _repr_pprint, |
|
633 | 643 | str: _repr_pprint, |
|
634 | 644 | unicode: _repr_pprint, |
|
635 | tuple: _seq_pprinter_factory('(', ')'), | |
|
636 | list: _seq_pprinter_factory('[', ']'), | |
|
637 | dict: _dict_pprinter_factory('{', '}'), | |
|
645 | tuple: _seq_pprinter_factory('(', ')', tuple), | |
|
646 | list: _seq_pprinter_factory('[', ']', list), | |
|
647 | dict: _dict_pprinter_factory('{', '}', dict), | |
|
638 | 648 | types.DictProxyType: _dict_pprinter_factory('<dictproxy {', '}>'), |
|
639 | set: _seq_pprinter_factory('set([', '])'), | |
|
640 | frozenset: _seq_pprinter_factory('frozenset([', '])'), | |
|
649 | set: _seq_pprinter_factory('set([', '])', set), | |
|
650 | frozenset: _seq_pprinter_factory('frozenset([', '])', frozenset), | |
|
641 | 651 | super: _super_pprint, |
|
642 | 652 | _re_pattern_type: _re_pattern_pprint, |
|
643 | 653 | type: _type_pprint, |
General Comments 0
You need to be logged in to leave comments.
Login now