From 108d396be48da4a1d2bd3bfce6f7e4957bf03e4a Mon Sep 17 00:00:00 2001 From: junkmd Date: Sun, 25 Jan 2026 22:04:28 +0900 Subject: [PATCH 1/3] test: Simplify `test_subinterface.py` Remove unused `sys` import and `test_main` function. Streamline `ctypes` imports for better clarity. --- comtypes/test/test_subinterface.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/comtypes/test/test_subinterface.py b/comtypes/test/test_subinterface.py index cd279ea6c..6d8bde327 100644 --- a/comtypes/test/test_subinterface.py +++ b/comtypes/test/test_subinterface.py @@ -1,14 +1,7 @@ -import sys import unittest -from ctypes import * +from ctypes import c_void_p -from comtypes import GUID, IUnknown - - -def test_main(): - from test import test_support - - test_support.run_unittest(Test) +from comtypes import IUnknown class Test(unittest.TestCase): From 7ecda5d8cae884de94bdd5d980525b3adf20f192 Mon Sep 17 00:00:00 2001 From: junkmd Date: Sun, 25 Jan 2026 22:04:28 +0900 Subject: [PATCH 2/3] refactor: Remove unused test utilities from `test/__init__.py` Remove `is_resource_enabled` and `requires` functions to simplify test setup. --- comtypes/test/__init__.py | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/comtypes/test/__init__.py b/comtypes/test/__init__.py index 2cb5332ec..afe19a1d1 100644 --- a/comtypes/test/__init__.py +++ b/comtypes/test/__init__.py @@ -37,37 +37,9 @@ class ResourceDenied(Exception): """ -def is_resource_enabled(resource): - """Test whether a resource is enabled. - - If the caller's module is __main__ then automatically return True.""" - if sys._getframe().f_back.f_globals.get("__name__") == "__main__": - return True - result = use_resources is not None and ( - resource in use_resources or "*" in use_resources - ) - if not result: - _unavail[resource] = None - return result - - _unavail = {} -def requires(resource, msg=None): - """Raise ResourceDenied if the specified resource is not available. - - If the caller's module is __main__ then automatically return True.""" - # see if the caller's module is __main__ - if so, treat as if - # the resource was set - if sys._getframe().f_back.f_globals.get("__name__") == "__main__": - return - if not is_resource_enabled(resource): - if msg is None: - msg = f"Use of the `{resource}` resource not enabled" - raise ResourceDenied(msg) - - def find_package_modules(package, mask): import fnmatch From 561c07e386bbf5f6d0f70730f0cf7ed6d9ff885e Mon Sep 17 00:00:00 2001 From: junkmd Date: Sun, 25 Jan 2026 22:04:28 +0900 Subject: [PATCH 3/3] refactor: Remove Python 2.3 compatibility for `__name__` assignment. Removes a `try...except TypeError` block related to `__name__` assignment in `client/lazybind.py`. This compatibility code for Python 2.3's read-only `__name__` attribute is no longer necessary in modern Python versions, simplifying the codebase. --- comtypes/client/lazybind.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/comtypes/client/lazybind.py b/comtypes/client/lazybind.py index 85716d014..1aae89338 100644 --- a/comtypes/client/lazybind.py +++ b/comtypes/client/lazybind.py @@ -159,11 +159,7 @@ def __getattr__(self, name): def caller(*args): return self._comobj._invoke(descr.memid, descr.invkind, 0, *args) - try: - caller.__name__ = name - except TypeError: - # In Python 2.3, __name__ is readonly - pass + caller.__name__ = name return caller def __setattr__(self, name, value):