Skip to content

Commit

Permalink
Trial.
Browse files Browse the repository at this point in the history
  • Loading branch information
junkmd committed Oct 7, 2024
1 parent f38821a commit 464f566
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions comtypes/_post_coinit/unknwn.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,24 @@ def __new__(cls, name, bases, namespace):
if dispmethods is not None:
self._disp_methods_ = dispmethods

# ` _compointer_meta` is a subclass inherited from `_cominterface_meta`.
# `_compointer_base` uses `_compointer_meta` as its metaclass.
# In other words, when the `__new__` method of this metaclass is called,
# `_compointer_base` type or an subclass of it might be created.
if bases == (c_void_p,):
# `self` is `_compointer_base` type.
# At this point, it can be that `_compointer_base` is not available in
# the accessible namespace and referencing it could raise a `NameError`,
# so the condition is based on `bases` is `(c_void_p,)`.
return self
if issubclass(self, _compointer_base):
try:
is_compointer = issubclass(self, _compointer_base)
except NameError:
# On some versions of Python, `_compointer_base` is not
# yet available in the accessible namespace at this
# point in its initialization.
# In this case, `self` will become `_compointer_base`
# later, so `issubclass(self, _compointer_base)`
# will be True.
is_compointer = True
# Double-check that self is actually _compointer_base.
assert bases == (c_void_p,)

if is_compointer:
# `self` is `POINTER(interface)` type.
# Prevent registering a pointer to a pointer (to a pointer...),
# which would lead to infinite recursion.
# Depending on a version or revision of Python, this may be essential.
return self

# If we sublass a COM interface, for example:
Expand Down

0 comments on commit 464f566

Please sign in to comment.