pythonautohotkeypython-typingmypy

How to type libraries using ahk?


How to type libraries using ahk? I thought about doing it like this:

class AHKMouseController:
    def __init__(
        self,
        ahk: AHK
    ):
        self._ahk = ahk

But mypy complains:

error: Missing type parameters for generic type "AHK" [type-arg]

I'm asking specifically what ahk wants to be passed to it as a type in generic?


Solution

  • This is a little like mypy complaining that xs: list = [] is not enough. The type checker is looking for something specific, like list[int] or list[str].

    Take a look at https://github.com/spyoungtech/ahk/blob/main/ahk/_sync/window.py . It suggests that you should be specifying what type of auto hotkey engine you're using. Some valid possibilities seem to be AHK[Any], AHK[Literal['v2']], or even AHK[None].