1818import tempfile
1919from configparser import ConfigParser
2020from pathlib import Path
21- from typing import IO , Any , Dict , List , Optional
21+ from typing import IO , Any , Optional
2222
2323try :
2424 import tomllib
4747log = logging .getLogger (__name__ )
4848
4949# A mapping from workspace path to config file path
50- mypyConfigFileMap : Dict [str , Optional [str ]] = {}
50+ mypyConfigFileMap : dict [str , Optional [str ]] = {}
5151
52- settingsCache : Dict [str , Dict [str , Any ]] = {}
52+ settingsCache : dict [str , dict [str , Any ]] = {}
5353
5454tmpFile : Optional [IO [bytes ]] = None
5555
5858# so store a cache of last diagnostics for each file a-la the pylint plugin,
5959# so we can return some potentially-stale diagnostics.
6060# https://github.com/python-lsp/python-lsp-server/blob/v1.0.1/pylsp/plugins/pylint_lint.py#L55-L62
61- last_diagnostics : Dict [str , List [ Dict [str , Any ]]] = collections .defaultdict (list )
61+ last_diagnostics : dict [str , list [ dict [str , Any ]]] = collections .defaultdict (list )
6262
6363# Windows started opening opening a cmd-like window for every subprocess call
6464# This flag prevents that.
6565# This flag is new in python 3.7
6666# This flag only exists on Windows
67- windows_flag : Dict [str , int ] = (
67+ windows_flag : dict [str , int ] = (
6868 {"creationflags" : subprocess .CREATE_NO_WINDOW } if os .name == "nt" else {} # type: ignore
6969)
7070
7171
72- def parse_line (line : str , document : Optional [Document ] = None ) -> Optional [Dict [str , Any ]]:
72+ def parse_line (line : str , document : Optional [Document ] = None ) -> Optional [dict [str , Any ]]:
7373 """
7474 Return a language-server diagnostic from a line of the Mypy error report.
7575
@@ -128,7 +128,7 @@ def parse_line(line: str, document: Optional[Document] = None) -> Optional[Dict[
128128 return diag
129129
130130
131- def apply_overrides (args : List [str ], overrides : List [Any ]) -> List [str ]:
131+ def apply_overrides (args : list [str ], overrides : list [Any ]) -> list [str ]:
132132 """Replace or combine default command-line options with overrides."""
133133 overrides_iterator = iter (overrides )
134134 if True not in overrides_iterator :
@@ -140,7 +140,7 @@ def apply_overrides(args: List[str], overrides: List[Any]) -> List[str]:
140140 return overrides [: - (len (rest ) + 1 )] + args + rest
141141
142142
143- def didSettingsChange (workspace : str , settings : Dict [str , Any ]) -> None :
143+ def didSettingsChange (workspace : str , settings : dict [str , Any ]) -> None :
144144 """Handle relevant changes to the settings between runs."""
145145 configSubPaths = settings .get ("config_sub_paths" , [])
146146 if settingsCache [workspace ].get ("config_sub_paths" , []) != configSubPaths :
@@ -169,14 +169,14 @@ def match_exclude_patterns(document_path: str, exclude_patterns: list[str]) -> b
169169 return False
170170
171171
172- def get_cmd (settings : Dict [str , Any ], cmd : str ) -> List [str ]:
172+ def get_cmd (settings : dict [str , Any ], cmd : str ) -> list [str ]:
173173 """
174174 Get the command to run from settings, falling back to searching the PATH.
175175 If the command is not found in the settings and is not available on the PATH, an
176176 empty list is returned.
177177 """
178178 command_key = f"{ cmd } _command"
179- command : List [str ] = settings .get (command_key , [])
179+ command : list [str ] = settings .get (command_key , [])
180180
181181 if not (command and os .getenv ("PYLSP_MYPY_ALLOW_DANGEROUS_CODE_EXECUTION" )):
182182 # env var is required to allow command from settings
@@ -196,7 +196,7 @@ def get_cmd(settings: Dict[str, Any], cmd: str) -> List[str]:
196196@hookimpl
197197def pylsp_lint (
198198 config : Config , workspace : Workspace , document : Document , is_saved : bool
199- ) -> List [ Dict [str , Any ]]:
199+ ) -> list [ dict [str , Any ]]:
200200 """
201201 Call the linter.
202202
@@ -254,9 +254,9 @@ def pylsp_lint(
254254def get_diagnostics (
255255 workspace : Workspace ,
256256 document : Document ,
257- settings : Dict [str , Any ],
257+ settings : dict [str , Any ],
258258 is_saved : bool ,
259- ) -> List [ Dict [str , Any ]]:
259+ ) -> list [ dict [str , Any ]]:
260260 """
261261 Lints.
262262
@@ -332,7 +332,7 @@ def get_diagnostics(
332332 args .extend (["--incremental" , "--follow-imports" , settings .get ("follow-imports" , "silent" )])
333333 args = apply_overrides (args , overrides )
334334
335- mypy_command : List [str ] = get_cmd (settings , "mypy" )
335+ mypy_command : list [str ] = get_cmd (settings , "mypy" )
336336
337337 if mypy_command :
338338 # mypy exists on PATH or was provided by settings
@@ -357,7 +357,7 @@ def get_diagnostics(
357357 # If daemon is dead/absent, kill will no-op.
358358 # In either case, reset to fresh state
359359
360- dmypy_command : List [str ] = get_cmd (settings , "dmypy" )
360+ dmypy_command : list [str ] = get_cmd (settings , "dmypy" )
361361
362362 if dmypy_command :
363363 # dmypy exists on PATH or was provided by settings
@@ -449,7 +449,7 @@ def get_diagnostics(
449449
450450
451451@hookimpl
452- def pylsp_settings (config : Config ) -> Dict [str , Dict [str , Dict [str , str ]]]:
452+ def pylsp_settings (config : Config ) -> dict [str , dict [str , dict [str , str ]]]:
453453 """
454454 Read the settings.
455455
@@ -468,7 +468,7 @@ def pylsp_settings(config: Config) -> Dict[str, Dict[str, Dict[str, str]]]:
468468 return {"plugins" : {"pylsp_mypy" : configuration }}
469469
470470
471- def init (workspace : str ) -> Dict [str , str ]:
471+ def init (workspace : str ) -> dict [str , str ]:
472472 """
473473 Find plugin and mypy config files and creates the temp file should it be used.
474474
@@ -509,7 +509,7 @@ def init(workspace: str) -> Dict[str, str]:
509509
510510
511511def findConfigFile (
512- path : str , configSubPaths : List [str ], names : List [str ], mypy : bool
512+ path : str , configSubPaths : list [str ], names : list [str ], mypy : bool
513513) -> Optional [str ]:
514514 """
515515 Search for a config file.
@@ -580,9 +580,9 @@ def pylsp_code_actions(
580580 config : Config ,
581581 workspace : Workspace ,
582582 document : Document ,
583- range : Dict [str , Any ],
584- context : Dict [str , Any ],
585- ) -> List [ Dict [str , Any ]]:
583+ range : dict [str , Any ],
584+ context : dict [str , Any ],
585+ ) -> list [ dict [str , Any ]]:
586586 """
587587 Provide code actions to ignore errors.
588588
0 commit comments