function_doc_signature.qbk 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. [section boost/python/function_doc_signature.hpp]
  2. [section Introduction]
  3. Boost.Python supports docstrings with automatic appending of Pythonic and C++ signatures. This feature is implemented by class `function_doc_signature_generator`. The class uses all of the overloads, supplied arg names and default values, as well as the user-defined docstrings, to generate documentation for a given function.
  4. [endsect]
  5. [section Class `function_doc_signature_generator`]
  6. The class has only one public function which returns a list of strings documenting the overloads of a function.
  7. ``
  8. namespace boost { namespace python { namespace objects {
  9. class function_doc_signature_generator
  10. {
  11. public:
  12. static list function_doc_signatures(function const *f);
  13. };
  14. }}}
  15. ``
  16. [endsect]
  17. [section Example]
  18. ``
  19. #include <boost/python/module.hpp>
  20. #include <boost/python/def.hpp>
  21. #include <boost/python/args.hpp>
  22. #include <boost/python/tuple.hpp>
  23. #include <boost/python/class.hpp>
  24. #include <boost/python/overloads.hpp>
  25. #include <boost/python/raw_function.hpp>
  26. using namespace boost::python;
  27. tuple f(int x = 1, double y = 4.25, char const* z = "wow")
  28. {
  29. return make_tuple(x, y, z);
  30. }
  31. BOOST_PYTHON_FUNCTION_OVERLOADS(f_overloads, f, 0, 3)
  32. struct X
  33. {
  34. tuple f(int x = 1, double y = 4.25, char const* z = "wow")
  35. {
  36. return make_tuple(x, y, z);
  37. }
  38. };
  39. BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_f_overloads, X::f, 0, 3)
  40. tuple raw_func(tuple args, dict kw)
  41. {
  42. return make_tuple(args, kw);
  43. }
  44. BOOST_PYTHON_MODULE(args_ext)
  45. {
  46. def("f", f, (arg("x")=1, arg("y")=4.25, arg("z")="wow")
  47. , "This is f's docstring"
  48. );
  49. def("raw", raw_function(raw_func));
  50. def("f1", f, f_overloads("f1's docstring", args("x", "y", "z")));
  51. class_<X>("X", "This is X's docstring", init<>(args("self")))
  52. .def("f", &X::f
  53. , "This is X.f's docstring"
  54. , args("self","x", "y", "z"))
  55. ;
  56. }
  57. ``
  58. Python code: [python]
  59. ``
  60. >>> import args_ext
  61. >>> help(args_ext)
  62. Help on module args_ext:
  63. NAME
  64. args_ext
  65. FILE
  66. args_ext.pyd
  67. CLASSES
  68. Boost.Python.instance(__builtin__.object)
  69. X
  70. class X(Boost.Python.instance)
  71. | This is X's docstring
  72. |
  73. | Method resolution order:
  74. | X
  75. | Boost.Python.instance
  76. | __builtin__.object
  77. |
  78. | Methods defined here:
  79. |
  80. | __init__(...)
  81. | __init__( (object)self) -> None :
  82. | C++ signature:
  83. | void __init__(struct _object *)
  84. |
  85. | f(...)
  86. | f( (X)self, (int)x, (float)y, (str)z) -> tuple : This is X.f's docstring
  87. | C++ signature:
  88. | class boost::python::tuple f(struct X {lvalue},int,double,char const *)
  89. |
  90. | .................
  91. |
  92. FUNCTIONS
  93. f(...)
  94. f([ (int)x=1 [, (float)y=4.25 [, (str)z='wow']]]) -> tuple : This is f's docstring
  95. C++ signature:
  96. class boost::python::tuple f([ int=1 [,double=4.25 [,char const *='wow']]])
  97. f1(...)
  98. f1([ (int)x [, (float)y [, (str)z]]]) -> tuple : f1's docstring
  99. C++ signature:
  100. class boost::python::tuple f1([ int [,double [,char const *]]])
  101. raw(...)
  102. object raw(tuple args, dict kwds) :
  103. C++ signature:
  104. object raw(tuple args, dict kwds)
  105. ``
  106. [endsect]
  107. [endsect]