Skip to content

Commit 1b042de

Browse files
authored
Update type stubs for Python 3.8 (#2535)
1 parent e29883a commit 1b042de

13 files changed

+817
-329
lines changed

plugin/completion.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def __init__(
178178
view: sublime.View,
179179
location: int,
180180
triggered_manually: bool,
181-
on_done_async: Callable[[list[sublime.CompletionItem], int], None]
181+
on_done_async: Callable[[list[sublime.CompletionItem], sublime.AutoCompleteFlags], None]
182182
) -> None:
183183
self._view = view
184184
self._location = location
@@ -212,7 +212,7 @@ def _resolve_completions_async(self, responses: list[ResolvedCompletions]) -> No
212212
items: list[sublime.CompletionItem] = []
213213
item_defaults: CompletionItemDefaults = {}
214214
errors: list[Error] = []
215-
flags = 0
215+
flags = sublime.AutoCompleteFlags.NONE
216216
prefs = userprefs()
217217
if prefs.inhibit_snippet_completions:
218218
flags |= sublime.INHIBIT_EXPLICIT_COMPLETIONS
@@ -263,7 +263,11 @@ def _cancel_pending_requests_async(self) -> None:
263263
session.cancel_request(request_id, False)
264264
self._pending_completion_requests.clear()
265265

266-
def _resolve_task_async(self, completions: list[sublime.CompletionItem], flags: int = 0) -> None:
266+
def _resolve_task_async(
267+
self,
268+
completions: list[sublime.CompletionItem],
269+
flags: sublime.AutoCompleteFlags = sublime.AutoCompleteFlags.NONE
270+
) -> None:
267271
if not self._resolved:
268272
self._resolved = True
269273
self._on_done_async(completions, flags)

plugin/core/open.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def lsp_range_from_uri_fragment(fragment: str) -> Range | None:
4545

4646

4747
def open_file_uri(
48-
window: sublime.Window, uri: DocumentUri, flags: int = 0, group: int = -1
48+
window: sublime.Window, uri: DocumentUri, flags: sublime.NewFileFlags = sublime.NewFileFlags.NONE, group: int = -1
4949
) -> Promise[sublime.View | None]:
5050

5151
decoded_uri = unquote(uri) # decode percent-encoded characters
@@ -84,7 +84,7 @@ def _find_open_file(window: sublime.Window, fname: str, group: int = -1) -> subl
8484

8585

8686
def open_file(
87-
window: sublime.Window, uri: DocumentUri, flags: int = 0, group: int = -1
87+
window: sublime.Window, uri: DocumentUri, flags: sublime.NewFileFlags = sublime.NewFileFlags.NONE, group: int = -1
8888
) -> Promise[sublime.View | None]:
8989
"""
9090
Open a file asynchronously.

plugin/core/registry.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def run(
174174
self,
175175
location: Location | LocationLink,
176176
session_name: str | None = None,
177-
flags: int = 0,
177+
flags: sublime.NewFileFlags = sublime.NewFileFlags.NONE,
178178
group: int = -1,
179179
event: dict | None = None
180180
) -> None:
@@ -191,7 +191,7 @@ def want_event(self) -> bool:
191191
return True
192192

193193
def _run_async(
194-
self, location: Location | LocationLink, session_name: str | None, flags: int, group: int
194+
self, location: Location | LocationLink, session_name: str | None, flags: sublime.NewFileFlags, group: int
195195
) -> None:
196196
session = self.session_by_name(session_name) if session_name else self.session()
197197
if session:

plugin/core/sessions.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -1686,7 +1686,7 @@ def try_open_uri_async(
16861686
self,
16871687
uri: DocumentUri,
16881688
r: Range | None = None,
1689-
flags: int = 0,
1689+
flags: sublime.NewFileFlags = sublime.NewFileFlags.NONE,
16901690
group: int = -1
16911691
) -> Promise[sublime.View | None] | None:
16921692
if uri.startswith("file:"):
@@ -1708,7 +1708,7 @@ def open_uri_async(
17081708
self,
17091709
uri: DocumentUri,
17101710
r: Range | None = None,
1711-
flags: int = 0,
1711+
flags: sublime.NewFileFlags = sublime.NewFileFlags.NONE,
17121712
group: int = -1
17131713
) -> Promise[sublime.View | None]:
17141714
promise = self.try_open_uri_async(uri, r, flags, group)
@@ -1718,7 +1718,7 @@ def _open_file_uri_async(
17181718
self,
17191719
uri: DocumentUri,
17201720
r: Range | None = None,
1721-
flags: int = 0,
1721+
flags: sublime.NewFileFlags = sublime.NewFileFlags.NONE,
17221722
group: int = -1
17231723
) -> Promise[sublime.View | None]:
17241724
result: PackagedTask[sublime.View | None] = Promise.packaged_task()
@@ -1736,7 +1736,7 @@ def _open_uri_with_plugin_async(
17361736
plugin: AbstractPlugin,
17371737
uri: DocumentUri,
17381738
r: Range | None,
1739-
flags: int,
1739+
flags: sublime.NewFileFlags,
17401740
group: int,
17411741
) -> Promise[sublime.View | None] | None:
17421742
# I cannot type-hint an unpacked tuple
@@ -1765,8 +1765,12 @@ def open_scratch_buffer(title: str, content: str, syntax: str) -> None:
17651765
return result[0]
17661766
return None
17671767

1768-
def open_location_async(self, location: Location | LocationLink, flags: int = 0,
1769-
group: int = -1) -> Promise[sublime.View | None]:
1768+
def open_location_async(
1769+
self,
1770+
location: Location | LocationLink,
1771+
flags: sublime.NewFileFlags = sublime.NewFileFlags.NONE,
1772+
group: int = -1
1773+
) -> Promise[sublime.View | None]:
17701774
uri, r = get_uri_and_range_from_location(location)
17711775
return self.open_uri_async(uri, r, flags, group)
17721776

plugin/core/types.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def r(name: str, default: bool | int | str | list | dict) -> None:
326326

327327
set_debug_logging(self.log_debug)
328328

329-
def highlight_style_region_flags(self, style_str: str) -> tuple[int, int]:
329+
def highlight_style_region_flags(self, style_str: str) -> tuple[sublime.RegionFlags, sublime.RegionFlags]:
330330
default = sublime.NO_UNDO
331331
if style_str in ("background", "fill"): # Backwards-compatible with "fill"
332332
style = default | sublime.DRAW_NO_OUTLINE
@@ -339,7 +339,7 @@ def highlight_style_region_flags(self, style_str: str) -> tuple[int, int]:
339339
return default | sublime.DRAW_NO_FILL, default | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE # noqa: E501
340340

341341
@staticmethod
342-
def _style_str_to_flag(style_str: str) -> int | None:
342+
def _style_str_to_flag(style_str: str) -> sublime.RegionFlags | None:
343343
default = sublime.DRAW_EMPTY_AS_OVERWRITE | sublime.DRAW_NO_FILL | sublime.NO_UNDO
344344
# This method could be a dict or lru_cache
345345
if style_str == "":
@@ -355,13 +355,13 @@ def _style_str_to_flag(style_str: str) -> int | None:
355355
# default style (includes NO_UNDO)
356356
return None
357357

358-
def diagnostics_highlight_style_flags(self) -> list[int | None]:
358+
def diagnostics_highlight_style_flags(self) -> list[sublime.RegionFlags | None]:
359359
"""Returns flags for highlighting diagnostics on single lines per severity"""
360360
if isinstance(self.diagnostics_highlight_style, str):
361361
# same style for all severity levels
362362
return [self._style_str_to_flag(self.diagnostics_highlight_style)] * 4
363363
elif isinstance(self.diagnostics_highlight_style, dict):
364-
flags: list[int | None] = []
364+
flags: list[sublime.RegionFlags | None] = []
365365
for sev in ("error", "warning", "info", "hint"):
366366
user_style = self.diagnostics_highlight_style.get(sev)
367367
if user_style is None: # user did not provide a style

plugin/core/views.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
_baseflags = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_EMPTY_AS_OVERWRITE | sublime.NO_UNDO
6060
_multilineflags = sublime.DRAW_NO_FILL | sublime.NO_UNDO
6161

62-
DIAGNOSTIC_SEVERITY: list[tuple[str, str, str, str, int, int]] = [
62+
DIAGNOSTIC_SEVERITY: list[tuple[str, str, str, str, sublime.RegionFlags, sublime.RegionFlags]] = [
6363
# Kind CSS class Scope for color Icon resource add_regions flags for single-line diagnostic multi-line diagnostic # noqa: E501
6464
("error", "errors", "region.redish markup.error.lsp", "Packages/LSP/icons/error.png", _baseflags | sublime.DRAW_SQUIGGLY_UNDERLINE, _multilineflags), # noqa: E501
6565
("warning", "warnings", "region.yellowish markup.warning.lsp", "Packages/LSP/icons/warning.png", _baseflags | sublime.DRAW_SQUIGGLY_UNDERLINE, _multilineflags), # noqa: E501
@@ -429,7 +429,7 @@ def show_lsp_popup(
429429
*,
430430
location: int = -1,
431431
md: bool = False,
432-
flags: int = 0,
432+
flags: sublime.PopupFlags = sublime.PopupFlags.NONE,
433433
css: str | None = None,
434434
wrapper_class: str | None = None,
435435
body_id: str | None = None,

plugin/documents.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def is_regular_view(v: sublime.View) -> bool:
106106
def previous_non_whitespace_char(view: sublime.View, pt: int) -> str:
107107
prev = view.substr(pt - 1)
108108
if prev.isspace():
109-
return view.substr(view.find_by_class(pt, False, ~0) - 1)
109+
return view.substr(view.find_by_class(pt, False, ~0) - 1) # type: ignore
110110
return prev
111111

112112

@@ -606,7 +606,10 @@ def _on_query_completions_async(
606606
self._completions_task.query_completions_async(sessions)
607607

608608
def _on_query_completions_resolved_async(
609-
self, clist: sublime.CompletionList, completions: list[sublime.CompletionItem], flags: int = 0
609+
self,
610+
clist: sublime.CompletionList,
611+
completions: list[sublime.CompletionItem],
612+
flags: sublime.AutoCompleteFlags = sublime.AutoCompleteFlags.NONE
610613
) -> None:
611614
self._completions_task = None
612615
# Resolve on the main thread to prevent any sort of data race for _set_target (see sublime_plugin.py).

plugin/formatting.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ def is_applicable(cls, view: sublime.View) -> bool:
9696
def run_async(self) -> None:
9797
super().run_async()
9898
self._purge_changes_async()
99-
base_scope = self._task_runner.view.syntax().scope
99+
syntax = self._task_runner.view.syntax()
100+
if not syntax:
101+
return
102+
base_scope = syntax.scope
100103
formatter = get_formatter(self._task_runner.view.window(), base_scope)
101104
format_document(self._task_runner, formatter).then(self._on_response)
102105

@@ -121,7 +124,10 @@ def is_enabled(self, event: dict | None = None, select: bool = False) -> bool:
121124

122125
def run(self, edit: sublime.Edit, event: dict | None = None, select: bool = False) -> None:
123126
session_names = [session.config.name for session in self.sessions(self.capability)]
124-
base_scope = self.view.syntax().scope
127+
syntax = self.view.syntax()
128+
if not syntax:
129+
return
130+
base_scope = syntax.scope
125131
if select:
126132
self.select_formatter(base_scope, session_names)
127133
elif len(session_names) > 1:

plugin/goto_diagnostic.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ def diagnostic_location(parsed_uri: ParsedUri, diagnostic: Diagnostic) -> Locati
261261
}
262262

263263

264-
def open_location(session: Session, location: Location, flags: int = 0, group: int = -1) -> sublime.View:
264+
def open_location(
265+
session: Session, location: Location, flags: sublime.NewFileFlags = sublime.NewFileFlags.NONE, group: int = -1
266+
) -> sublime.View:
265267
uri, position = get_uri_and_position_from_location(location)
266268
file_name = to_encoded_filename(session.config.map_server_uri_to_client_path(uri), position)
267269
return session.window.open_file(file_name, flags=flags | sublime.ENCODED_POSITION, group=group)

plugin/locationpicker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def open_basic_file(
4242
session: Session,
4343
uri: str,
4444
position: Position,
45-
flags: int = 0,
45+
flags: sublime.NewFileFlags = sublime.NewFileFlags.NONE,
4646
group: int | None = None
4747
) -> sublime.View | None:
4848
if group is None:

plugin/session_view.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def _draw_diagnostics(
317317
self,
318318
severity: int,
319319
max_severity_level: int,
320-
flags: int,
320+
flags: sublime.RegionFlags,
321321
multiline: bool
322322
) -> None:
323323
ICON_FLAGS = sublime.HIDE_ON_MINIMAP | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.NO_UNDO

0 commit comments

Comments
 (0)