Skip to content

[primer] Fall back to no rcfile rather than pylint's #7798

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
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
16 changes: 11 additions & 5 deletions pylint/testutils/_primer/package_to_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/testutils/_primer/test_package_to_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="]