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

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

Open
junkmd opened this issue Nov 4, 2024 · 0 comments
Open

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

junkmd opened this issue Nov 4, 2024 · 0 comments
Labels
good first issue Good for newcomers

Comments

@junkmd
Copy link
Collaborator

junkmd commented Nov 4, 2024

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},
@junkmd junkmd added the good first issue Good for newcomers label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant