1 from __future__
import annotations
6 from pybind11_tests
import ConstructorStats
7 from pybind11_tests
import multiple_inheritance
as m
17 @pytest.mark.xfail(
"env.PYPY")
26 class MITypePy(Base1, m.Base2):
28 Base1.__init__(self, i)
29 m.Base2.__init__(self, j)
45 class MITypePy(m.Base1, Base2):
47 m.Base1.__init__(self, i)
48 Base2.__init__(self, j)
56 @pytest.mark.xfail(
"env.PYPY")
58 class MI1(m.Base1, m.Base2):
60 m.Base1.__init__(self, i)
61 m.Base2.__init__(self, j)
67 class MI2(B1, m.Base1, m.Base2):
70 m.Base1.__init__(self, i)
71 m.Base2.__init__(self, j)
75 MI2.__init__(self, i, j)
77 class MI4(MI3, m.Base2):
79 MI3.__init__(self, i, j)
81 m.Base2.__init__(self, i + 100)
83 class MI5(m.Base2, B1, m.Base1):
86 m.Base1.__init__(self, i)
87 m.Base2.__init__(self, j)
89 class MI6(m.Base2, B1):
91 m.Base2.__init__(self, i)
109 MI6.__init__(self, i)
113 MI6.__init__(self, i)
119 MI6.__init__(self, i)
122 assert mi1.foo() == 1
123 assert mi1.bar() == 2
127 assert mi2.foo() == 3
128 assert mi2.bar() == 4
132 assert mi3.foo() == 5
133 assert mi3.bar() == 6
137 assert mi4.foo() == 7
138 assert mi4.bar() == 8
142 assert mi5.foo() == 10
143 assert mi5.bar() == 11
147 assert mi6.bar() == 12
151 assert mi7.bar() == 13
155 assert mi8.bar() == 14
159 assert mi8b.bar() == 15
163 class MIMany14(m.BaseN1, m.BaseN2, m.BaseN3, m.BaseN4):
165 m.BaseN1.__init__(self, 1)
166 m.BaseN2.__init__(self, 2)
167 m.BaseN3.__init__(self, 3)
168 m.BaseN4.__init__(self, 4)
170 class MIMany58(m.BaseN5, m.BaseN6, m.BaseN7, m.BaseN8):
172 m.BaseN5.__init__(self, 5)
173 m.BaseN6.__init__(self, 6)
174 m.BaseN7.__init__(self, 7)
175 m.BaseN8.__init__(self, 8)
188 m.BaseN9.__init__(self, 9)
189 m.BaseN10.__init__(self, 10)
190 m.BaseN11.__init__(self, 11)
191 m.BaseN12.__init__(self, 12)
192 m.BaseN13.__init__(self, 13)
193 m.BaseN14.__init__(self, 14)
194 m.BaseN15.__init__(self, 15)
195 m.BaseN16.__init__(self, 16)
197 class MIMany19(MIMany14, MIMany58, m.BaseN9):
199 MIMany14.__init__(self)
200 MIMany58.__init__(self)
201 m.BaseN9.__init__(self, 9)
203 class MIMany117(MIMany14, MIMany58, MIMany916, m.BaseN17):
205 MIMany14.__init__(self)
206 MIMany58.__init__(self)
207 MIMany916.__init__(self)
208 m.BaseN17.__init__(self, 17)
212 for i
in range(1, 4):
217 for i
in range(9, 16):
222 for i
in range(1, 9):
227 for i
in range(1, 17):
232 class MITypePy(m.Base12a):
234 m.Base12a.__init__(self, i, j)
238 assert m.bar_base2a(mt) == 4
239 assert m.bar_base2a_sharedptr(mt) == 4
243 """Mixing bases with and without static properties should be possible
244 and the result should be independent of base definition order"""
246 for d
in (m.VanillaStaticMix1(), m.VanillaStaticMix2()):
247 assert d.vanilla() ==
"Vanilla"
248 assert d.static_func1() ==
"WithStatic1"
249 assert d.static_func2() ==
"WithStatic2"
250 assert d.static_func() == d.__class__.__name__
252 m.WithStatic1.static_value1 = 1
253 m.WithStatic2.static_value2 = 2
254 assert d.static_value1 == 1
255 assert d.static_value2 == 2
256 assert d.static_value == 12
259 assert d.static_value1 == 0
261 assert d.static_value2 == 0
263 assert d.static_value == 0
268 """Mixing bases with and without dynamic attribute support"""
270 for d
in (m.VanillaDictMix1(), m.VanillaDictMix2()):
272 assert d.dynamic == 1
276 """Returning an offset (non-first MI) base class pointer should recognize the instance"""
278 n_inst = ConstructorStats.detail_reg_inst()
283 assert ConstructorStats.detail_reg_inst() == n_inst + 4
293 assert ConstructorStats.detail_reg_inst() == n_inst + 4
295 assert ConstructorStats.detail_reg_inst() == n_inst + 2
297 assert ConstructorStats.detail_reg_inst() == n_inst
301 """Tests returning an offset (non-first MI) base class pointer to a derived instance"""
303 n_inst = ConstructorStats.detail_reg_inst()
306 assert type(c1)
is m.I801C
311 assert type(d1)
is m.I801D
315 assert ConstructorStats.detail_reg_inst() == n_inst + 4
318 assert type(c2)
is m.I801C
323 assert type(d2)
is m.I801D
327 assert ConstructorStats.detail_reg_inst() == n_inst + 8
330 assert ConstructorStats.detail_reg_inst() == n_inst + 6
332 assert ConstructorStats.detail_reg_inst() == n_inst
338 assert type(e1)
is m.I801C
343 assert type(e2)
is m.I801B2
348 """Tests that diamond inheritance works as expected (issue #959)"""
357 assert d
is d.c0().
b()
358 assert d
is d.c1().
b()
359 assert d
is d.c0().
c1().
b().c0().
b()
366 assert o.get_b_b() == 1
374 assert o.get_b_b() == 1
375 assert o.get_c_b() == 1
377 assert o.get_c_c() == 2
386 assert o.get_b_b() == 1
387 assert o.get_c_b() == 1
388 assert o.get_d0_b() == 1
390 assert o.get_c_c() == 2
391 assert o.get_d0_c() == 2
393 assert o.get_d0_d0() == 3
402 assert o.get_b_b() == 1
403 assert o.get_c_b() == 1
404 assert o.get_d1_b() == 1
406 assert o.get_c_c() == 2
407 assert o.get_d1_c() == 2
409 assert o.get_d1_d1() == 4
420 assert o.get_b_b() == 1
421 assert o.get_c_b() == 1
422 assert o.get_d0_b() == 1
423 assert o.get_d1_b() == 1
424 assert o.get_e_b() == 1
426 assert o.get_c_c() == 2
427 assert o.get_d0_c() == 2
428 assert o.get_d1_c() == 2
429 assert o.get_e_c() == 2
431 assert o.get_d0_d0() == 3
432 assert o.get_e_d0() == 3
434 assert o.get_d1_d1() == 4
435 assert o.get_e_d1() == 4
437 assert o.get_e_e() == 5
449 assert o.get_b_b() == 1
450 assert o.get_c_b() == 1
451 assert o.get_d0_b() == 1
452 assert o.get_d1_b() == 1
453 assert o.get_e_b() == 1
454 assert o.get_f_b() == 1
456 assert o.get_c_c() == 2
457 assert o.get_d0_c() == 2
458 assert o.get_d1_c() == 2
459 assert o.get_e_c() == 2
460 assert o.get_f_c() == 2
462 assert o.get_d0_d0() == 3
463 assert o.get_e_d0() == 3
464 assert o.get_f_d0() == 3
466 assert o.get_d1_d1() == 4
467 assert o.get_e_d1() == 4
468 assert o.get_f_d1() == 4
470 assert o.get_e_e() == 5
471 assert o.get_f_e() == 5
473 assert o.get_f_f() == 6
477 """Tests extending a Python class from a single inheritor of a MI class"""
495 assert o.get_g_g() == 7