11# -*- coding: utf-8 -*-
22"""
3- File that contains the pylsp plugin mypy-ls.
3+ File that contains the python-lsp-server plugin mypy-ls.
44
55Created on Fri Jul 10 09:53:57 2020
66
2727tmpFile : Optional [IO [str ]] = None
2828
2929
30- def parse_line (
31- line : str , document : Optional [Document ] = None
32- ) -> Optional [Dict [str , Any ]]:
30+ def parse_line (line : str , document : Optional [Document ] = None ) -> Optional [Dict [str , Any ]]:
3331 """
3432 Return a language-server diagnostic from a line of the Mypy error report.
3533
@@ -56,44 +54,42 @@ def parse_line(
5654 if file_path != "<string>" : # live mode
5755 # results from other files can be included, but we cannot return
5856 # them.
59- if document and document .path and not document .path .endswith (file_path ):
60- log . warning (
61- "discarding result for %s against %s" , file_path , document . path
62- )
57+ if document and document .path and not document .path .endswith (
58+ file_path ):
59+ log . warning ( "discarding result for %s against %s" , file_path ,
60+ document . path )
6361 return None
6462
6563 lineno = int (linenoStr or 1 ) - 1 # 0-based line number
6664 offset = int (offsetStr or 1 ) - 1 # 0-based offset
6765 errno = 2
68- if severity == " error" :
66+ if severity == ' error' :
6967 errno = 1
7068 diag : Dict [str , Any ] = {
71- " source" : " mypy" ,
72- " range" : {
73- " start" : {" line" : lineno , " character" : offset },
69+ ' source' : ' mypy' ,
70+ ' range' : {
71+ ' start' : {' line' : lineno , ' character' : offset },
7472 # There may be a better solution, but mypy does not provide end
75- " end" : {" line" : lineno , " character" : offset + 1 },
73+ ' end' : {' line' : lineno , ' character' : offset + 1 }
7674 },
77- " message" : msg ,
78- " severity" : errno ,
75+ ' message' : msg ,
76+ ' severity' : errno
7977 }
8078 if document :
8179 # although mypy does not provide the end of the affected range, we
8280 # can make a good guess by highlighting the word that Mypy flagged
83- word = document .word_at_position (diag [" range" ][ " start" ])
81+ word = document .word_at_position (diag [' range' ][ ' start' ])
8482 if word :
85- diag ["range" ]["end" ]["character" ] = diag ["range" ]["start" ][
86- "character"
87- ] + len (word )
83+ diag ['range' ]['end' ]['character' ] = (
84+ diag ['range' ]['start' ]['character' ] + len (word ))
8885
8986 return diag
9087 return None
9188
9289
9390@hookimpl
94- def pylsp_lint (
95- config : Config , workspace : Workspace , document : Document , is_saved : bool
96- ) -> List [Dict [str , Any ]]:
91+ def pylsp_lint (config : Config , workspace : Workspace , document : Document ,
92+ is_saved : bool ) -> List [Dict [str , Any ]]:
9793 """
9894 Lints.
9995
@@ -114,25 +110,27 @@ def pylsp_lint(
114110 List of the linting data.
115111
116112 """
117- settings = config .plugin_settings ("mypy-ls" )
118- live_mode = settings .get ("live_mode" , True )
119- args = ["--incremental" , "--show-column-numbers" , "--follow-imports" , "silent" ]
113+ settings = config .plugin_settings ('mypy-ls' )
114+ live_mode = settings .get ('live_mode' , True )
115+ args = ['--incremental' ,
116+ '--show-column-numbers' ,
117+ '--follow-imports' , 'silent' ]
120118
121119 global tmpFile
122120 if live_mode and not is_saved and tmpFile :
123121 tmpFile = open (tmpFile .name , "w" )
124122 tmpFile .write (document .source )
125123 tmpFile .close ()
126- args .extend ([" --shadow-file" , document .path , tmpFile .name ])
124+ args .extend ([' --shadow-file' , document .path , tmpFile .name ])
127125 elif not is_saved :
128126 return []
129127
130128 if mypyConfigFile :
131- args .append (" --config-file" )
129+ args .append (' --config-file' )
132130 args .append (mypyConfigFile )
133131 args .append (document .path )
134- if settings .get (" strict" , False ):
135- args .append (" --strict" )
132+ if settings .get (' strict' , False ):
133+ args .append (' --strict' )
136134
137135 report , errors , _ = mypy_api .run (args )
138136
@@ -189,11 +187,10 @@ def init(workspace: str) -> Dict[str, str]:
189187 configuration = eval (file .read ())
190188 global mypyConfigFile
191189 mypyConfigFile = findConfigFile (workspace , "mypy.ini" )
192- if ("enabled" not in configuration or configuration ["enabled" ]) and (
193- "live_mode" not in configuration or configuration ["live_mode" ]
194- ):
190+ if (("enabled" not in configuration or configuration ["enabled" ])
191+ and ("live_mode" not in configuration or configuration ["live_mode" ])):
195192 global tmpFile
196- tmpFile = tempfile .NamedTemporaryFile ("w" , delete = False )
193+ tmpFile = tempfile .NamedTemporaryFile ('w' , delete = False )
197194 tmpFile .close ()
198195 return configuration
199196
0 commit comments