Convert an array into a pretty-printed multiline string representation. The format is tag( item1.. itemN) Individual items are formatted like this: - arrays are flattened - pairs (str, array) are converted recursively, so that str is the tag - other item
(nodes: Sequence[object], tag: str | None, str_conv: StrConv)
| 664 | |
| 665 | |
| 666 | def dump_tagged(nodes: Sequence[object], tag: str | None, str_conv: StrConv) -> str: |
| 667 | """Convert an array into a pretty-printed multiline string representation. |
| 668 | |
| 669 | The format is |
| 670 | tag( |
| 671 | item1.. |
| 672 | itemN) |
| 673 | Individual items are formatted like this: |
| 674 | - arrays are flattened |
| 675 | - pairs (str, array) are converted recursively, so that str is the tag |
| 676 | - other items are converted to strings and indented |
| 677 | """ |
| 678 | from mypy.types import Type, TypeStrVisitor |
| 679 | |
| 680 | a: list[str] = [] |
| 681 | if tag: |
| 682 | a.append(tag + "(") |
| 683 | for n in nodes: |
| 684 | if isinstance(n, list): |
| 685 | if n: |
| 686 | a.append(dump_tagged(n, None, str_conv)) |
| 687 | elif isinstance(n, tuple): |
| 688 | s = dump_tagged(n[1], n[0], str_conv) |
| 689 | a.append(indent(s, 2)) |
| 690 | elif isinstance(n, mypy.nodes.Node): |
| 691 | a.append(indent(n.accept(str_conv), 2)) |
| 692 | elif isinstance(n, Type): |
| 693 | a.append( |
| 694 | indent(n.accept(TypeStrVisitor(str_conv.id_mapper, options=str_conv.options)), 2) |
| 695 | ) |
| 696 | elif n is not None: |
| 697 | a.append(indent(str(n), 2)) |
| 698 | if tag: |
| 699 | a[-1] += ")" |
| 700 | return "\n".join(a) |
| 701 | |
| 702 | |
| 703 | def indent(s: str, n: int) -> str: |
no test coverage detected
searching dependent graphs…