diff --git a/comtypes/git.py b/comtypes/git.py index e7201770..f55235b3 100644 --- a/comtypes/git.py +++ b/comtypes/git.py @@ -4,12 +4,12 @@ between different threading appartments. """ -from ctypes import * +from ctypes import POINTER from ctypes.wintypes import DWORD +from typing import Type, TypeVar from comtypes import ( CLSCTX_INPROC_SERVER, - COMMETHOD, GUID, HRESULT, STDMETHOD, @@ -17,6 +17,8 @@ IUnknown, ) +_T_IUnknown = TypeVar("_T_IUnknown", bound=IUnknown) + class IGlobalInterfaceTable(IUnknown): _iid_ = GUID("{00000146-0000-0000-C000-000000000046}") @@ -34,18 +36,22 @@ class IGlobalInterfaceTable(IUnknown): ), ] - def RegisterInterfaceInGlobal(self, obj, interface=IUnknown): + def RegisterInterfaceInGlobal( + self, obj: IUnknown, interface: Type[_T_IUnknown] = IUnknown + ) -> int: cookie = DWORD() - self.__com_RegisterInterfaceInGlobal(obj, interface._iid_, cookie) + self.__com_RegisterInterfaceInGlobal(obj, interface._iid_, cookie) # type: ignore return cookie.value - def GetInterfaceFromGlobal(self, cookie, interface=IUnknown): + def GetInterfaceFromGlobal( + self, cookie: int, interface: Type[_T_IUnknown] = IUnknown + ) -> _T_IUnknown: ptr = POINTER(interface)() - self.__com_GetInterfaceFromGlobal(cookie, interface._iid_, ptr) - return ptr + self.__com_GetInterfaceFromGlobal(cookie, interface._iid_, ptr) # type: ignore + return ptr # type: ignore - def RevokeInterfaceFromGlobal(self, cookie): - self.__com_RevokeInterfaceFromGlobal(cookie) + def RevokeInterfaceFromGlobal(self, cookie: int) -> None: + self.__com_RevokeInterfaceFromGlobal(cookie) # type: ignore # It was a pain to get this CLSID: it's neither in the registry, nor @@ -69,20 +75,3 @@ def RevokeInterfaceFromGlobal(self, cookie): "GetInterfaceFromGlobal", ] # fmt: on - - -if __name__ == "__main__": - from comtypes.typeinfo import CreateTypeLib, ICreateTypeLib - - tlib = CreateTypeLib("foo.bar") # we don not save it later - assert (tlib.AddRef(), tlib.Release()) == (2, 1) - - cookie = RegisterInterfaceInGlobal(tlib) - assert (tlib.AddRef(), tlib.Release()) == (3, 2) - - GetInterfaceFromGlobal(cookie, ICreateTypeLib) - GetInterfaceFromGlobal(cookie, ICreateTypeLib) - GetInterfaceFromGlobal(cookie) - assert (tlib.AddRef(), tlib.Release()) == (3, 2) - RevokeInterfaceFromGlobal(cookie) - assert (tlib.AddRef(), tlib.Release()) == (2, 1) diff --git a/pyproject.toml b/pyproject.toml index f9cea138..c5b38445 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,7 +67,6 @@ ignore = ["E402"] "comtypes/_npsupport.py" = ["F401"] "comtypes/_vtbl.py" = ["E722"] "comtypes/automation.py" = ["F401", "F403", "F405"] -"comtypes/git.py" = ["F401", "F403", "F405"] "comtypes/viewobject.py" = ["F403", "F405"] "comtypes/client/_constants.py" = ["F401"] "comtypes/server/automation.py" = ["F403", "F405"]