Skip to content

Commit

Permalink
type-hint Window classmethods for engine version
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Feb 1, 2025
1 parent 9fe8ac3 commit 3059d71
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions ahk/_async/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ async def get_active_window(
title='A', detect_hidden_windows=False, title_match_mode=(1, 'Fast'), blocking=blocking
)

# Ideally, this would be type-hinted for the AHK version. But we cant: https://github.com/python/mypy/issues/9937
@property
def active_window(self) -> AsyncPropertyReturnOptionalAsyncWindow:
"""
Expand Down
8 changes: 8 additions & 0 deletions ahk/_async/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,14 @@ async def move(
blocking=blocking,
)

# fmt: off
@overload
@classmethod
async def from_pid(cls, engine: AsyncAHK[Literal['v2']], pid: int) -> AsyncWindow: ...
@overload
@classmethod
async def from_pid(cls, engine: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]], pid: int) -> Optional[AsyncWindow]: ...
# fmt: on
@classmethod
async def from_pid(cls, engine: AsyncAHK[Any], pid: int) -> Optional[AsyncWindow]:
return await engine.win_get(title=f'ahk_pid {pid}')
Expand Down
1 change: 1 addition & 0 deletions ahk/_sync/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ def get_active_window(
title='A', detect_hidden_windows=False, title_match_mode=(1, 'Fast'), blocking=blocking
)

# Ideally, this would be type-hinted for the AHK version. But we cant: https://github.com/python/mypy/issues/9937
@property
def active_window(self) -> SyncPropertyReturnOptionalAsyncWindow:
"""
Expand Down
8 changes: 8 additions & 0 deletions ahk/_sync/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,14 @@ def move(
blocking=blocking,
)

# fmt: off
@overload
@classmethod
def from_pid(cls, engine: AHK[Literal['v2']], pid: int) -> Window: ...
@overload
@classmethod
def from_pid(cls, engine: Union[AHK[Literal['v1']], AHK[None]], pid: int) -> Optional[Window]: ...
# fmt: on
@classmethod
def from_pid(cls, engine: AHK[Any], pid: int) -> Optional[Window]:
return engine.win_get(title=f'ahk_pid {pid}')
Expand Down

0 comments on commit 3059d71

Please sign in to comment.