Skip to content

Commit

Permalink
This is a change that reproduces the issue
Browse files Browse the repository at this point in the history
where it runs successfully on Python 3.13, but a `NameError` occurs
on Python 3.11.

It corresponds to an updated version of the reproducer reported at
python/cpython#124520 (comment).
  • Loading branch information
junkmd committed Sep 29, 2024
1 parent 621ec95 commit 9d3935e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions comtypes/_post_coinit/unknwn.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def __new__(cls, name, bases, namespace):
if dispmethods is not None:
new_cls._disp_methods_ = dispmethods

return new_cls

def __init__(self, name, bases, namespace):
# If we sublass a COM interface, for example:
#
# class IDispatch(IUnknown):
Expand All @@ -85,26 +88,24 @@ def __new__(cls, name, bases, namespace):
# subclass of POINTER(IUnknown) because of the way ctypes
# typechecks work.
if bases == (object,):
_ptr_bases = (new_cls, _compointer_base)
_ptr_bases = (self, _compointer_base)
else:
_ptr_bases = (new_cls, POINTER(bases[0]))
_ptr_bases = (self, POINTER(bases[0]))

# The interface 'new_cls' is used as a mixin.
p = type(_compointer_base)(
"POINTER(%s)" % new_cls.__name__,
"POINTER(%s)" % self.__name__,
_ptr_bases,
{"__com_interface__": new_cls, "_needs_com_addref_": None},
{"__com_interface__": self, "_needs_com_addref_": None},
)

from ctypes import _pointer_type_cache # type: ignore

_pointer_type_cache[new_cls] = p

if new_cls._case_insensitive_:
new_cls._patch_case_insensitive_to_ptr_type(p)
new_cls._patch_reference_fix_to_ptrptr_type(p)
_pointer_type_cache[self] = p

return new_cls
if self._case_insensitive_:
self._patch_case_insensitive_to_ptr_type(p)
self._patch_reference_fix_to_ptrptr_type(p)

@staticmethod
def _patch_case_insensitive_to_ptr_type(p: Type) -> None:
Expand Down

0 comments on commit 9d3935e

Please sign in to comment.