Skip to content

[deprecation] 'Pylinter.check' now takes sequence of str only #8463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/8463.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Following a deprecation period, ``Pylinter.check`` now only work with sequences of strings, not strings.

Refs #8463
21 changes: 5 additions & 16 deletions pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,23 +637,12 @@ def _discover_files(self, files_or_modules: Sequence[str]) -> Iterator[str]:
else:
yield something

def check(self, files_or_modules: Sequence[str] | str) -> None:
def check(self, files_or_modules: Sequence[str]) -> None:
"""Main checking entry: check a list of files or modules from their name.

files_or_modules is either a string or list of strings presenting modules to check.
"""
# 1) Initialize
self.initialize()

# 2) Gather all files
if not isinstance(files_or_modules, (list, tuple)):
# TODO: 3.0: Remove deprecated typing and update docstring
warnings.warn(
"In pylint 3.0, the checkers check function will only accept sequence of string",
DeprecationWarning,
stacklevel=2,
)
files_or_modules = (files_or_modules,) # type: ignore[assignment]
if self.config.recursive:
files_or_modules = tuple(self._discover_files(files_or_modules))
if self.config.from_stdin:
Expand All @@ -669,7 +658,7 @@ def check(self, files_or_modules: Sequence[str] | str) -> None:
}
)

# TODO: Move the parallel invocation into step 5 of the checking process
# TODO: Move the parallel invocation into step 3 of the checking process
if not self.config.from_stdin and self.config.jobs > 1:
original_sys_path = sys.path[:]
check_parallel(
Expand All @@ -681,7 +670,7 @@ def check(self, files_or_modules: Sequence[str] | str) -> None:
sys.path = original_sys_path
return

# 3) Get all FileItems
# 1) Get all FileItems
with augmented_sys_path(extra_packages_paths):
if self.config.from_stdin:
fileitems = self._get_file_descr_from_stdin(files_or_modules[0])
Expand All @@ -693,10 +682,10 @@ def check(self, files_or_modules: Sequence[str] | str) -> None:
# The contextmanager also opens all checkers and sets up the PyLinter class
with augmented_sys_path(extra_packages_paths):
with self._astroid_module_checker() as check_astroid_module:
# 4) Get the AST for each FileItem
# 2) Get the AST for each FileItem
ast_per_fileitem = self._get_asts(fileitems, data)

# 5) Lint each ast
# 3) Lint each ast
self._lint_files(ast_per_fileitem, check_astroid_module)

def _get_asts(
Expand Down
7 changes: 0 additions & 7 deletions tests/lint/test_pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from unittest import mock
from unittest.mock import patch

from _pytest.recwarn import WarningsRecorder
from pytest import CaptureFixture

from pylint.lint.pylinter import PyLinter
Expand All @@ -34,12 +33,6 @@ def test_crash_in_file(
assert any(m.symbol == "fatal" for m in linter.reporter.messages)


def test_check_deprecation(linter: PyLinter, recwarn: WarningsRecorder) -> None:
linter.check("myfile.py")
msg = recwarn.pop()
assert "check function will only accept sequence" in str(msg)


def test_crash_during_linting(
linter: PyLinter, capsys: CaptureFixture[str], tmp_path: Path
) -> None:
Expand Down