Skip to content

Commit d94194b

Browse files
authored
fix "skipped files" count calculation (#10141)
1 parent 14b242f commit d94194b

File tree

7 files changed

+66
-8
lines changed

7 files changed

+66
-8
lines changed

doc/whatsnew/fragments/10073.bugfix

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixes "skipped files" count calculation; the previous method was displaying an arbitrary number.
2+
3+
Closes #10073

pylint/lint/expand_modules.py

+18
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ def expand_modules(
8787
if _is_ignored_file(
8888
something, ignore_list, ignore_list_re, ignore_list_paths_re
8989
):
90+
result[something] = {
91+
"path": something,
92+
"name": "",
93+
"isarg": False,
94+
"basepath": something,
95+
"basename": "",
96+
"isignored": True,
97+
}
9098
continue
9199
module_package_path = discover_package_path(something, source_roots)
92100
additional_search_path = [".", module_package_path, *path]
@@ -138,6 +146,7 @@ def expand_modules(
138146
"isarg": True,
139147
"basepath": filepath,
140148
"basename": modname,
149+
"isignored": False,
141150
}
142151
has_init = (
143152
not (modname.endswith(".__init__") or modname == "__init__")
@@ -153,6 +162,14 @@ def expand_modules(
153162
if _is_in_ignore_list_re(
154163
os.path.basename(subfilepath), ignore_list_re
155164
) or _is_in_ignore_list_re(subfilepath, ignore_list_paths_re):
165+
result[subfilepath] = {
166+
"path": subfilepath,
167+
"name": "",
168+
"isarg": False,
169+
"basepath": subfilepath,
170+
"basename": "",
171+
"isignored": True,
172+
}
156173
continue
157174

158175
modpath = _modpath_from_file(
@@ -167,5 +184,6 @@ def expand_modules(
167184
"isarg": isarg,
168185
"basepath": filepath,
169186
"basename": modname,
187+
"isignored": False,
170188
}
171189
return result, errors

pylint/lint/pylinter.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ def _get_file_descr_from_stdin(self, filepath: str) -> Iterator[FileItem]:
851851
self.config.ignore_patterns,
852852
self.config.ignore_paths,
853853
):
854+
self.stats.skipped += 1
854855
return
855856

856857
try:
@@ -873,7 +874,9 @@ def _iterate_file_descrs(
873874
"""
874875
for descr in self._expand_files(files_or_modules).values():
875876
name, filepath, is_arg = descr["name"], descr["path"], descr["isarg"]
876-
if self.should_analyze_file(name, filepath, is_argument=is_arg):
877+
if descr["isignored"]:
878+
self.stats.skipped += 1
879+
elif self.should_analyze_file(name, filepath, is_argument=is_arg):
877880
yield FileItem(name, filepath, descr["basename"])
878881

879882
def _expand_files(
@@ -1100,6 +1103,7 @@ def generate_reports(self, verbose: bool = False) -> int | None:
11001103

11011104
if self.config.reports:
11021105
self.reporter.display_reports(sect)
1106+
11031107
score_value = self._report_evaluation(verbose)
11041108
# save results if persistent run
11051109
if self.config.persistent:
@@ -1143,8 +1147,7 @@ def _report_evaluation(self, verbose: bool = False) -> int | None:
11431147

11441148
if verbose:
11451149
checked_files_count = self.stats.node_count["module"]
1146-
unchecked_files_count = self.stats.undocumented["module"]
1147-
msg += f"\nChecked {checked_files_count} files, skipped {unchecked_files_count} files"
1150+
msg += f"\nChecked {checked_files_count} files, skipped {self.stats.skipped} files/modules"
11481151

11491152
if self.config.score:
11501153
sect = report_nodes.EvaluationSection(msg)

pylint/typing.py

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ModuleDescriptionDict(TypedDict):
5151
isarg: bool
5252
basepath: str
5353
basename: str
54+
isignored: bool
5455

5556

5657
class ErrorDescriptionDict(TypedDict):

pylint/utils/linterstats.py

+3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def __init__(
128128
self.refactor = 0
129129
self.statement = 0
130130
self.warning = 0
131+
self.skipped = 0
131132

132133
self.global_note = 0
133134
self.nb_duplicated_lines = 0
@@ -151,6 +152,7 @@ def __str__(self) -> str:
151152
{self.refactor}
152153
{self.statement}
153154
{self.warning}
155+
{self.skipped}
154156
{self.global_note}
155157
{self.nb_duplicated_lines}
156158
{self.percent_duplicated_lines}"""
@@ -385,6 +387,7 @@ def merge_stats(stats: list[LinterStats]) -> LinterStats:
385387
merged.refactor += stat.refactor
386388
merged.statement += stat.statement
387389
merged.warning += stat.warning
390+
merged.skipped += stat.skipped
388391

389392
merged.global_note += stat.global_note
390393
return merged

tests/lint/unittest_expand_modules.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def test__is_in_ignore_list_re_match() -> None:
4040
"isarg": True,
4141
"name": "lint.unittest_expand_modules",
4242
"path": EXPAND_MODULES,
43+
"isignored": False,
4344
}
4445

4546
this_file_relative_to_parent = {
@@ -48,6 +49,7 @@ def test__is_in_ignore_list_re_match() -> None:
4849
"isarg": True,
4950
"name": "lint.unittest_expand_modules",
5051
"path": EXPAND_MODULES_BASE,
52+
"isignored": False,
5153
}
5254

5355
this_file_from_init = {
@@ -56,6 +58,7 @@ def test__is_in_ignore_list_re_match() -> None:
5658
"isarg": False,
5759
"name": "lint.unittest_expand_modules",
5860
"path": EXPAND_MODULES,
61+
"isignored": False,
5962
}
6063

6164
this_file_from_init_deduplicated = {
@@ -64,6 +67,7 @@ def test__is_in_ignore_list_re_match() -> None:
6467
"isarg": True,
6568
"name": "lint.unittest_expand_modules",
6669
"path": EXPAND_MODULES,
70+
"isignored": False,
6771
}
6872

6973
unittest_lint = {
@@ -72,6 +76,7 @@ def test__is_in_ignore_list_re_match() -> None:
7276
"isarg": False,
7377
"name": "lint.unittest_lint",
7478
"path": str(TEST_DIRECTORY / "lint/unittest_lint.py"),
79+
"isignored": False,
7580
}
7681

7782
test_utils = {
@@ -80,6 +85,7 @@ def test__is_in_ignore_list_re_match() -> None:
8085
"isarg": False,
8186
"name": "lint.test_utils",
8287
"path": str(TEST_DIRECTORY / "lint/test_utils.py"),
88+
"isignored": False,
8389
}
8490

8591
test_run_pylint = {
@@ -88,6 +94,7 @@ def test__is_in_ignore_list_re_match() -> None:
8894
"isarg": False,
8995
"name": "lint.test_run_pylint",
9096
"path": str(TEST_DIRECTORY / "lint/test_run_pylint.py"),
97+
"isignored": False,
9198
}
9299

93100
test_pylinter = {
@@ -96,6 +103,7 @@ def test__is_in_ignore_list_re_match() -> None:
96103
"isarg": False,
97104
"name": "lint.test_pylinter",
98105
"path": str(TEST_DIRECTORY / "lint/test_pylinter.py"),
106+
"isignored": False,
99107
}
100108

101109
test_caching = {
@@ -104,6 +112,7 @@ def test__is_in_ignore_list_re_match() -> None:
104112
"isarg": False,
105113
"name": "lint.test_caching",
106114
"path": str(TEST_DIRECTORY / "lint/test_caching.py"),
115+
"isignored": False,
107116
}
108117

109118
init_of_package = {
@@ -112,6 +121,7 @@ def test__is_in_ignore_list_re_match() -> None:
112121
"isarg": True,
113122
"name": "lint",
114123
"path": INIT_PATH,
124+
"isignored": False,
115125
}
116126

117127
# A directory that is not a python package.
@@ -123,13 +133,15 @@ def test__is_in_ignore_list_re_match() -> None:
123133
"isarg": False,
124134
"basepath": str(REPORTERS_PATH / "__init__.py"),
125135
"basename": "reporters",
136+
"isignored": False,
126137
},
127138
str(REPORTERS_PATH / "unittest_reporting.py"): {
128139
"path": str(REPORTERS_PATH / "unittest_reporting.py"),
129140
"name": "reporters.unittest_reporting",
130141
"isarg": False,
131142
"basepath": str(REPORTERS_PATH / "__init__.py"),
132143
"basename": "reporters",
144+
"isignored": False,
133145
},
134146
}
135147

@@ -304,5 +316,5 @@ def test_expand_modules_with_ignore(
304316
ignore_list_re,
305317
self.linter.config.ignore_paths,
306318
)
307-
assert modules == expected
319+
assert {k: v for k, v in modules.items() if not v["isignored"]} == expected
308320
assert not errors

tests/test_self.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,23 @@ def test_disable_all_enable_invalid(self) -> None:
241241

242242
def test_output_with_verbose(self) -> None:
243243
out = StringIO()
244-
self._runtest([UNNECESSARY_LAMBDA, "--verbose"], out=out, code=4)
245-
assert "Checked 1 files, skipped 0 files" in out.getvalue().strip()
244+
self._runtest(
245+
[
246+
UNNECESSARY_LAMBDA,
247+
join(
248+
HERE,
249+
"regrtest_data",
250+
"directory",
251+
"ignored_subdirectory",
252+
"failing.py",
253+
),
254+
"--ignore-paths=.*failing.*",
255+
"--verbose",
256+
],
257+
out=out,
258+
code=4,
259+
)
260+
assert "Checked 1 files, skipped 1 files/modules" in out.getvalue().strip()
246261

247262
def test_no_out_encoding(self) -> None:
248263
"""Test redirection of stdout with non ascii characters."""
@@ -1104,7 +1119,7 @@ def test_fail_on_info_only_exit_code(self, args: list[str], expected: int) -> No
11041119
(
11051120
"colorized",
11061121
(
1107-
"{path}:4:4: W0612: \x1B[35mUnused variable 'variable'\x1B[0m (\x1B[35munused-variable\x1B[0m)"
1122+
"{path}:4:4: W0612: \x1b[35mUnused variable 'variable'\x1b[0m (\x1b[35munused-variable\x1b[0m)"
11081123
),
11091124
),
11101125
("json", '"message": "Unused variable \'variable\'",'),
@@ -1212,7 +1227,10 @@ def test_ignore_recursive(self, ignore_value: str) -> None:
12121227
test would fail due these errors.
12131228
"""
12141229
directory = join(HERE, "regrtest_data", "directory")
1215-
self._runtest([directory, "--recursive=y", f"--ignore={ignore_value}"], code=0)
1230+
self._runtest(
1231+
[directory, "--verbose", "--recursive=y", f"--ignore={ignore_value}"],
1232+
code=0,
1233+
)
12161234

12171235
@pytest.mark.parametrize("ignore_pattern_value", ["ignored_.*", "failing.*"])
12181236
def test_ignore_pattern_recursive(self, ignore_pattern_value: str) -> None:

0 commit comments

Comments
 (0)