Skip to content

Commit

Permalink
Add a test.
Browse files Browse the repository at this point in the history
Such an implementation is used in `CoClass` of `comtypes`.
  • Loading branch information
junkmd committed Oct 23, 2024
1 parent a0fb204 commit 4b324fc
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Lib/test/test_ctypes/test_c_simple_type_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,32 @@ class _Sub2(_Sub):
self.assertTrue(issubclass(POINTER(_Sub2), _Sub2))
self.assertTrue(issubclass(POINTER(_Sub2), POINTER(_Sub)))
self.assertTrue(issubclass(POINTER(_Sub), POINTER(_CtBase)))

def test_early_return_in_dunder_new_2(self):
# Such an implementation is used in `CoClass` of `comtypes`.

class _ct_meta(type):
def __new__(cls, name, bases, namespace):
self = super().__new__(cls, name, bases, namespace)
if isinstance(self, _p_meta):
return self
p = _p_meta(
f"POINTER({self.__name__})", (self, c_void_p), {}
)
ctypes._pointer_type_cache[self] = p
return self

class _p_meta(PyCSimpleType, _ct_meta):
pass

class _Core(object):
pass

class _CtBase(_Core, metaclass=_ct_meta):
pass

class _Sub(_CtBase):
pass

self.assertIsInstance(POINTER(_Sub), _p_meta)
self.assertTrue(issubclass(POINTER(_Sub), _Sub))

0 comments on commit 4b324fc

Please sign in to comment.