Method: rich.text.Text.__getitem__
Calls: 7, Exceptions: 1, Paths: 3Back
Path 1: 4 calls (0.57)
slice (4)
Text (4)
1def __getitem__(self, slice: Union[int, slice]) -> "Text":
2 def get_text_at(offset: int) -> "Text":
3 _Span = Span
4 text = Text(
5 self.plain[offset],
6 spans=[
7 _Span(0, 1, style)
8 for start, end, style in self._spans
9 if end > offset >= start
10 ],
11 end="",
12 )
13 return text
14
15 if isinstance(slice, int):
16 return get_text_at(slice)
17 else:
18 start, stop, step = slice.indices(len(self.plain))
19 if step == 1:
20 lines = self.divide([start, stop])
21 return lines[1]
22 else:
23 # This would be a bit of work to implement efficiently
24 # For now, its not required
25 raise TypeError("slices with step!=1 are not supported")
Path 2: 2 calls (0.29)
0 (1) 4 (1)
Text (2)
1def __getitem__(self, slice: Union[int, slice]) -> "Text":
2 def get_text_at(offset: int) -> "Text":
3 _Span = Span
4 text = Text(
5 self.plain[offset],
6 spans=[
7 _Span(0, 1, style)
8 for start, end, style in self._spans
9 if end > offset >= start
10 ],
11 end="",
12 )
13 return text
14
15 if isinstance(slice, int):
16 return get_text_at(slice)
17 else:
18 start, stop, step = slice.indices(len(self.plain))
19 if step == 1:
20 lines = self.divide([start, stop])
21 return lines[1]
22 else:
23 # This would be a bit of work to implement efficiently
24 # For now, its not required
25 raise TypeError("slices with step!=1 are not supported")
Path 3: 1 calls (0.14)
slice (1)
TypeError (1)
1def __getitem__(self, slice: Union[int, slice]) -> "Text":
2 def get_text_at(offset: int) -> "Text":
3 _Span = Span
4 text = Text(
5 self.plain[offset],
6 spans=[
7 _Span(0, 1, style)
8 for start, end, style in self._spans
9 if end > offset >= start
10 ],
11 end="",
12 )
13 return text
14
15 if isinstance(slice, int):
16 return get_text_at(slice)
17 else:
18 start, stop, step = slice.indices(len(self.plain))
19 if step == 1:
20 lines = self.divide([start, stop])
21 return lines[1]
22 else:
23 # This would be a bit of work to implement efficiently
24 # For now, its not required
25 raise TypeError("slices with step!=1 are not supported")