@@ -87,11 +87,16 @@ class Sub(CtBase):
87
87
self .assertTrue (issubclass (POINTER (Sub ), Sub ))
88
88
89
89
def test_creating_pointer_in_dunder_init_1 (self ):
90
- # Test for modern metaclass initialization that does not
91
- # require recursion avoidance.
92
-
93
90
class ct_meta (type ):
94
91
def __init__ (self , name , bases , namespace ):
92
+ super ().__init__ (name , bases , namespace )
93
+
94
+ # Avoid recursion.
95
+ # (See test_creating_pointer_in_dunder_new_1)
96
+ if bases == (c_void_p ,):
97
+ return
98
+ if issubclass (self , PtrBase ):
99
+ return
95
100
if bases == (object ,):
96
101
ptr_bases = (self , PtrBase )
97
102
else :
@@ -120,10 +125,14 @@ class Sub2(Sub):
120
125
self .assertTrue (issubclass (POINTER (Sub ), POINTER (CtBase )))
121
126
122
127
def test_creating_pointer_in_dunder_init_2 (self ):
123
- # A simpler variant of the above.
124
-
125
128
class ct_meta (type ):
126
129
def __init__ (self , name , bases , namespace ):
130
+ super ().__init__ (name , bases , namespace )
131
+
132
+ # Avoid recursion.
133
+ # (See test_creating_pointer_in_dunder_new_2)
134
+ if isinstance (self , p_meta ):
135
+ return self
127
136
p = p_meta (f"POINTER({ self .__name__ } )" , (self , c_void_p ), {})
128
137
ctypes ._pointer_type_cache [self ] = p
129
138
0 commit comments