Show More
@@ -512,7 +512,7 def _default_pprint(obj, p, cycle): | |||||
512 | def _seq_pprinter_factory(start, end, basetype): |
|
512 | def _seq_pprinter_factory(start, end, basetype): | |
513 | """ |
|
513 | """ | |
514 | Factory that returns a pprint function useful for sequences. Used by |
|
514 | Factory that returns a pprint function useful for sequences. Used by | |
515 |
the default pprint for tuples, dicts, |
|
515 | the default pprint for tuples, dicts, and lists. | |
516 | """ |
|
516 | """ | |
517 | def inner(obj, p, cycle): |
|
517 | def inner(obj, p, cycle): | |
518 | typ = type(obj) |
|
518 | typ = type(obj) | |
@@ -536,6 +536,33 def _seq_pprinter_factory(start, end, basetype): | |||||
536 | return inner |
|
536 | return inner | |
537 |
|
537 | |||
538 |
|
538 | |||
|
539 | def _set_pprinter_factory(start, end, basetype): | |||
|
540 | """ | |||
|
541 | Factory that returns a pprint function useful for sets and frozensets. | |||
|
542 | """ | |||
|
543 | def inner(obj, p, cycle): | |||
|
544 | typ = type(obj) | |||
|
545 | if basetype is not None and typ is not basetype and typ.__repr__ != basetype.__repr__: | |||
|
546 | # If the subclass provides its own repr, use it instead. | |||
|
547 | return p.text(typ.__repr__(obj)) | |||
|
548 | ||||
|
549 | if cycle: | |||
|
550 | return p.text(start + '...' + end) | |||
|
551 | if len(obj) == 0: | |||
|
552 | # Special case. | |||
|
553 | p.text(basetype.__name__ + '()') | |||
|
554 | else: | |||
|
555 | step = len(start) | |||
|
556 | p.begin_group(step, start) | |||
|
557 | for idx, x in enumerate(obj): | |||
|
558 | if idx: | |||
|
559 | p.text(',') | |||
|
560 | p.breakable() | |||
|
561 | p.pretty(x) | |||
|
562 | p.end_group(step, end) | |||
|
563 | return inner | |||
|
564 | ||||
|
565 | ||||
539 | def _dict_pprinter_factory(start, end, basetype=None): |
|
566 | def _dict_pprinter_factory(start, end, basetype=None): | |
540 | """ |
|
567 | """ | |
541 | Factory that returns a pprint function used by the default pprint of |
|
568 | Factory that returns a pprint function used by the default pprint of | |
@@ -668,8 +695,8 _type_pprinters = { | |||||
668 | list: _seq_pprinter_factory('[', ']', list), |
|
695 | list: _seq_pprinter_factory('[', ']', list), | |
669 | dict: _dict_pprinter_factory('{', '}', dict), |
|
696 | dict: _dict_pprinter_factory('{', '}', dict), | |
670 |
|
697 | |||
671 |
set: _se |
|
698 | set: _set_pprinter_factory('{', '}', set), | |
672 |
frozenset: _se |
|
699 | frozenset: _set_pprinter_factory('frozenset({', '})', frozenset), | |
673 | super: _super_pprint, |
|
700 | super: _super_pprint, | |
674 | _re_pattern_type: _re_pattern_pprint, |
|
701 | _re_pattern_type: _re_pattern_pprint, | |
675 | type: _type_pprint, |
|
702 | type: _type_pprint, |
General Comments 0
You need to be logged in to leave comments.
Login now