You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.8 KiB

  1. /*
  2. tests/test_docstring_options.cpp -- generation of docstrings and signatures
  3. Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
  4. All rights reserved. Use of this source code is governed by a
  5. BSD-style license that can be found in the LICENSE file.
  6. */
  7. #include "pybind11_tests.h"
  8. struct DocstringTestFoo {
  9. int value;
  10. void setValue(int v) { value = v; }
  11. int getValue() const { return value; }
  12. };
  13. test_initializer docstring_generation([](py::module &m) {
  14. {
  15. py::options options;
  16. options.disable_function_signatures();
  17. m.def("test_function1", [](int, int) {}, py::arg("a"), py::arg("b"));
  18. m.def("test_function2", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
  19. options.enable_function_signatures();
  20. m.def("test_function3", [](int, int) {}, py::arg("a"), py::arg("b"));
  21. m.def("test_function4", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
  22. options.disable_function_signatures().disable_user_defined_docstrings();
  23. m.def("test_function5", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
  24. {
  25. py::options nested_options;
  26. nested_options.enable_user_defined_docstrings();
  27. m.def("test_function6", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
  28. }
  29. }
  30. m.def("test_function7", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
  31. {
  32. py::options options;
  33. options.disable_user_defined_docstrings();
  34. py::class_<DocstringTestFoo>(m, "DocstringTestFoo", "This is a class docstring")
  35. .def_property("value_prop", &DocstringTestFoo::getValue, &DocstringTestFoo::setValue, "This is a property docstring")
  36. ;
  37. }
  38. });