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 8bc8a94
Show file tree
Hide file tree
Showing 4 changed files with 34 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
16 changes: 16 additions & 0 deletions ahk/_async/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,10 +656,26 @@ 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}')

# fmt: off
@overload
@classmethod
async def from_mouse_position(cls, engine: AsyncAHK[Literal['v2']]) -> AsyncWindow: ...
@overload
@classmethod
async def from_mouse_position(cls, engine: Union[AsyncAHK[Literal['v1']], AsyncAHK[None]]) -> Optional[AsyncWindow]: ...
# fmt: on
@classmethod
async def from_mouse_position(cls, engine: AsyncAHK[Any]) -> Optional[AsyncWindow]:
return await engine.win_get_from_mouse_position()
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
16 changes: 16 additions & 0 deletions ahk/_sync/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,26 @@ 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}')

# fmt: off
@overload
@classmethod
def from_mouse_position(cls, engine: AHK[Literal['v2']]) -> Window: ...
@overload
@classmethod
def from_mouse_position(cls, engine: Union[AHK[Literal['v1']], AHK[None]]) -> Optional[Window]: ...
# fmt: on
@classmethod
def from_mouse_position(cls, engine: AHK[Any]) -> Optional[Window]:
return engine.win_get_from_mouse_position()
Expand Down

0 comments on commit 8bc8a94

Please sign in to comment.