MCPcopy
hub / github.com/python/mypy / dump_tagged

Function dump_tagged

mypy/strconv.py:666–700  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

664
665
666def 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
703def indent(s: str, n: int) -> str:

Callers 1

dumpMethod · 0.85

Calls 7

TypeStrVisitorClass · 0.90
isinstanceFunction · 0.85
indentFunction · 0.85
strClass · 0.85
appendMethod · 0.80
acceptMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…