Method: rich.pretty._Line.expand
Calls: 28, Exceptions: 0, Paths: 2Back
Path 1: 24 calls (0.86)
4 (24)
_Line (70) None (24)
1def expand(self, indent_size: int) -> Iterable["_Line"]:
2 """Expand this line by adding children on their own line."""
3 node = self.node
4 assert node is not None
5 whitespace = self.whitespace
6 assert node.children
7 if node.key_repr:
8 new_line = yield _Line(
9 text=f"{node.key_repr}{node.key_separator}{node.open_brace}",
10 whitespace=whitespace,
11 )
12 else:
13 new_line = yield _Line(text=node.open_brace, whitespace=whitespace)
14 child_whitespace = self.whitespace + " " * indent_size
15 tuple_of_one = node.is_tuple and len(node.children) == 1
16 for last, child in loop_last(node.children):
17 separator = "," if tuple_of_one else node.separator
18 line = _Line(
19 parent=new_line,
20 node=child,
21 whitespace=child_whitespace,
22 suffix=separator,
23 last=last and not tuple_of_one,
24 )
25 yield line
26
27 yield _Line(
28 text=node.close_brace,
29 whitespace=whitespace,
30 suffix=self.suffix,
31 last=self.last,
32 )
Path 2: 4 calls (0.14)
4 (4)
_Line (21) None (4)
1def expand(self, indent_size: int) -> Iterable["_Line"]:
2 """Expand this line by adding children on their own line."""
3 node = self.node
4 assert node is not None
5 whitespace = self.whitespace
6 assert node.children
7 if node.key_repr:
8 new_line = yield _Line(
9 text=f"{node.key_repr}{node.key_separator}{node.open_brace}",
10 whitespace=whitespace,
11 )
12 else:
13 new_line = yield _Line(text=node.open_brace, whitespace=whitespace)
14 child_whitespace = self.whitespace + " " * indent_size
15 tuple_of_one = node.is_tuple and len(node.children) == 1
16 for last, child in loop_last(node.children):
17 separator = "," if tuple_of_one else node.separator
18 line = _Line(
19 parent=new_line,
20 node=child,
21 whitespace=child_whitespace,
22 suffix=separator,
23 last=last and not tuple_of_one,
24 )
25 yield line
26
27 yield _Line(
28 text=node.close_brace,
29 whitespace=whitespace,
30 suffix=self.suffix,
31 last=self.last,
32 )