The source code and dockerfile for the GSW2024 AI Lab.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

62 lines
2.2 KiB

4 weeks ago
  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. m.def("test_overloaded1", [](int) {}, py::arg("i"), "Overload docstring");
  20. m.def("test_overloaded1", [](double) {}, py::arg("d"));
  21. m.def("test_overloaded2", [](int) {}, py::arg("i"), "overload docstring 1");
  22. m.def("test_overloaded2", [](double) {}, py::arg("d"), "overload docstring 2");
  23. m.def("test_overloaded3", [](int) {}, py::arg("i"));
  24. m.def("test_overloaded3", [](double) {}, py::arg("d"), "Overload docstr");
  25. options.enable_function_signatures();
  26. m.def("test_function3", [](int, int) {}, py::arg("a"), py::arg("b"));
  27. m.def("test_function4", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
  28. options.disable_function_signatures().disable_user_defined_docstrings();
  29. m.def("test_function5", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
  30. {
  31. py::options nested_options;
  32. nested_options.enable_user_defined_docstrings();
  33. m.def("test_function6", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
  34. }
  35. }
  36. m.def("test_function7", [](int, int) {}, py::arg("a"), py::arg("b"), "A custom docstring");
  37. {
  38. py::options options;
  39. options.disable_user_defined_docstrings();
  40. py::class_<DocstringTestFoo>(m, "DocstringTestFoo", "This is a class docstring")
  41. .def_property("value_prop", &DocstringTestFoo::getValue, &DocstringTestFoo::setValue, "This is a property docstring")
  42. ;
  43. }
  44. });