internal. pprinter for iterables. you should probably use pprint_thing() rather than calling this directly. bounds length of printed sequence, depending on options
(
seq: ListLike, _nest_lvl: int = 0, max_seq_items: int | None = None, **kwds: Any
)
| 101 | |
| 102 | |
| 103 | def _pprint_seq( |
| 104 | seq: ListLike, _nest_lvl: int = 0, max_seq_items: int | None = None, **kwds: Any |
| 105 | ) -> str: |
| 106 | """ |
| 107 | internal. pprinter for iterables. you should probably use pprint_thing() |
| 108 | rather than calling this directly. |
| 109 | |
| 110 | bounds length of printed sequence, depending on options |
| 111 | """ |
| 112 | if isinstance(seq, set): |
| 113 | fmt = "{{{body}}}" |
| 114 | elif isinstance(seq, frozenset): |
| 115 | fmt = "frozenset({{{body}}})" |
| 116 | else: |
| 117 | fmt = "[{body}]" if hasattr(seq, "__setitem__") else "({body})" |
| 118 | |
| 119 | if max_seq_items is False: |
| 120 | max_items = None |
| 121 | else: |
| 122 | max_items = max_seq_items or get_option("max_seq_items") or len(seq) |
| 123 | |
| 124 | s = iter(seq) |
| 125 | # handle sets, no slicing |
| 126 | r = [] |
| 127 | max_items_reached = False |
| 128 | for i, item in enumerate(s): |
| 129 | if (max_items is not None) and (i >= max_items): |
| 130 | max_items_reached = True |
| 131 | break |
| 132 | r.append(pprint_thing(item, _nest_lvl + 1, max_seq_items=max_seq_items, **kwds)) |
| 133 | body = ", ".join(r) |
| 134 | |
| 135 | if max_items_reached: |
| 136 | body += ", ..." |
| 137 | elif isinstance(seq, tuple) and len(seq) == 1: |
| 138 | body += "," |
| 139 | |
| 140 | return fmt.format(body=body) |
| 141 | |
| 142 | |
| 143 | def _pprint_dict( |
no test coverage detected