Method: pylint.checkers.table_lines_from_stats
Calls: 6, Exceptions: 0, Paths: 2Back
Path 1: 3 calls (0.5)
LinterStats (3)
None (3)
'duplicated_lines' (3)
['nb duplicated lines', '0', 'NC', 'NC', 'percent duplicated lines', '0.000', 'NC', 'NC'] (3)
1def table_lines_from_stats(
2 stats: LinterStats,
3 old_stats: LinterStats | None,
4 stat_type: Literal["duplicated_lines", "message_types"],
5) -> list[str]:
6 """Get values listed in <columns> from <stats> and <old_stats>,
7 and return a formatted list of values.
8
9 The return value is designed to be given to a ureport.Table object
10 """
11 lines: list[str] = []
12 if stat_type == "duplicated_lines":
13 new: list[tuple[str, int | float]] = [
14 ("nb_duplicated_lines", stats.duplicated_lines["nb_duplicated_lines"]),
15 (
16 "percent_duplicated_lines",
17 stats.duplicated_lines["percent_duplicated_lines"],
18 ),
19 ]
20 if old_stats:
21 old: list[tuple[str, str | int | float]] = [
22 (
23 "nb_duplicated_lines",
24 old_stats.duplicated_lines["nb_duplicated_lines"],
25 ),
26 (
27 "percent_duplicated_lines",
28 old_stats.duplicated_lines["percent_duplicated_lines"],
29 ),
30 ]
31 else:
32 old = [("nb_duplicated_lines", "NC"), ("percent_duplicated_lines", "NC")]
33 elif stat_type == "message_types":
34 new = [
35 ("convention", stats.convention),
36 ("refactor", stats.refactor),
37 ("warning", stats.warning),
38 ("error", stats.error),
39 ]
40 if old_stats:
41 old = [
42 ("convention", old_stats.convention),
43 ("refactor", old_stats.refactor),
44 ("warning", old_stats.warning),
45 ("error", old_stats.error),
46 ]
47 else:
48 old = [
49 ("convention", "NC"),
50 ("refactor", "NC"),
51 ("warning", "NC"),
52 ("error", "NC"),
53 ]
54
55 for index, value in enumerate(new):
56 new_value = value[1]
57 old_value = old[index][1]
58 diff_str = (
59 diff_string(old_value, new_value)
60 if isinstance(old_value, float)
61 else old_value
62 )
63 new_str = f"{new_value:.3f}" if isinstance(new_value, float) else str(new_value)
64 old_str = f"{old_value:.3f}" if isinstance(old_value, float) else str(old_value)
65 lines.extend((value[0].replace("_", " "), new_str, old_str, diff_str)) # type: ignore[arg-type]
66 return lines
Path 2: 3 calls (0.5)
LinterStats (3)
None (3)
'message_types' (3)
['convention', '75', 'NC', 'NC', 'refactor', '10', 'NC', 'NC', 'warning', '53', 'NC', 'NC', 'error', '26', 'NC', 'NC'] (1) ['convention', '0', 'NC', '...
1def table_lines_from_stats(
2 stats: LinterStats,
3 old_stats: LinterStats | None,
4 stat_type: Literal["duplicated_lines", "message_types"],
5) -> list[str]:
6 """Get values listed in <columns> from <stats> and <old_stats>,
7 and return a formatted list of values.
8
9 The return value is designed to be given to a ureport.Table object
10 """
11 lines: list[str] = []
12 if stat_type == "duplicated_lines":
13 new: list[tuple[str, int | float]] = [
14 ("nb_duplicated_lines", stats.duplicated_lines["nb_duplicated_lines"]),
15 (
16 "percent_duplicated_lines",
17 stats.duplicated_lines["percent_duplicated_lines"],
18 ),
19 ]
20 if old_stats:
21 old: list[tuple[str, str | int | float]] = [
22 (
23 "nb_duplicated_lines",
24 old_stats.duplicated_lines["nb_duplicated_lines"],
25 ),
26 (
27 "percent_duplicated_lines",
28 old_stats.duplicated_lines["percent_duplicated_lines"],
29 ),
30 ]
31 else:
32 old = [("nb_duplicated_lines", "NC"), ("percent_duplicated_lines", "NC")]
33 elif stat_type == "message_types":
34 new = [
35 ("convention", stats.convention),
36 ("refactor", stats.refactor),
37 ("warning", stats.warning),
38 ("error", stats.error),
39 ]
40 if old_stats:
41 old = [
42 ("convention", old_stats.convention),
43 ("refactor", old_stats.refactor),
44 ("warning", old_stats.warning),
45 ("error", old_stats.error),
46 ]
47 else:
48 old = [
49 ("convention", "NC"),
50 ("refactor", "NC"),
51 ("warning", "NC"),
52 ("error", "NC"),
53 ]
54
55 for index, value in enumerate(new):
56 new_value = value[1]
57 old_value = old[index][1]
58 diff_str = (
59 diff_string(old_value, new_value)
60 if isinstance(old_value, float)
61 else old_value
62 )
63 new_str = f"{new_value:.3f}" if isinstance(new_value, float) else str(new_value)
64 old_str = f"{old_value:.3f}" if isinstance(old_value, float) else str(old_value)
65 lines.extend((value[0].replace("_", " "), new_str, old_str, diff_str)) # type: ignore[arg-type]
66 return lines