comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

modernize and add annotation to `_compointer_base.value`

Open junkmd opened this issue 3 years ago • 2 comments

This is the old property style. https://github.com/enthought/comtypes/blob/4cbdb03b31583c6a974dd690d38f1abe69767dda/comtypes/_post_coinit/unknwn.py#L441-L445

This should be changed to the modern style with additional import sections.

from comtypes._memberspec import _ComMemberSpec, _DispMemberSpec
from comtypes._py_instance_method import instancemethod

+if TYPE_CHECKING:
+    from comtypes import hints  # type: ignore
+
     # redefine the .value property; return the object itself.
-    def __get_value(self):
+    @property
+    def value(self) -> "hints.Self":
+        """Return self."""
         return self

-    value = property(__get_value, doc="""Return self.""")
-

_compointer_base, as its name implies, is the base class for POINTER(IUnknown) by metaclasses. So, when returning self, it returns a POINTER(IUnknown) instance.

This is a 'GOOD FIRST ISSUE' because it requires only a few modifications to the code.

junkmd avatar Nov 14 '22 09:11 junkmd

I will close this once to make it suitable for the drop_py2 plan.

junkmd avatar Dec 27 '22 03:12 junkmd

With the drop_py2 plan complete, code modernization has become much easier. I thought it was time to reopen this issue.

junkmd avatar Nov 02 '24 02:11 junkmd