示例#1
0
def dump_tagged(nodes: Sequence[object], tag: Optional[str], str_conv: 'StrConv') -> str:
    """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 items are converted to strings and indented
    """
    from mypy.types import Type, TypeStrVisitor

    a = []  # type: List[str]
    if tag:
        a.append(tag + '(')
    for n in nodes:
        if isinstance(n, list):
            if n:
                a.append(dump_tagged(n, None, str_conv))
        elif isinstance(n, tuple):
            s = dump_tagged(n[1], n[0], str_conv)
            a.append(indent(s, 2))
        elif isinstance(n, mypy.nodes.Node):
            a.append(indent(n.accept(str_conv), 2))
        elif isinstance(n, Type):
            a.append(indent(n.accept(TypeStrVisitor(str_conv.id_mapper)), 2))
        elif n:
            a.append(indent(str(n), 2))
    if tag:
        a[-1] += ')'
    return '\n'.join(a)
示例#2
0
 def __init__(self, *, update_data: bool) -> None:
     self.str_conv = StrConv(show_ids=True)
     self.id_mapper = self.str_conv.id_mapper
     self.type_str_conv = TypeStrVisitor(self.id_mapper)
示例#3
0
 def __init__(self, *, update_data: bool) -> None:
     super().__init__(update_data=update_data)
     self.str_conv = StrConv(show_ids=True)
     assert self.str_conv.id_mapper is not None
     self.id_mapper = self.str_conv.id_mapper  # type: IdMapper
     self.type_str_conv = TypeStrVisitor(self.id_mapper)
示例#4
0
 def setup(self) -> None:
     super().setup()
     self.str_conv = StrConv(show_ids=True)
     assert self.str_conv.id_mapper is not None
     self.id_mapper: IdMapper = self.str_conv.id_mapper
     self.type_str_conv = TypeStrVisitor(self.id_mapper)