diff --git a/pylint/testutils/_primer/package_to_lint.py b/pylint/testutils/_primer/package_to_lint.py index c472a98c5c..09ecb44560 100644 --- a/pylint/testutils/_primer/package_to_lint.py +++ b/pylint/testutils/_primer/package_to_lint.py @@ -5,11 +5,17 @@ from __future__ import annotations import logging +import sys from pathlib import Path from git.cmd import Git from git.repo import Repo +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + PRIMER_DIRECTORY_PATH = Path("tests") / ".pylint_primer_tests" @@ -56,9 +62,10 @@ def __init__( self.minimum_python = minimum_python @property - def pylintrc(self) -> Path | None: + def pylintrc(self) -> Path | Literal[""]: if self.pylintrc_relpath is None: - return None + # Fall back to "" to ensure pylint's own pylintrc is not discovered + return "" return self.clone_directory / self.pylintrc_relpath @property @@ -75,9 +82,8 @@ def paths_to_lint(self) -> list[str]: @property def pylint_args(self) -> list[str]: options: list[str] = [] - if self.pylintrc is not None: - # There is an error if rcfile is given but does not exist - options += [f"--rcfile={self.pylintrc}"] + # There is an error if rcfile is given but does not exist + options += [f"--rcfile={self.pylintrc}"] return self.paths_to_lint + options + self.pylint_additional_args def lazy_clone(self) -> str: # pragma: no cover diff --git a/tests/testutils/_primer/test_package_to_lint.py b/tests/testutils/_primer/test_package_to_lint.py index 2ee9f3decd..220e2c0b28 100644 --- a/tests/testutils/_primer/test_package_to_lint.py +++ b/tests/testutils/_primer/test_package_to_lint.py @@ -42,8 +42,8 @@ def test_package_to_lint_default_value() -> None: branch="main", directories=["src/flask"], # Must work on Windows (src\\flask) ) - assert package_to_lint.pylintrc is None + assert package_to_lint.pylintrc == "" expected_path_to_lint = ( PRIMER_DIRECTORY_PATH / "pallets" / "flask" / "src" / "flask" ) - assert package_to_lint.pylint_args == [str(expected_path_to_lint)] + assert package_to_lint.pylint_args == [str(expected_path_to_lint), "--rcfile="]