Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove workarounds for importing safearrays. #640

Open
junkmd opened this issue Oct 14, 2024 · 0 comments · May be fixed by #645
Open

Remove workarounds for importing safearrays. #640

junkmd opened this issue Oct 14, 2024 · 0 comments · May be fixed by #645
Labels
coding style Topics related to style, formatters, linters, and delinting. good first issue Good for newcomers

Comments

@junkmd
Copy link
Collaborator

junkmd commented Oct 14, 2024

In the early stages of this project, when Windows CE was still supported, safearrays didn’t work, so a workaround was added in commit 37daf09.
In relation to safearray and automation, we made changes in #580 to ensure that this runtime workaround wouldn’t confuse the static type system.
However, we overlooked the fact that it’s no longer necessary to keep the workaround at runtime when importing safearray.

Just as we have eliminated remnants of Windows CE support in #211, #304, and #554, the following lines in the current codebase can be updated as shown below.

import comtypes.patcher
import comtypes
if TYPE_CHECKING:
from ctypes import _CArgObject
from comtypes import hints # type: ignore
from comtypes import _safearray
else:
_CArgObject = type(byref(c_int()))
try:
from comtypes import _safearray
except (ImportError, AttributeError):
class _safearray(object):
tagSAFEARRAY = None

 import comtypes.patcher
+from comtypes import _safearray
 import comtypes
 
 if TYPE_CHECKING:
     from ctypes import _CArgObject
     from comtypes import hints  # type: ignore
-    from comtypes import _safearray
 else:
     _CArgObject = type(byref(c_int()))
-    try:
-        from comtypes import _safearray
-    except (ImportError, AttributeError):
-
-        class _safearray(object):
-            tagSAFEARRAY = None

try:
from comtypes.safearray import _midlSAFEARRAY
except (ImportError, AttributeError):
pass

-try:
-    from comtypes.safearray import _midlSAFEARRAY
-except (ImportError, AttributeError):
-    pass
+from comtypes.safearray import _midlSAFEARRAY

I believe there’s room for improvement in the code formatting, but I’ll leave that to the contributor who works on this issue.

@junkmd junkmd added the good first issue Good for newcomers label Oct 14, 2024
@junkmd junkmd changed the title Remove workarounds for Remove workarounds for importing safearrays. Oct 14, 2024
@newwingbird newwingbird linked a pull request Oct 29, 2024 that will close this issue
@junkmd junkmd linked a pull request Oct 29, 2024 that will close this issue
@junkmd junkmd added the coding style Topics related to style, formatters, linters, and delinting. label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
coding style Topics related to style, formatters, linters, and delinting. good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant