Method: rich.text.Text.detect_indentation
Calls: 5, Exceptions: 1, Paths: 2Back
Path 1: 4 calls (0.8)
4 (2) 2 (1) 1 (1)
1def detect_indentation(self) -> int:
2 """Auto-detect indentation of code.
3
4 Returns:
5 int: Number of spaces used to indent code.
6 """
7
8 _indentations = {
9 len(match.group(1))
10 for match in re.finditer(r"^( *)(.*)$", self.plain, flags=re.MULTILINE)
11 }
12
13 try:
14 indentation = (
15 reduce(gcd, [indent for indent in _indentations if not indent % 2]) or 1
16 )
17 except TypeError:
18 indentation = 1
19
20 return indentation
Path 2: 1 calls (0.2)
1 (1)
TypeError (1)
1def detect_indentation(self) -> int:
2 """Auto-detect indentation of code.
3
4 Returns:
5 int: Number of spaces used to indent code.
6 """
7
8 _indentations = {
9 len(match.group(1))
10 for match in re.finditer(r"^( *)(.*)$", self.plain, flags=re.MULTILINE)
11 }
12
13 try:
14 indentation = (
15 reduce(gcd, [indent for indent in _indentations if not indent % 2]) or 1
16 )
17 except TypeError:
18 indentation = 1
19
20 return indentation