Skip to content

Commit a0aee74

Browse files
authored
Merge pull request #366 from spyoungtech/fix-version-overloads
fix version-specific type hinting
2 parents 70f43c4 + 3059d71 commit a0aee74

File tree

5 files changed

+67
-49
lines changed

5 files changed

+67
-49
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ repos:
4545
- id: reorder-python-imports
4646

4747
- repo: https://github.com/pre-commit/mirrors-mypy
48-
rev: 'v1.13.0'
48+
rev: 'v1.14.1'
4949
hooks:
5050
- id: mypy
5151
args:

ahk/_async/engine.py

+25-24
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ async def get_active_window(
821821
title='A', detect_hidden_windows=False, title_match_mode=(1, 'Fast'), blocking=blocking
822822
)
823823

824+
# Ideally, this would be type-hinted for the AHK version. But we cant: https://github.com/python/mypy/issues/9937
824825
@property
825826
def active_window(self) -> AsyncPropertyReturnOptionalAsyncWindow:
826827
"""
@@ -1441,13 +1442,13 @@ async def show_traytip(self: AsyncAHK[Literal['v2']], title: str, text: str, sec
14411442
async def show_traytip(self: AsyncAHK[Literal['v2']], title: str, text: str, second: None = None, type_id: int = 1, *, silent: bool = False, large_icon: bool = False, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
14421443

14431444
@overload
1444-
async def show_traytip(self: AsyncAHK[Optional[Literal['v1']]], title: str, text: str, second: Optional[float] = None, type_id: int = 1, *, silent: bool = False, large_icon: bool = False) -> None: ...
1445+
async def show_traytip(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str, text: str, second: Optional[float] = None, type_id: int = 1, *, silent: bool = False, large_icon: bool = False) -> None: ...
14451446
@overload
1446-
async def show_traytip(self: AsyncAHK[Optional[Literal['v1']]], title: str, text: str, second: Optional[float] = None, type_id: int = 1, *, silent: bool = False, large_icon: bool = False, blocking: Literal[False]) -> AsyncFutureResult[None]: ...
1447+
async def show_traytip(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str, text: str, second: Optional[float] = None, type_id: int = 1, *, silent: bool = False, large_icon: bool = False, blocking: Literal[False]) -> AsyncFutureResult[None]: ...
14471448
@overload
1448-
async def show_traytip(self: AsyncAHK[Optional[Literal['v1']]], title: str, text: str, second: Optional[float] = None, type_id: int = 1, *, silent: bool = False, large_icon: bool = False, blocking: Literal[True]) -> None: ...
1449+
async def show_traytip(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str, text: str, second: Optional[float] = None, type_id: int = 1, *, silent: bool = False, large_icon: bool = False, blocking: Literal[True]) -> None: ...
14491450
@overload
1450-
async def show_traytip(self: AsyncAHK[Optional[Literal['v1']]], title: str, text: str, second: Optional[float] = None, type_id: int = 1, *, silent: bool = False, large_icon: bool = False, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
1451+
async def show_traytip(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str, text: str, second: Optional[float] = None, type_id: int = 1, *, silent: bool = False, large_icon: bool = False, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
14511452
# fmt: on
14521453
async def show_traytip(
14531454
self,
@@ -1486,13 +1487,13 @@ async def show_error_traytip(self: AsyncAHK[Literal['v2']], title: str, text: st
14861487
async def show_error_traytip(self: AsyncAHK[Literal['v2']], title: str, text: str, *, silent: bool = False, large_icon: bool = False, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
14871488

14881489
@overload
1489-
async def show_error_traytip(self: AsyncAHK[Optional[Literal['v1']]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False) -> None: ...
1490+
async def show_error_traytip(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False) -> None: ...
14901491
@overload
1491-
async def show_error_traytip(self: AsyncAHK[Optional[Literal['v1']]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: Literal[False]) -> AsyncFutureResult[None]: ...
1492+
async def show_error_traytip(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: Literal[False]) -> AsyncFutureResult[None]: ...
14921493
@overload
1493-
async def show_error_traytip(self: AsyncAHK[Optional[Literal['v1']]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: Literal[True]) -> None: ...
1494+
async def show_error_traytip(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: Literal[True]) -> None: ...
14941495
@overload
1495-
async def show_error_traytip(self: AsyncAHK[Optional[Literal['v1']]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
1496+
async def show_error_traytip(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
14961497

14971498
# fmt: on
14981499
async def show_error_traytip(
@@ -1523,13 +1524,13 @@ async def show_info_traytip(self: AsyncAHK[Literal['v2']], title: str, text: str
15231524
async def show_info_traytip(self: AsyncAHK[Literal['v2']], title: str, text: str, *, silent: bool = False, large_icon: bool = False, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
15241525

15251526
@overload
1526-
async def show_info_traytip(self: AsyncAHK[Optional[Literal['v1']]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False) -> None: ...
1527+
async def show_info_traytip(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False) -> None: ...
15271528
@overload
1528-
async def show_info_traytip(self: AsyncAHK[Optional[Literal['v1']]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: Literal[False]) -> AsyncFutureResult[None]: ...
1529+
async def show_info_traytip(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: Literal[False]) -> AsyncFutureResult[None]: ...
15291530
@overload
1530-
async def show_info_traytip(self: AsyncAHK[Optional[Literal['v1']]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: Literal[True]) -> None: ...
1531+
async def show_info_traytip(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: Literal[True]) -> None: ...
15311532
@overload
1532-
async def show_info_traytip(self: AsyncAHK[Optional[Literal['v1']]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
1533+
async def show_info_traytip(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
15331534
# fmt: on
15341535
async def show_info_traytip(
15351536
self: AsyncAHK[Any],
@@ -1559,13 +1560,13 @@ async def show_warning_traytip(self: AsyncAHK[Literal['v2']], title: str, text:
15591560
async def show_warning_traytip(self: AsyncAHK[Literal['v2']], title: str, text: str, *, silent: bool = False, large_icon: bool = False, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
15601561

15611562
@overload
1562-
async def show_warning_traytip(self: AsyncAHK[Optional[Literal['v1']]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False) -> None: ...
1563+
async def show_warning_traytip(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False) -> None: ...
15631564
@overload
1564-
async def show_warning_traytip(self: AsyncAHK[Optional[Literal['v1']]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: Literal[False]) -> AsyncFutureResult[None]: ...
1565+
async def show_warning_traytip(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: Literal[False]) -> AsyncFutureResult[None]: ...
15651566
@overload
1566-
async def show_warning_traytip(self: AsyncAHK[Optional[Literal['v1']]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: Literal[True]) -> None: ...
1567+
async def show_warning_traytip(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: Literal[True]) -> None: ...
15671568
@overload
1568-
async def show_warning_traytip(self: AsyncAHK[Optional[Literal['v1']]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
1569+
async def show_warning_traytip(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str, text: str, second: Optional[float] = None, *, silent: bool = False, large_icon: bool = False, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
15691570
# fmt: on
15701571
async def show_warning_traytip(
15711572
self: AsyncAHK[Any],
@@ -1742,13 +1743,13 @@ async def win_get(self: AsyncAHK[Literal['v2']], title: str = '', text: str = ''
17421743
async def win_get(self: AsyncAHK[Literal['v2']], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, blocking: bool = True) -> Union[AsyncWindow, AsyncFutureResult[AsyncWindow]]: ...
17431744

17441745
@overload
1745-
async def win_get(self: AsyncAHK[Optional[Literal['v1']]], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None) -> Union[AsyncWindow, None]: ...
1746+
async def win_get(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None) -> Union[AsyncWindow, None]: ...
17461747
@overload
1747-
async def win_get(self: AsyncAHK[Optional[Literal['v1']]], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, blocking: Literal[False]) -> AsyncFutureResult[Union[AsyncWindow, None]]: ...
1748+
async def win_get(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, blocking: Literal[False]) -> AsyncFutureResult[Union[AsyncWindow, None]]: ...
17481749
@overload
1749-
async def win_get(self: AsyncAHK[Optional[Literal['v1']]], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, blocking: Literal[True]) -> Union[AsyncWindow, None]: ...
1750+
async def win_get(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, blocking: Literal[True]) -> Union[AsyncWindow, None]: ...
17501751
@overload
1751-
async def win_get(self: AsyncAHK[Optional[Literal['v1']]], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, blocking: bool = True) -> Union[AsyncWindow, None, AsyncFutureResult[Union[None, AsyncWindow]], AsyncFutureResult[AsyncWindow]]: ...
1752+
async def win_get(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, blocking: bool = True) -> Union[AsyncWindow, None, AsyncFutureResult[Union[None, AsyncWindow]], AsyncFutureResult[AsyncWindow]]: ...
17521753
# fmt: on
17531754
async def win_get(
17541755
self,
@@ -1885,13 +1886,13 @@ async def win_get_position(self: AsyncAHK[Literal['v2']], title: str = '', text:
18851886
async def win_get_position(self: AsyncAHK[Literal['v2']], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, blocking: bool = True) -> Union[Position, AsyncFutureResult[Position]]: ...
18861887

18871888
@overload
1888-
async def win_get_position(self: AsyncAHK[Optional[Literal['v1']]], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None) -> Union[Position, None]: ...
1889+
async def win_get_position(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None) -> Union[Position, None]: ...
18891890
@overload
1890-
async def win_get_position(self: AsyncAHK[Optional[Literal['v1']]], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, blocking: Literal[False]) -> AsyncFutureResult[Union[Position, None]]: ...
1891+
async def win_get_position(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, blocking: Literal[False]) -> AsyncFutureResult[Union[Position, None]]: ...
18911892
@overload
1892-
async def win_get_position(self: AsyncAHK[Optional[Literal['v1']]], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, blocking: Literal[True]) -> Union[Position, None]: ...
1893+
async def win_get_position(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, blocking: Literal[True]) -> Union[Position, None]: ...
18931894
@overload
1894-
async def win_get_position(self: AsyncAHK[Optional[Literal['v1']]], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, blocking: bool = True) -> Union[Position, None, AsyncFutureResult[Union[Position, None]]]: ...
1895+
async def win_get_position(self: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, blocking: bool = True) -> Union[Position, None, AsyncFutureResult[Union[Position, None]]]: ...
18951896
# fmt: on
18961897
async def win_get_position(
18971898
self,

ahk/_async/window.py

+8
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,14 @@ async def move(
656656
blocking=blocking,
657657
)
658658

659+
# fmt: off
660+
@overload
661+
@classmethod
662+
async def from_pid(cls, engine: AsyncAHK[Literal['v2']], pid: int) -> AsyncWindow: ...
663+
@overload
664+
@classmethod
665+
async def from_pid(cls, engine: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], pid: int) -> Optional[AsyncWindow]: ...
666+
# fmt: on
659667
@classmethod
660668
async def from_pid(cls, engine: AsyncAHK[Any], pid: int) -> Optional[AsyncWindow]:
661669
return await engine.win_get(title=f'ahk_pid {pid}')

0 commit comments

Comments
 (0)