Skip to content

type(_compointer_base) might be replaced with _compointer_meta. #656

@junkmd

Description

@junkmd

Whether it’s a remnant of Python 2.x or a legacy from the early stages of this project, the metaclass is directly accessible as shown below, it still retrieves the metaclass indirectly using type.

_ptr_bases = (self, POINTER(bases[0]))
# The interface 'self' is used as a mixin.
# HACK: Could `type(_compointer_base)` be replaced with `_compointer_meta`?
# `type(klass)` returns its metaclass.
# Since this specification, `type(_compointer_base)` will return the
# `_compointer_meta` type as per the class definition.
# The reason for this implementation might be a remnant of the differences in
# how metaclasses work between Python 3.x and Python 2.x.
# If there are no problems with the versions of Python that `comtypes`
# supports, this replacement could make the process flow easier to understand.
p = type(_compointer_base)(
f"POINTER({self.__name__})",
_ptr_bases,
{"__com_interface__": self, "_needs_com_addref_": None},

If it can be confirmed that there are no problems, replacing them would improve the readability of the codebase.

             _ptr_bases = (self, POINTER(bases[0]))

         # The interface 'self' is used as a mixin.
-        # HACK: Could `type(_compointer_base)` be replaced with `_compointer_meta`?
-        # `type(klass)` returns its metaclass.
-        # Since this specification, `type(_compointer_base)` will return the
-        # `_compointer_meta` type as per the class definition.
-        # The reason for this implementation might be a remnant of the differences in
-        # how metaclasses work between Python 3.x and Python 2.x.
-        # If there are no problems with the versions of Python that `comtypes`
-        # supports, this replacement could make the process flow easier to understand.
-        p = type(_compointer_base)(
+        p = _compointer_meta(
             f"POINTER({self.__name__})",
             _ptr_bases,
             {"__com_interface__": self, "_needs_com_addref_": None},

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions