1717
1818# Eol chars accepted by the LSP protocol
1919# the ordering affects performance
20- EOL_CHARS = [' \r \n ' , ' \r ' , ' \n ' ]
20+ EOL_CHARS = [" \r \n " , " \r " , " \n " ]
2121EOL_REGEX = re .compile (f'({ "|" .join (EOL_CHARS )} )' )
2222
2323log = logging .getLogger (__name__ )
2424
2525
2626def debounce (interval_s , keyed_by = None ):
2727 """Debounce calls to this function until interval_s seconds have passed."""
28+
2829 def wrapper (func ):
2930 timers = {}
3031 lock = threading .Lock ()
@@ -48,7 +49,9 @@ def run():
4849 timer = threading .Timer (interval_s , run )
4950 timers [key ] = timer
5051 timer .start ()
52+
5153 return debounced
54+
5255 return wrapper
5356
5457
@@ -92,11 +95,11 @@ def path_to_dot_name(path):
9295 directory = os .path .dirname (path )
9396 module_name , _ = os .path .splitext (os .path .basename (path ))
9497 full_name = [module_name ]
95- while os .path .exists (os .path .join (directory , ' __init__.py' )):
98+ while os .path .exists (os .path .join (directory , " __init__.py" )):
9699 this_directory = os .path .basename (directory )
97100 directory = os .path .dirname (directory )
98101 full_name = [this_directory ] + full_name
99- return '.' .join (full_name )
102+ return "." .join (full_name )
100103
101104
102105def match_uri_to_workspace (uri , workspaces ):
@@ -128,6 +131,7 @@ def merge_dicts(dict_a, dict_b):
128131
129132 If override_nones is True, then
130133 """
134+
131135 def _merge_dicts_ (a , b ):
132136 for key in set (a .keys ()).union (b .keys ()):
133137 if key in a and key in b :
@@ -143,15 +147,16 @@ def _merge_dicts_(a, b):
143147 yield (key , a [key ])
144148 elif b [key ] is not None :
145149 yield (key , b [key ])
150+
146151 return dict (_merge_dicts_ (dict_a , dict_b ))
147152
148153
149154def escape_plain_text (contents : str ) -> str :
150155 """
151156 Format plain text to display nicely in environments which do not respect whitespaces.
152157 """
153- contents = contents .replace (' \t ' , ' \u00A0 ' * 4 )
154- contents = contents .replace (' ' , ' \u00A0 ' * 2 )
158+ contents = contents .replace (" \t " , " \u00A0 " * 4 )
159+ contents = contents .replace (" " , " \u00A0 " * 2 )
155160 return contents
156161
157162
@@ -160,17 +165,17 @@ def escape_markdown(contents: str) -> str:
160165 Format plain text to display nicely in Markdown environment.
161166 """
162167 # escape markdown syntax
163- contents = re .sub (r' ([\\*_#[\]])' , r' \\\1' , contents )
168+ contents = re .sub (r" ([\\*_#[\]])" , r" \\\1" , contents )
164169 # preserve white space characters
165170 contents = escape_plain_text (contents )
166171 return contents
167172
168173
169174def wrap_signature (signature ):
170- return ' ```python\n ' + signature + ' \n ```\n '
175+ return " ```python\n " + signature + " \n ```\n "
171176
172177
173- SERVER_SUPPORTED_MARKUP_KINDS = {' markdown' , ' plaintext' }
178+ SERVER_SUPPORTED_MARKUP_KINDS = {" markdown" , " plaintext" }
174179
175180
176181def choose_markup_kind (client_supported_markup_kinds : List [str ]):
@@ -181,7 +186,7 @@ def choose_markup_kind(client_supported_markup_kinds: List[str]):
181186 for kind in client_supported_markup_kinds :
182187 if kind in SERVER_SUPPORTED_MARKUP_KINDS :
183188 return kind
184- return ' markdown'
189+ return " markdown"
185190
186191
187192def format_docstring (contents : str , markup_kind : str , signatures : Optional [List [str ]] = None ):
@@ -195,33 +200,24 @@ def format_docstring(contents: str, markup_kind: str, signatures: Optional[List[
195200 to the provided contents of the docstring if given.
196201 """
197202 if not isinstance (contents , str ):
198- contents = ''
203+ contents = ""
199204
200- if markup_kind == ' markdown' :
205+ if markup_kind == " markdown" :
201206 try :
202207 value = docstring_to_markdown .convert (contents )
203- return {
204- 'kind' : 'markdown' ,
205- 'value' : value
206- }
208+ return {"kind" : "markdown" , "value" : value }
207209 except docstring_to_markdown .UnknownFormatError :
208210 # try to escape the Markdown syntax instead:
209211 value = escape_markdown (contents )
210212
211213 if signatures :
212- value = wrap_signature (' \n ' .join (signatures )) + ' \n \n ' + value
214+ value = wrap_signature (" \n " .join (signatures )) + " \n \n " + value
213215
214- return {
215- 'kind' : 'markdown' ,
216- 'value' : value
217- }
216+ return {"kind" : "markdown" , "value" : value }
218217 value = contents
219218 if signatures :
220- value = '\n ' .join (signatures ) + '\n \n ' + value
221- return {
222- 'kind' : 'plaintext' ,
223- 'value' : escape_plain_text (value )
224- }
219+ value = "\n " .join (signatures ) + "\n \n " + value
220+ return {"kind" : "plaintext" , "value" : escape_plain_text (value )}
225221
226222
227223def clip_column (column , lines , line_number ):
@@ -230,7 +226,7 @@ def clip_column(column, lines, line_number):
230226
231227 https://microsoft.github.io/language-server-protocol/specification#position
232228 """
233- max_column = len (lines [line_number ].rstrip (' \r \n ' )) if len (lines ) > line_number else 0
229+ max_column = len (lines [line_number ].rstrip (" \r \n " )) if len (lines ) > line_number else 0
234230 return min (column , max_column )
235231
236232
@@ -242,14 +238,14 @@ def position_to_jedi_linecolumn(document, position):
242238 """
243239 code_position = {}
244240 if position :
245- code_position = {'line' : position [ 'line' ] + 1 ,
246- 'column' : clip_column ( position ['character' ] ,
247- document .lines ,
248- position [ 'line' ]) }
241+ code_position = {
242+ "line" : position ["line" ] + 1 ,
243+ "column" : clip_column ( position [ "character" ], document .lines , position [ "line" ]) ,
244+ }
249245 return code_position
250246
251247
252- if os .name == 'nt' :
248+ if os .name == "nt" :
253249 import ctypes
254250
255251 kernel32 = ctypes .windll .kernel32
0 commit comments