Skip to content

Commit ebedd2e

Browse files
authored
Remove Outdated Python 2.3 Compatibility and Unused Test Utilities. (#916)
* test: Simplify `test_subinterface.py` Remove unused `sys` import and `test_main` function. Streamline `ctypes` imports for better clarity. * refactor: Remove unused test utilities from `test/__init__.py` Remove `is_resource_enabled` and `requires` functions to simplify test setup. * 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.
1 parent e2c65cc commit ebedd2e

3 files changed

Lines changed: 3 additions & 42 deletions

File tree

comtypes/client/lazybind.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,7 @@ def __getattr__(self, name):
159159
def caller(*args):
160160
return self._comobj._invoke(descr.memid, descr.invkind, 0, *args)
161161

162-
try:
163-
caller.__name__ = name
164-
except TypeError:
165-
# In Python 2.3, __name__ is readonly
166-
pass
162+
caller.__name__ = name
167163
return caller
168164

169165
def __setattr__(self, name, value):

comtypes/test/__init__.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,9 @@ class ResourceDenied(Exception):
3737
"""
3838

3939

40-
def is_resource_enabled(resource):
41-
"""Test whether a resource is enabled.
42-
43-
If the caller's module is __main__ then automatically return True."""
44-
if sys._getframe().f_back.f_globals.get("__name__") == "__main__":
45-
return True
46-
result = use_resources is not None and (
47-
resource in use_resources or "*" in use_resources
48-
)
49-
if not result:
50-
_unavail[resource] = None
51-
return result
52-
53-
5440
_unavail = {}
5541

5642

57-
def requires(resource, msg=None):
58-
"""Raise ResourceDenied if the specified resource is not available.
59-
60-
If the caller's module is __main__ then automatically return True."""
61-
# see if the caller's module is __main__ - if so, treat as if
62-
# the resource was set
63-
if sys._getframe().f_back.f_globals.get("__name__") == "__main__":
64-
return
65-
if not is_resource_enabled(resource):
66-
if msg is None:
67-
msg = f"Use of the `{resource}` resource not enabled"
68-
raise ResourceDenied(msg)
69-
70-
7143
def find_package_modules(package, mask):
7244
import fnmatch
7345

comtypes/test/test_subinterface.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
import sys
21
import unittest
3-
from ctypes import *
2+
from ctypes import c_void_p
43

5-
from comtypes import GUID, IUnknown
6-
7-
8-
def test_main():
9-
from test import test_support
10-
11-
test_support.run_unittest(Test)
4+
from comtypes import IUnknown
125

136

147
class Test(unittest.TestCase):

0 commit comments

Comments
 (0)