Method: rich.filesize._to_str
Calls: 10, Exceptions: 0, Paths: 3Back
Path 1: 6 calls (0.6)
1111 (4) 1000 (1) 1500000.0 (1)
('kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB') (6)
1000 (6)
1 (4) 0 (1) 2 (1)
' ' (5) '' (1)
'1.0 kB' (1) '1.5 MB' (1) '1 kB' (1) '1.1 kB' (1) '1.11 kB' (1) '1.1kB' (1)
1def _to_str(
2 size: int,
3 suffixes: Iterable[str],
4 base: int,
5 *,
6 precision: Optional[int] = 1,
7 separator: Optional[str] = " ",
8) -> str:
9 if size == 1:
10 return "1 byte"
11 elif size < base:
12 return "{:,} bytes".format(size)
13
14 for i, suffix in enumerate(suffixes, 2): # noqa: B007
15 unit = base**i
16 if size < unit:
17 break
18 return "{:,.{precision}f}{separator}{}".format(
19 (base * size / unit),
20 suffix,
21 precision=precision,
22 separator=separator,
23 )
Path 2: 3 calls (0.3)
0 (2) 2 (1)
('kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB') (3)
1000 (3)
1 (2) 2 (1)
' ' (3)
'0 bytes' (2) '2 bytes' (1)
1def _to_str(
2 size: int,
3 suffixes: Iterable[str],
4 base: int,
5 *,
6 precision: Optional[int] = 1,
7 separator: Optional[str] = " ",
8) -> str:
9 if size == 1:
10 return "1 byte"
11 elif size < base:
12 return "{:,} bytes".format(size)
13
14 for i, suffix in enumerate(suffixes, 2): # noqa: B007
15 unit = base**i
16 if size < unit:
17 break
18 return "{:,.{precision}f}{separator}{}".format(
19 (base * size / unit),
20 suffix,
21 precision=precision,
22 separator=separator,
23 )
Path 3: 1 calls (0.1)
1 (1)
('kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB') (1)
1000 (1)
1 (1)
' ' (1)
'1 byte' (1)
1def _to_str(
2 size: int,
3 suffixes: Iterable[str],
4 base: int,
5 *,
6 precision: Optional[int] = 1,
7 separator: Optional[str] = " ",
8) -> str:
9 if size == 1:
10 return "1 byte"
11 elif size < base:
12 return "{:,} bytes".format(size)
13
14 for i, suffix in enumerate(suffixes, 2): # noqa: B007
15 unit = base**i
16 if size < unit:
17 break
18 return "{:,.{precision}f}{separator}{}".format(
19 (base * size / unit),
20 suffix,
21 precision=precision,
22 separator=separator,
23 )