From b5007260148a1be2bd1d1303e5fde4578a1f7d83 Mon Sep 17 00:00:00 2001 From: junkmd Date: Sun, 14 Jun 2026 22:09:08 +0900 Subject: [PATCH 1/4] refactor: Fix linting issues in `comtypes/git.py` and remove lint ignores. - Replace wildcard `ctypes` import with explicit `POINTER` import. - Remove unused `COMMETHOD` import. - Remove `comtypes/git.py` from `per-file-ignores` in `pyproject.toml`. --- comtypes/git.py | 3 +-- pyproject.toml | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/comtypes/git.py b/comtypes/git.py index e72017700..a3b956759 100644 --- a/comtypes/git.py +++ b/comtypes/git.py @@ -4,12 +4,11 @@ between different threading appartments. """ -from ctypes import * +from ctypes import POINTER from ctypes.wintypes import DWORD from comtypes import ( CLSCTX_INPROC_SERVER, - COMMETHOD, GUID, HRESULT, STDMETHOD, diff --git a/pyproject.toml b/pyproject.toml index f9cea138d..c5b38445f 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"] From c737f8fb54b52ad51f365024b3f35d1229c3831a Mon Sep 17 00:00:00 2001 From: junkmd Date: Sun, 14 Jun 2026 22:09:08 +0900 Subject: [PATCH 2/4] refactor: Remove redundant `if __name__ == "__main__":` block from `comtypes/git.py`. The manual test code in the main block is no longer needed as the functionality is covered by other tests or was intended only for local verification. --- comtypes/git.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/comtypes/git.py b/comtypes/git.py index a3b956759..3b1cdcaf7 100644 --- a/comtypes/git.py +++ b/comtypes/git.py @@ -68,20 +68,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) From 1cad3192cd229bd1c082b4deb01750539041ce06 Mon Sep 17 00:00:00 2001 From: junkmd Date: Sun, 14 Jun 2026 22:09:08 +0900 Subject: [PATCH 3/4] fix: Add type ignores to `IGlobalInterfaceTable` methods. Add `# type: ignore` to `RegisterInterfaceInGlobal`, `GetInterfaceFromGlobal`, and `RevokeInterfaceFromGlobal` in `IGlobalInterfaceTable` to suppress type checking errors for generated `__com_*` methods. --- comtypes/git.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/comtypes/git.py b/comtypes/git.py index 3b1cdcaf7..87d8b5e79 100644 --- a/comtypes/git.py +++ b/comtypes/git.py @@ -35,16 +35,16 @@ class IGlobalInterfaceTable(IUnknown): def RegisterInterfaceInGlobal(self, obj, interface=IUnknown): 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): ptr = POINTER(interface)() - self.__com_GetInterfaceFromGlobal(cookie, interface._iid_, ptr) + self.__com_GetInterfaceFromGlobal(cookie, interface._iid_, ptr) # type: ignore return ptr def RevokeInterfaceFromGlobal(self, cookie): - self.__com_RevokeInterfaceFromGlobal(cookie) + self.__com_RevokeInterfaceFromGlobal(cookie) # type: ignore # It was a pain to get this CLSID: it's neither in the registry, nor From 403e6774159c903ecfc89a4533c657867a352268 Mon Sep 17 00:00:00 2001 From: junkmd Date: Sun, 14 Jun 2026 22:09:08 +0900 Subject: [PATCH 4/4] refactor: Add type hints to `IGlobalInterfaceTable` methods. - Use `TypeVar` `_T_IUnknown` to define generic interface types. - Add type hints to `RegisterInterfaceInGlobal`, `GetInterfaceFromGlobal`, and `RevokeInterfaceFromGlobal`. - Update method signatures to use `_T_IUnknown` for improved type safety. --- comtypes/git.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/comtypes/git.py b/comtypes/git.py index 87d8b5e79..f55235b34 100644 --- a/comtypes/git.py +++ b/comtypes/git.py @@ -6,6 +6,7 @@ from ctypes import POINTER from ctypes.wintypes import DWORD +from typing import Type, TypeVar from comtypes import ( CLSCTX_INPROC_SERVER, @@ -16,6 +17,8 @@ IUnknown, ) +_T_IUnknown = TypeVar("_T_IUnknown", bound=IUnknown) + class IGlobalInterfaceTable(IUnknown): _iid_ = GUID("{00000146-0000-0000-C000-000000000046}") @@ -33,17 +36,21 @@ 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) # 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) # type: ignore - return ptr + return ptr # type: ignore - def RevokeInterfaceFromGlobal(self, cookie): + def RevokeInterfaceFromGlobal(self, cookie: int) -> None: self.__com_RevokeInterfaceFromGlobal(cookie) # type: ignore