1 from __future__
import annotations
5 from pybind11_tests
import custom_type_casters
as m
13 loading ArgInspector1 argument WITH conversion allowed. Argument value = hi
17 msg(a.g(
"this is a",
"this is b"))
19 loading ArgInspector1 argument WITHOUT conversion allowed. Argument value = this is a
20 loading ArgInspector1 argument WITH conversion allowed. Argument value = this is b
22 loading ArgInspector2 argument WITH conversion allowed. Argument value = (default arg inspector 2)
26 msg(a.g(
"this is a",
"this is b", 42))
28 loading ArgInspector1 argument WITHOUT conversion allowed. Argument value = this is a
29 loading ArgInspector1 argument WITH conversion allowed. Argument value = this is b
31 loading ArgInspector2 argument WITH conversion allowed. Argument value = (default arg inspector 2)
35 msg(a.g(
"this is a",
"this is b", 42,
"this is d"))
37 loading ArgInspector1 argument WITHOUT conversion allowed. Argument value = this is a
38 loading ArgInspector1 argument WITH conversion allowed. Argument value = this is b
40 loading ArgInspector2 argument WITH conversion allowed. Argument value = this is d
45 ==
"loading ArgInspector2 argument WITHOUT conversion allowed. Argument value = arg 1"
48 msg(m.arg_inspect_func(
"A1",
"A2"))
50 loading ArgInspector2 argument WITH conversion allowed. Argument value = A1
51 loading ArgInspector1 argument WITHOUT conversion allowed. Argument value = A2
55 assert m.floats_preferred(4) == 2.0
56 assert m.floats_only(4.0) == 2.0
57 with pytest.raises(TypeError)
as excinfo:
62 floats_only(): incompatible function arguments. The following argument types are supported:
63 1. (f: float) -> float
69 assert m.ints_preferred(4) == 2
70 assert m.ints_preferred(
True) == 0
71 with pytest.raises(TypeError)
as excinfo:
76 ints_preferred(): incompatible function arguments. The following argument types are supported:
83 assert m.ints_only(4) == 2
84 with pytest.raises(TypeError)
as excinfo:
89 ints_only(): incompatible function arguments. The following argument types are supported:
98 """Tests that returning a pointer to a type that gets converted with a custom type caster gets
99 destroyed when the function has py::return_value_policy::take_ownership policy applied.
102 cstats = m.destruction_tester_cstats()
104 z = m.custom_caster_no_destroy()
105 assert cstats.alive() == 1
106 assert cstats.default_constructions == 1
110 z = m.custom_caster_destroy()
112 assert cstats.default_constructions == 2
115 z = m.custom_caster_destroy_const()
117 assert cstats.default_constructions == 3
120 assert cstats.alive() == 1
124 assert m.other_lib_type(
True)