Skip to content

Commit

Permalink
Handle invalid .cfg when assessing if they contain a pylint config
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Mar 31, 2022
1 parent 592f133 commit bb84699
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pylint/config/find_default_config_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def _toml_has_config(path: Union[Path, str]) -> bool:

def _cfg_has_config(path: Union[Path, str]) -> bool:
parser = configparser.ConfigParser()
parser.read(path, encoding="utf-8")
try:
parser.read(path, encoding="utf-8")
except configparser.Error:
return False
return any(section.startswith("pylint.") for section in parser.sections())


Expand Down
1 change: 1 addition & 0 deletions tests/config/test_find_default_config_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_toml_has_config(content: str, expected: bool, tmp_path: Path) -> None:
"content,expected",
[
["", False],
["(not valid .cfg)", False],
[
"""
[metadata]
Expand Down

0 comments on commit bb84699

Please sign in to comment.