Skip to content

Commit 160c98e

Browse files
committed
🧹 add types for pylint config
1 parent 14e6c2b commit 160c98e

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

pylsp/plugins/pylint_lint.py

+21-14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from subprocess import Popen, PIPE
1111
import os
1212
import shlex
13+
from typing import Optional, TypedDict
1314

1415
from pylsp import hookimpl, lsp
1516
from pylsp.config.config import Config
@@ -47,6 +48,14 @@
4748
}
4849

4950

51+
class PylintConfig(TypedDict):
52+
"""Pylint configuration settings."""
53+
54+
enabled: Optional[bool]
55+
args: Optional[list[str]]
56+
executable: Optional[str]
57+
58+
5059
class PylintLinter:
5160
last_diags: dict[str, list[Diagnostic]] = collections.defaultdict(list)
5261

@@ -193,7 +202,7 @@ def lint(
193202
return diagnostics
194203

195204

196-
def _build_pylint_flags(settings: dict) -> str:
205+
def _build_pylint_flags(settings: PylintConfig) -> str:
197206
"""Build arguments for calling pylint."""
198207
pylint_args = settings.get("args")
199208
if pylint_args is None:
@@ -203,18 +212,16 @@ def _build_pylint_flags(settings: dict) -> str:
203212

204213
@hookimpl
205214
def pylsp_settings() -> dict:
215+
"""Get the default pylint plugin settings."""
206216
# Default pylint to disabled because it requires a config
207217
# file to be useful.
208-
return {
209-
"plugins": {
210-
"pylint": {
211-
"enabled": False,
212-
"args": [],
213-
# disabled by default as it can slow down the workflow
214-
"executable": None,
215-
}
216-
}
218+
pylint_config: PylintConfig = {
219+
"enabled": False,
220+
"args": [],
221+
# disabled by default as it can slow down the workflow
222+
"executable": None,
217223
}
224+
return {"plugins": {"pylint": pylint_config}}
218225

219226

220227
@hookimpl
@@ -223,19 +230,19 @@ def pylsp_lint(
223230
) -> list[Diagnostic]:
224231
"""Run pylint linter."""
225232
with workspace.report_progress("lint: pylint"):
226-
settings = config.plugin_settings("pylint")
233+
settings: PylintConfig = config.plugin_settings("pylint")
227234
log.debug("Got pylint settings: %s", settings)
228235
# pylint >= 2.5.0 is required for working through stdin and only
229236
# available with python3
230237
if settings.get("executable") and sys.version_info[0] >= 3:
231238
flag_list = build_args_stdio(settings)
232-
pylint_executable = settings.get("executable", "pylint")
239+
pylint_executable = settings["executable"] or "pylint"
233240
return pylint_lint_stdin(pylint_executable, document, flag_list)
234241
flags = _build_pylint_flags(settings)
235242
return PylintLinter.lint(document, is_saved, flags=flags)
236243

237244

238-
def build_args_stdio(settings: dict) -> list[str]:
245+
def build_args_stdio(settings: PylintConfig) -> list[str]:
239246
"""Build arguments for calling pylint.
240247
241248
:param settings: client settings
@@ -244,7 +251,7 @@ def build_args_stdio(settings: dict) -> list[str]:
244251
:return: arguments to path to pylint
245252
:rtype: list
246253
"""
247-
pylint_args = settings.get("args")
254+
pylint_args = settings["args"]
248255
if pylint_args is None:
249256
return []
250257
return pylint_args

0 commit comments

Comments
 (0)