|
26 | 26 | class _ConfigurationFileParser:
|
27 | 27 | """Class to parse various formats of configuration files."""
|
28 | 28 |
|
29 |
| - def __init__(self, verbose: bool, linter: PyLinter) -> None: |
| 29 | + def __init__(self, verbose: bool, linter: PyLinter | None = None) -> None: |
30 | 30 | self.verbose_mode = verbose
|
31 | 31 | self.linter = linter
|
32 | 32 |
|
@@ -64,7 +64,8 @@ def _parse_toml_file(self, file_path: Path) -> tuple[dict[str, str], list[str]]:
|
64 | 64 | with open(file_path, mode="rb") as fp:
|
65 | 65 | content = tomllib.load(fp)
|
66 | 66 | except tomllib.TOMLDecodeError as e:
|
67 |
| - self.linter.add_message("config-parse-error", line=0, args=str(e)) |
| 67 | + if self.linter is not None: |
| 68 | + self.linter.add_message("config-parse-error", line=0, args=str(e)) |
68 | 69 | return {}, []
|
69 | 70 |
|
70 | 71 | try:
|
@@ -109,5 +110,6 @@ def parse_config_file(
|
109 | 110 | return self._parse_toml_file(file_path)
|
110 | 111 | return self._parse_ini_file(file_path)
|
111 | 112 | except (configparser.Error, tomllib.TOMLDecodeError) as e:
|
112 |
| - self.linter.add_message("config-parse-error", line=0, args=str(e)) |
| 113 | + if self.linter is not None: |
| 114 | + self.linter.add_message("config-parse-error", line=0, args=str(e)) |
113 | 115 | return {}, []
|
0 commit comments