10
10
from subprocess import Popen , PIPE
11
11
import os
12
12
import shlex
13
+ from typing import Optional , TypedDict
13
14
14
15
from pylsp import hookimpl , lsp
15
16
from pylsp .config .config import Config
47
48
}
48
49
49
50
51
+ class PylintConfig (TypedDict ):
52
+ """Pylint configuration settings."""
53
+
54
+ enabled : Optional [bool ]
55
+ args : Optional [list [str ]]
56
+ executable : Optional [str ]
57
+
58
+
50
59
class PylintLinter :
51
60
last_diags : dict [str , list [Diagnostic ]] = collections .defaultdict (list )
52
61
@@ -193,7 +202,7 @@ def lint(
193
202
return diagnostics
194
203
195
204
196
- def _build_pylint_flags (settings : dict ) -> str :
205
+ def _build_pylint_flags (settings : PylintConfig ) -> str :
197
206
"""Build arguments for calling pylint."""
198
207
pylint_args = settings .get ("args" )
199
208
if pylint_args is None :
@@ -203,18 +212,16 @@ def _build_pylint_flags(settings: dict) -> str:
203
212
204
213
@hookimpl
205
214
def pylsp_settings () -> dict :
215
+ """Get the default pylint plugin settings."""
206
216
# Default pylint to disabled because it requires a config
207
217
# 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 ,
217
223
}
224
+ return {"plugins" : {"pylint" : pylint_config }}
218
225
219
226
220
227
@hookimpl
@@ -223,19 +230,19 @@ def pylsp_lint(
223
230
) -> list [Diagnostic ]:
224
231
"""Run pylint linter."""
225
232
with workspace .report_progress ("lint: pylint" ):
226
- settings = config .plugin_settings ("pylint" )
233
+ settings : PylintConfig = config .plugin_settings ("pylint" )
227
234
log .debug ("Got pylint settings: %s" , settings )
228
235
# pylint >= 2.5.0 is required for working through stdin and only
229
236
# available with python3
230
237
if settings .get ("executable" ) and sys .version_info [0 ] >= 3 :
231
238
flag_list = build_args_stdio (settings )
232
- pylint_executable = settings . get ( "executable" , "pylint" )
239
+ pylint_executable = settings [ "executable" ] or "pylint"
233
240
return pylint_lint_stdin (pylint_executable , document , flag_list )
234
241
flags = _build_pylint_flags (settings )
235
242
return PylintLinter .lint (document , is_saved , flags = flags )
236
243
237
244
238
- def build_args_stdio (settings : dict ) -> list [str ]:
245
+ def build_args_stdio (settings : PylintConfig ) -> list [str ]:
239
246
"""Build arguments for calling pylint.
240
247
241
248
:param settings: client settings
@@ -244,7 +251,7 @@ def build_args_stdio(settings: dict) -> list[str]:
244
251
:return: arguments to path to pylint
245
252
:rtype: list
246
253
"""
247
- pylint_args = settings . get ( "args" )
254
+ pylint_args = settings [ "args" ]
248
255
if pylint_args is None :
249
256
return []
250
257
return pylint_args
0 commit comments