Skip to content

Commit 05bfb2c

Browse files
authored
Fix parsing of unrelated options in tox.ini (pylint-dev#6801)
1 parent 2ee15d3 commit 05bfb2c

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

doc/whatsnew/2/2.14/full.rst

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ What's New in Pylint 2.14.1?
55
----------------------------
66
Release date: TBA
77

8+
* Fixed parsing of unrelated options in ``tox.ini``.
9+
10+
Closes #6800
11+
812
* Don't crash if we can't find the user's home directory.
913

1014
Closes #6802

pylint/config/config_file_parser.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ def __init__(self, verbose: bool, linter: PyLinter) -> None:
3131
self.verbose_mode = verbose
3232
self.linter = linter
3333

34-
@staticmethod
35-
def _parse_ini_file(file_path: Path) -> tuple[dict[str, str], list[str]]:
34+
def _parse_ini_file(self, file_path: Path) -> tuple[dict[str, str], list[str]]:
3635
"""Parse and handle errors of a ini configuration file."""
3736
parser = configparser.ConfigParser(inline_comment_prefixes=("#", ";"))
3837

@@ -43,7 +42,9 @@ def _parse_ini_file(file_path: Path) -> tuple[dict[str, str], list[str]]:
4342
config_content: dict[str, str] = {}
4443
options: list[str] = []
4544
for section in parser.sections():
46-
if "setup.cfg" in str(file_path) and not section.startswith("pylint"):
45+
if self._ini_file_with_sections(str(file_path)) and not section.startswith(
46+
"pylint"
47+
):
4748
if section.lower() == "master":
4849
# TODO: 3.0: Remove deprecated handling of master, only allow 'pylint.' sections
4950
warnings.warn(
@@ -60,6 +61,15 @@ def _parse_ini_file(file_path: Path) -> tuple[dict[str, str], list[str]]:
6061
options += [f"--{opt}", value]
6162
return config_content, options
6263

64+
@staticmethod
65+
def _ini_file_with_sections(file_path: str) -> bool:
66+
"""Return whether the file uses sections."""
67+
if "setup.cfg" in file_path:
68+
return True
69+
if "tox.ini" in file_path:
70+
return True
71+
return False
72+
6373
def _parse_toml_file(self, file_path: Path) -> tuple[dict[str, str], list[str]]:
6474
"""Parse and handle errors of a toml configuration file."""
6575
try:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; Test for https://github.com/PyCQA/pylint/issues/6800
2+
3+
[tox]
4+
skipsdist = True
5+
envlist = py3, pylint
6+
7+
[testenv]
8+
setenv = PYTHONWARNINGS=ignore
9+
10+
[testenv:pylint]
11+
deps =
12+
pylint
13+
14+
15+
[pylint]
16+
jobs = 10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"jobs": 10
3+
}

0 commit comments

Comments
 (0)