File indexing completed on 2025-01-18 10:17:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "pybind11_tests.h"
0011
0012 TEST_SUBMODULE(docstring_options, m) {
0013
0014 {
0015 py::options options;
0016 options.disable_function_signatures();
0017
0018 m.def(
0019 "test_function1", [](int, int) {}, py::arg("a"), py::arg("b"));
0020 m.def(
0021 "test_function2", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
0022
0023 m.def(
0024 "test_overloaded1", [](int) {}, py::arg("i"), "Overload docstring");
0025 m.def(
0026 "test_overloaded1", [](double) {}, py::arg("d"));
0027
0028 m.def(
0029 "test_overloaded2", [](int) {}, py::arg("i"), "overload docstring 1");
0030 m.def(
0031 "test_overloaded2", [](double) {}, py::arg("d"), "overload docstring 2");
0032
0033 m.def(
0034 "test_overloaded3", [](int) {}, py::arg("i"));
0035 m.def(
0036 "test_overloaded3", [](double) {}, py::arg("d"), "Overload docstr");
0037
0038 options.enable_function_signatures();
0039
0040 m.def(
0041 "test_function3", [](int, int) {}, py::arg("a"), py::arg("b"));
0042 m.def(
0043 "test_function4", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
0044
0045 options.disable_function_signatures().disable_user_defined_docstrings();
0046
0047 m.def(
0048 "test_function5", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
0049
0050 {
0051 py::options nested_options;
0052 nested_options.enable_user_defined_docstrings();
0053 m.def(
0054 "test_function6",
0055 [](int, int) {},
0056 py::arg("a"),
0057 py::arg("b"),
0058 "A custom docstring");
0059 }
0060 }
0061
0062 m.def(
0063 "test_function7", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
0064
0065 {
0066 py::options options;
0067 options.disable_user_defined_docstrings();
0068 options.disable_function_signatures();
0069
0070 m.def("test_function8", []() {});
0071 }
0072
0073 {
0074 py::options options;
0075 options.disable_user_defined_docstrings();
0076
0077 struct DocstringTestFoo {
0078 int value;
0079 void setValue(int v) { value = v; }
0080 int getValue() const { return value; }
0081 };
0082 py::class_<DocstringTestFoo>(m, "DocstringTestFoo", "This is a class docstring")
0083 .def_property("value_prop",
0084 &DocstringTestFoo::getValue,
0085 &DocstringTestFoo::setValue,
0086 "This is a property docstring");
0087 }
0088
0089 {
0090 enum class DocstringTestEnum1 { Member1, Member2 };
0091
0092 py::enum_<DocstringTestEnum1>(m, "DocstringTestEnum1", "Enum docstring")
0093 .value("Member1", DocstringTestEnum1::Member1)
0094 .value("Member2", DocstringTestEnum1::Member2);
0095 }
0096
0097 {
0098 py::options options;
0099 options.enable_enum_members_docstring();
0100
0101 enum class DocstringTestEnum2 { Member1, Member2 };
0102
0103 py::enum_<DocstringTestEnum2>(m, "DocstringTestEnum2", "Enum docstring")
0104 .value("Member1", DocstringTestEnum2::Member1)
0105 .value("Member2", DocstringTestEnum2::Member2);
0106 }
0107
0108 {
0109 py::options options;
0110 options.disable_enum_members_docstring();
0111
0112 enum class DocstringTestEnum3 { Member1, Member2 };
0113
0114 py::enum_<DocstringTestEnum3>(m, "DocstringTestEnum3", "Enum docstring")
0115 .value("Member1", DocstringTestEnum3::Member1)
0116 .value("Member2", DocstringTestEnum3::Member2);
0117 }
0118
0119 {
0120 py::options options;
0121 options.disable_user_defined_docstrings();
0122
0123 enum class DocstringTestEnum4 { Member1, Member2 };
0124
0125 py::enum_<DocstringTestEnum4>(m, "DocstringTestEnum4", "Enum docstring")
0126 .value("Member1", DocstringTestEnum4::Member1)
0127 .value("Member2", DocstringTestEnum4::Member2);
0128 }
0129
0130 {
0131 py::options options;
0132 options.disable_user_defined_docstrings();
0133 options.disable_enum_members_docstring();
0134
0135 enum class DocstringTestEnum5 { Member1, Member2 };
0136
0137 py::enum_<DocstringTestEnum5>(m, "DocstringTestEnum5", "Enum docstring")
0138 .value("Member1", DocstringTestEnum5::Member1)
0139 .value("Member2", DocstringTestEnum5::Member2);
0140 }
0141 }