MCPcopy Index your code
hub / github.com/python/cpython / _format_items

Method _format_items

Lib/pprint.py:582–622  ·  view source on GitHub ↗
(self, items, stream, indent, allowance, context, level)

Source from the content-addressed store, hash-verified

580 write(',')
581
582 def _format_items(self, items, stream, indent, allowance, context, level):
583 write = stream.write
584 indent += self._indent_per_level
585 self._write_indent_padding(write)
586 delimnl = ',\n' + ' ' * indent
587 delim = ''
588 width = max_width = self._width - indent + 1
589 it = iter(items)
590 try:
591 next_ent = next(it)
592 except StopIteration:
593 return
594 last = False
595 while not last:
596 ent = next_ent
597 try:
598 next_ent = next(it)
599 except StopIteration:
600 last = True
601 max_width -= allowance
602 width -= allowance
603 if self._compact:
604 rep = self._repr(ent, context, level)
605 w = len(rep) + 2
606 if width < w:
607 width = max_width
608 if delim:
609 delim = delimnl
610 if width >= w:
611 width -= w
612 write(delim)
613 delim = ', '
614 write(rep)
615 continue
616 write(delim)
617 delim = delimnl
618 self._format(ent, stream, indent,
619 allowance if last else 1,
620 context, level)
621 if last and self._expand:
622 write(',')
623
624 def _repr(self, object, context, level):
625 repr, readable, recursive = self.format(object, context.copy(),

Callers 5

_pprint_dict_viewMethod · 0.95
_pprint_listMethod · 0.95
_pprint_tupleMethod · 0.95
_pprint_setMethod · 0.95
_pprint_dequeMethod · 0.95

Calls 4

_write_indent_paddingMethod · 0.95
_reprMethod · 0.95
_formatMethod · 0.95
writeFunction · 0.70

Tested by

no test coverage detected