From 07a3b83d764fa2b345e649cbfa2a85251cb483ed Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Sat, 28 Sep 2024 00:35:40 +0900 Subject: [PATCH] Improve patching classes in `_compointer_meta`. (#624) * Extract the parts where classes are being patched in `_cominterface_meta.__new__` into a `staticmethod`. * Add a `type: ignore` comment. --- comtypes/_post_coinit/unknwn.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/comtypes/_post_coinit/unknwn.py b/comtypes/_post_coinit/unknwn.py index 046d1bc2..00624a46 100644 --- a/comtypes/_post_coinit/unknwn.py +++ b/comtypes/_post_coinit/unknwn.py @@ -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): @@ -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