Factory that returns a pprint function useful for sequences. Used by the default pprint for tuples, dicts, and lists.
(start, end)
| 539 | |
| 540 | |
| 541 | def _seq_pprinter_factory(start, end): |
| 542 | """ |
| 543 | Factory that returns a pprint function useful for sequences. Used by |
| 544 | the default pprint for tuples, dicts, and lists. |
| 545 | """ |
| 546 | def inner(obj, p, cycle): |
| 547 | if cycle: |
| 548 | return p.text(start + '...' + end) |
| 549 | step = len(start) |
| 550 | p.begin_group(step, start) |
| 551 | for idx, x in p._enumerate(obj): |
| 552 | if idx: |
| 553 | p.text(',') |
| 554 | p.breakable() |
| 555 | p.pretty(x) |
| 556 | if len(obj) == 1 and type(obj) is tuple: |
| 557 | # Special case for 1-item tuples. |
| 558 | p.text(',') |
| 559 | p.end_group(step, end) |
| 560 | return inner |
| 561 | |
| 562 | |
| 563 | def _set_pprinter_factory(start, end): |