Skip to content

Commit

Permalink
Improve patching classes in _compointer_meta. (#624)
Browse files Browse the repository at this point in the history
* Extract the parts where classes are being patched
in `_cominterface_meta.__new__` into a `staticmethod`.

* Add a `type: ignore` comment.
  • Loading branch information
junkmd committed Sep 27, 2024
1 parent 945800b commit 07a3b83
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions comtypes/_post_coinit/unknwn.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,20 @@ def __new__(cls, name, bases, namespace):
{"__com_interface__": new_cls, "_needs_com_addref_": None},
)

from ctypes import _pointer_type_cache
from ctypes import _pointer_type_cache # type: ignore

_pointer_type_cache[new_cls] = p

if new_cls._case_insensitive_:
new_cls._patch_to_ptr_type(p, True)
else:
new_cls._patch_to_ptr_type(p, False)

return new_cls

@staticmethod
def _patch_to_ptr_type(p, case_insensitive) -> None:
if case_insensitive:

@patcher.Patch(p)
class CaseInsensitive(object):
Expand Down Expand Up @@ -155,8 +164,6 @@ def __setitem__(self, index, value):

CopyComPointer(value, self)

return new_cls

def __setattr__(self, name, value):
if name == "_methods_":
# XXX I'm no longer sure why the code generator generates
Expand Down

0 comments on commit 07a3b83

Please sign in to comment.