Skip to content

Commit 239cb58

Browse files
authored
Various fixes for sublime_plugin stubs. (#167)
* Various fixes for sublime_plugin stubs. * More fixes for type stubs. * Address comments. * Fix a couple return types. * Fix substr parameter type.
1 parent 4dad2ea commit 239cb58

File tree

2 files changed

+47
-34
lines changed

2 files changed

+47
-34
lines changed

stubs/sublime.pyi

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def active_window() -> Window: ...
106106
def windows() -> List[Window]: ...
107107
def get_macro() -> list: ...
108108

109-
class Window(object):
109+
class Window:
110110
def __init__(self, id: int): ...
111111
def __eq__(self, other: Any) -> bool: ...
112112
def __bool__(self) -> bool: ...
@@ -186,10 +186,10 @@ class Window(object):
186186
def extract_variables(self) -> dict: ...
187187
def status_message(self, msg: str) -> None: ...
188188

189-
class Edit(object):
189+
class Edit:
190190
def __init__(self, token: int) -> None: ...
191191

192-
class Region(object):
192+
class Region:
193193
__slots__ = ['a', 'b', 'xpos']
194194

195195
a = 0 # type: int
@@ -211,7 +211,7 @@ class Region(object):
211211
def intersection(self, rhs: Region) -> Region: ...
212212
def intersects(self, rhs: Region) -> bool: ...
213213

214-
class Selection(object):
214+
class Selection:
215215
def __init__(self, id: int) -> None: ...
216216
def __len__(self) -> int: ...
217217
def __getitem__(self, index: int) -> Region: ...
@@ -226,14 +226,14 @@ class Selection(object):
226226
def subtract(self, region: Region) -> None: ...
227227
def contains(self, region: Region) -> bool: ...
228228

229-
class Sheet(object):
229+
class Sheet:
230230
def __init__(self, id: int) -> None: ...
231231
def __eq__(self, other: Any) -> bool: ...
232232
def id(self) -> int: ...
233233
def window(self) -> Optional[Window]: ...
234234
def view(self) -> Optional[View]: ...
235235

236-
class View(object):
236+
class View:
237237
def __init__(self, id: int) -> None: ...
238238
def __len__(self) -> int: ...
239239
def __eq__(self, other: Any) -> bool: ...
@@ -270,11 +270,11 @@ class View(object):
270270
def change_count(self) -> int: ...
271271
def run_command(self, cmd: str, args: Optional[dict] = None) -> None: ...
272272
def sel(self) -> Selection: ...
273-
def substr(self, x: Region) -> str: ...
273+
def substr(self, x: Union[Region, int]) -> str: ...
274274
def find(self, pattern: str, start_pt: int, flags: int = 0) -> Region: ...
275275
def find_all(self, pattern: str, flags: int = 0, fmt: Optional[str] = None, extractions: Optional[list] = None) -> List[Region]: ...
276276
def settings(self) -> Settings: ...
277-
def meta_info(self, key: str, pt: int) -> str: ...
277+
def meta_info(self, key: str, pt: int) -> dict: ...
278278
def extract_tokens_with_scopes(self, r: Region) -> List[Tuple[Region, str]]: ...
279279
def extract_scope(self, pt: int) -> Region: ...
280280
def scope_name(self, pt: int) -> str: ...
@@ -355,7 +355,7 @@ class View(object):
355355
def hide_popup(self) -> None: ...
356356
def is_auto_complete_visible(self) -> bool: ...
357357

358-
class Settings(object):
358+
class Settings:
359359
settings_id: int
360360

361361
def __init__(self, id: int) -> None: ...
@@ -366,16 +366,16 @@ class Settings(object):
366366
def add_on_change(self, tag: str, callback: Callable[[], Any]) -> None: ...
367367
def clear_on_change(self, tag: str) -> None: ...
368368

369-
class Phantom(object):
369+
class Phantom:
370370
def __init__(self, region: Region, content: str, layout: int, on_navigate: Callable[[str], Any] = None) -> None: ...
371371
def __eq__(self, rhs: Any) -> bool: ...
372372

373-
class PhantomSet(object):
373+
class PhantomSet:
374374
def __init__(self, view: View, key: str = "") -> None: ...
375375
def __del__(self) -> None: ...
376376
def update(self, new_phantoms: List[Phantom]) -> None: ...
377377

378-
class Html(object):
378+
class Html:
379379
__slots__ = ['data']
380380

381381
def __init__(self, data: Any) -> None: ...

stubs/sublime_plugin.pyi

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
11
import sublime
2-
from typing import Optional, Union, List, Dict, Tuple
32

3+
from typing import Callable, Generic, TypeVar, Optional, Union, List, Tuple, overload
44

5-
class CommandInputHandler():
5+
6+
InputType = TypeVar('InputType', bound=Union[str, int, float, list, dict, tuple, None])
7+
8+
9+
class CommandInputHandler(Generic[InputType]):
610
def name(self) -> str: ...
711
def next_input(self, args: dict) -> Optional[CommandInputHandler]: ...
812
def placeholder(self) -> str: ...
913
def initial_text(self) -> str: ...
10-
def preview(self, arg: dict) -> Union[str, sublime.Html]: ...
11-
def validate(self, arg: dict) -> bool: ...
14+
def preview(self, arg: InputType) -> Union[str, sublime.Html]: ...
15+
def validate(self, arg: InputType) -> bool: ...
1216
def cancel(self) -> None: ...
13-
def confirm(self, arg: dict) -> None: ...
17+
18+
@overload
19+
def confirm(self, arg: InputType) -> None: ...
20+
@overload
21+
def confirm(self, arg: InputType, event: dict) -> None: ...
1422

1523

16-
class BackInputHandler(CommandInputHandler):
24+
class BackInputHandler(CommandInputHandler[None]):
1725
pass
1826

1927

20-
class TextInputHandler(CommandInputHandler):
28+
class TextInputHandler(CommandInputHandler[str]):
2129
def description(self, text: str) -> str: ...
2230

2331

24-
class ListInputHandler(CommandInputHandler):
25-
def list_items(self) -> list: ...
32+
ListItem = Union[str, Tuple[str, InputType]]
33+
34+
35+
class ListInputHandler(CommandInputHandler[InputType], Generic[InputType]):
36+
def list_items(self) -> Union[List[ListItem], Tuple[List[ListItem], int]]: ...
2637
def description(self, v: object, text: str) -> str: ...
2738

2839

29-
class Command():
40+
class Command:
3041
def is_enabled(self) -> bool: ...
3142
def is_visible(self) -> bool: ...
3243
def is_checked(self) -> bool: ...
@@ -36,23 +47,25 @@ class Command():
3647

3748

3849
class ApplicationCommand(Command):
39-
def run(self) -> None: ...
50+
run: Callable[..., None]
4051

4152

4253
class WindowCommand(Command):
4354
window: sublime.Window
4455

45-
def run(self) -> None: ...
56+
run: Callable[..., None]
4657

4758

4859
class TextCommand(Command):
4960
view: sublime.View
5061

51-
def run(self, edit: sublime.Edit) -> None: ...
62+
run: Callable[..., None]
5263
def want_event(self) -> bool: ...
5364

5465

55-
class EventListener():
66+
Completion = Union[str, Tuple[str, str], List[str]]
67+
68+
class EventListener:
5669
def on_new(self, view: sublime.View) -> None: ...
5770
def on_new_async(self, view: sublime.View) -> None: ...
5871
def on_clone(self, view: sublime.View) -> None: ...
@@ -74,15 +87,15 @@ class EventListener():
7487
def on_deactivated(self, view: sublime.View) -> None: ...
7588
def on_deactivated_async(self, view: sublime.View) -> None: ...
7689
def on_hover(self, view: sublime.View, point: int, hover_zone: int) -> None: ...
77-
def on_query_context(self, view: sublime.View, key: str, operator: int, operand: str, match_all: bool) -> Optional[None]: ...
78-
def on_query_completions(self, view: sublime.View, prefix: str, locations: List[int]) -> Union[None, list, tuple]: ...
79-
def on_text_command(self, view: sublime.View, command_name: str, args: dict) -> Tuple[str, dict]: ...
90+
def on_query_context(self, view: sublime.View, key: str, operator: int, operand: str, match_all: bool) -> Optional[bool]: ...
91+
def on_query_completions(self, view: sublime.View, prefix: str, locations: List[int]) -> Union[None, List[Completion], Tuple[List[Completion], int]]: ...
92+
def on_text_command(self, view: sublime.View, command_name: str, args: dict) -> Optional[Tuple[str, dict]]: ...
8093
def on_post_text_command(self, view: sublime.View, command_name: str, args: dict) -> None: ...
81-
def on_window_command(self, view: sublime.Window, command_name: str, args: dict) -> Tuple[str, dict]: ...
94+
def on_window_command(self, view: sublime.Window, command_name: str, args: dict) -> Optional[Tuple[str, dict]]: ...
8295
def on_post_window_command(self, view: sublime.Window, command_name: str, args: dict) -> None: ...
8396

8497

85-
class ViewEventListener():
98+
class ViewEventListener:
8699
view: sublime.View
87100

88101
@classmethod
@@ -108,7 +121,7 @@ class ViewEventListener():
108121
def on_deactivated_modified(self) -> None: ...
109122
def on_deactivated_modified_async(self) -> None: ...
110123
def on_hover(self, point: int, hover_zone: int) -> None: ...
111-
def on_query_context(self, key: str, operator: int, operand: str, match_all: bool) -> Optional[None]: ...
112-
def on_query_completions(self, prefix: str, locations: List[int]) -> Union[None, list, tuple]: ...
113-
def on_text_command(self, command_name: str, args: dict) -> Tuple[str, dict]: ...
124+
def on_query_context(self, key: str, operator: int, operand: str, match_all: bool) -> Optional[bool]: ...
125+
def on_query_completions(self, prefix: str, locations: List[int]) -> Union[None, List[Completion], Tuple[List[Completion], int]]: ...
126+
def on_text_command(self, command_name: str, args: dict) -> Optional[Tuple[str, dict]]: ...
114127
def on_post_text_command(self, command_name: str, args: dict) -> None: ...

0 commit comments

Comments
 (0)