Skip to content

Commit

Permalink
refactor exceptions to exceptions module
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Apr 5, 2024
1 parent f1b19b7 commit f9ef0aa
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
4 changes: 1 addition & 3 deletions ahk/_async/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
)
from ahk._utils import _version_detection_script
from ahk.directives import Directive
from ahk.exceptions import AHKProtocolError

from concurrent.futures import Future, ThreadPoolExecutor

Expand All @@ -58,9 +59,6 @@
T_SyncFuture = TypeVar('T_SyncFuture')


class AHKProtocolError(Exception): ...


class AsyncFutureResult(Generic[T_AsyncFuture]): # unasync: remove
def __init__(self, task: asyncio.Task[T_AsyncFuture]):
self._task: asyncio.Task[T_AsyncFuture] = task
Expand Down
4 changes: 1 addition & 3 deletions ahk/_async/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from typing import TypeVar
from typing import Union

from ahk.exceptions import WindowNotFoundException
from ahk.message import Position

if sys.version_info < (3, 10):
Expand All @@ -31,9 +32,6 @@
from .transport import AsyncFutureResult


class WindowNotFoundException(Exception): ...


AsyncPropertyReturnStr: TypeAlias = Coroutine[None, None, str] # unasync: remove
SyncPropertyReturnStr: TypeAlias = str

Expand Down
2 changes: 1 addition & 1 deletion ahk/_sync/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@
)
from ahk._utils import _version_detection_script
from ahk.directives import Directive
from ahk.exceptions import AHKProtocolError

from concurrent.futures import Future, ThreadPoolExecutor


T_SyncFuture = TypeVar('T_SyncFuture')


class AHKProtocolError(Exception): ...



Expand Down
2 changes: 1 addition & 1 deletion ahk/_sync/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from typing import TypeVar
from typing import Union

from ahk.exceptions import WindowNotFoundException
from ahk.message import Position

if sys.version_info < (3, 10):
Expand All @@ -31,7 +32,6 @@
from .transport import FutureResult


class WindowNotFoundException(Exception): ...


SyncPropertyReturnStr: TypeAlias = str
Expand Down
6 changes: 2 additions & 4 deletions ahk/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from typing import Literal
from typing import Optional

from ahk.exceptions import AhkExecutableNotFoundError

HOTKEY_ESCAPE_SEQUENCE_MAP = {
'\n': '`n',
'\t': '`t',
Expand Down Expand Up @@ -84,10 +86,6 @@ class MsgBoxOtherOptions(enum.IntEnum):
DEFAULT_EXECUTABLE_PATH_V2 = r'C:\Program Files\AutoHotkey\v2\AutoHotkey64.exe'


class AhkExecutableNotFoundError(EnvironmentError):
pass


def _resolve_executable_path(executable_path: str = '', version: Optional[Literal['v1', 'v2']] = None) -> str:
if not executable_path:
executable_path = (
Expand Down
14 changes: 14 additions & 0 deletions ahk/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
class AHKBaseException(Exception):
# TODO: make existing exceptions subclasses of this
...


class WindowNotFoundException(AHKBaseException): ...


class AHKProtocolError(AHKBaseException): ...


class AHKExecutionException(AHKBaseException):
pass


class AhkExecutableNotFoundError(AHKBaseException, EnvironmentError):
pass
6 changes: 2 additions & 4 deletions ahk/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from typing import TypeVar
from typing import Union

from ahk.exceptions import AHKExecutionException


class OutOfMessageTypes(Exception): ...

Expand Down Expand Up @@ -209,10 +211,6 @@ def unpack(self) -> None:
return None


class AHKExecutionException(Exception):
pass


class ExceptionResponseMessage(ResponseMessage):
_exception_type: Type[Exception] = AHKExecutionException

Expand Down

0 comments on commit f9ef0aa

Please sign in to comment.