Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions src/sublime_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import concurrent.futures
import inspect
import io
import os
import sys
Expand Down Expand Up @@ -413,15 +414,11 @@ class ApplicationCommand(sublime_plugin.ApplicationCommand):
An async `Command` instantiated just once.
"""

def __init__(self):
""":meta private:"""
if not iscoroutinefunction(self.run):
raise TypeError(f"{type(self).__name__}.run() must be an asyncio coroutine function!")

def run_(self, edit_token: int, args: sublime.CommandArgs) -> None:
args = self.filter_args(args)
try:
call_coroutine(self.run(**args) if args else self.run())
if (maybe_coro := self.run(**args) if args else self.run()) and inspect.iscoroutine(maybe_coro):
call_coroutine(maybe_coro)
except TypeError as e:
if (
"required positional argument" in str(e)
Expand All @@ -448,17 +445,17 @@ class WindowCommand(sublime_plugin.WindowCommand):
retrieved via `self.window <window>`.
"""

def __init__(self, window: sublime.Window): # pyright: ignore[reportMissingSuperCall]
def __init__(self, window: sublime.Window):
""":meta private:"""
self.window: Window = Window(window.id()) # pyright: ignore[reportIncompatibleVariableOverride]
"""The asyncio supporting `Window` this command is attached to."""
if not iscoroutinefunction(self.run):
raise TypeError(f"{type(self).__name__}.run() must be an asyncio coroutine function!")

self.window: Window = Window(window.id())
""" The asyncio supporting `Window` this command is attached to. """

def run_(self, edit_token: int, args: sublime.CommandArgs) -> None:
args = self.filter_args(args)
try:
call_coroutine(self.run(**args) if args else self.run())
if (maybe_coro := self.run(**args) if args else self.run()) and inspect.iscoroutine(maybe_coro):
call_coroutine(maybe_coro)
except TypeError as e:
if (
"required positional argument" in str(e)
Expand Down Expand Up @@ -497,17 +494,13 @@ async def run(self):
```
"""

def __init__(self, view: sublime.View): # pyright: ignore[reportMissingSuperCall]
""":meta private:"""
self.view: View = View(view.id()) # pyright: ignore[reportIncompatibleVariableOverride]
"""The asyncio supporting `View` this command is attached to."""
if not iscoroutinefunction(self.run):
raise TypeError(f"{type(self).__name__}.run() must be an asyncio coroutine function!")

def run_(self, edit_token: int, args: sublime.CommandArgs) -> None:
args = self.filter_args(args)
try:
call_coroutine(self.run(**args) if args else self.run())
if inspect.iscoroutinefunction(self.run):
call_coroutine(self.run(**args) if args else self.run())
else:
self.run(edit_token, **args) if args else self.run(edit_token)
except TypeError as e:
if (
"required positional argument" in str(e)
Expand Down