Builds a list of the members given, appropriately indented, with each field on a line. (special case: if there is only one field, then we do not put it on a new line unless that field contains a newline or `force_newline` is set to true). `open_tok` and `clos
(
self, members: Iterable[str], open_tok="[", close_tok="]", force_newline=False
)
| 96 | return self.build_ast_node(nodename, force_newline=force_newline, **fields) |
| 97 | |
| 98 | def build_list( |
| 99 | self, members: Iterable[str], open_tok="[", close_tok="]", force_newline=False |
| 100 | ) -> str: |
| 101 | """ |
| 102 | Builds a list of the members given, appropriately indented, |
| 103 | with each field on a line. |
| 104 | (special case: if there is only one field, then we do not put it on a new line |
| 105 | unless that field contains a newline or `force_newline` is set to true). |
| 106 | `open_tok` and `close_tok` are used to open and close the list, respectively. |
| 107 | """ |
| 108 | mem_list = list(members) |
| 109 | if not mem_list: |
| 110 | return f"{open_tok}{close_tok}" |
| 111 | if len(mem_list) == 1 and not force_newline and "\n" not in mem_list[0]: |
| 112 | return f"{open_tok}{mem_list[0]}{close_tok}" |
| 113 | member_lines = ",\n".join(map(self.indent, mem_list)) |
| 114 | return f"{open_tok}\n{member_lines}\n{close_tok}" |
| 115 | |
| 116 | def visit_constant_(self, op: relax.Constant) -> str: |
| 117 | # simple rule of thumb: keep scalars inline, but anything larger goes on a new one |
no test coverage detected