diff --git a/doc/whatsnew/fragments/6242.bugfix b/doc/whatsnew/fragments/6242.bugfix new file mode 100644 index 0000000000..4337a0b59c --- /dev/null +++ b/doc/whatsnew/fragments/6242.bugfix @@ -0,0 +1,5 @@ +Maintain and reference a set of visited files while expanding the module files +from list of module directories, package names, and standalone files to +prevent duplicate scans. + +Closes #6242 diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py index 66455bfb10..2c9318713a 100644 --- a/pylint/lint/pylinter.py +++ b/pylint/lint/pylinter.py @@ -14,7 +14,7 @@ import traceback import warnings from collections import defaultdict -from collections.abc import Callable, Iterator, Sequence +from collections.abc import Callable, Iterator, MutableSet, Sequence from io import TextIOWrapper from pathlib import Path from re import Pattern @@ -878,8 +878,12 @@ def _iterate_file_descrs( The returned generator yield one item for each Python module that should be linted. """ + seen_filepaths: MutableSet[str] = set() # For deduplication of paths. for descr in self._expand_files(files_or_modules): name, filepath, is_arg = descr["name"], descr["path"], descr["isarg"] + if filepath in seen_filepaths: + continue + seen_filepaths.add(filepath) if self.should_analyze_file(name, filepath, is_argument=is_arg): yield FileItem(name, filepath, descr["basename"])