Skip to content

Commit 4d50bf0

Browse files
author
Jonathan Brandmeyer
committed
Concatentation subsequent function docstrings rather than replace the original.
[SVN r27332]
1 parent 1cfa795 commit 4d50bf0

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

doc/v2/class.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,9 @@ <h4><a name="class_-spec-modifiers"></a>Class template
462462
<td>Any <a href="definitions.html#ntbs">ntbs</a>.</td>
463463

464464
<td>Value will be bound to the <code>__doc__</code> attribute
465-
of the resulting method overload.</td>
465+
of the resulting method overload. If an earlier overload
466+
supplied a docstring, two newline characters and the new
467+
docstring are appended to it.</td>
466468
</tr>
467469

468470
<tr>

src/object/function.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,12 @@ void function::add_to_namespace(
472472
if (doc != 0)
473473
{
474474
object attr_copy(attribute);
475-
attr_copy.attr("__doc__") = doc;
475+
if (PyObject_HasAttrString(attr_copy.ptr(), "__doc__") && attr_copy.attr("__doc__")) {
476+
attr_copy.attr("__doc__") += "\n\n";
477+
attr_copy.attr("__doc__") += doc;
478+
}
479+
else
480+
attr_copy.attr("__doc__") = doc;
476481
}
477482
}
478483

test/docstring.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ BOOST_PYTHON_MODULE(docstring_ext)
4747
)
4848
.def("value", &X::value,
4949
"gets the value of the object")
50+
.def( "value", &X::value,
51+
"also gets the value of the object")
5052
;
5153

5254
def("create", create, return_value_policy<manage_new_object>(),

test/docstring.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@
1515
this is the __init__ function
1616
its documentation has two lines.
1717
18-
>>> printdoc(X.value)
19-
gets the value of the object
20-
2118
>>> printdoc(create)
2219
creates a new X object
2320
2421
>>> printdoc(fact)
2522
compute the factorial
2623
'''
2724

25+
def check_double_string():
26+
"""
27+
>>> assert check_double_string() == True
28+
"""
29+
from docstring_ext import X
30+
return X.value.__doc__ == "gets the value of the object\n\nalso gets the value of the object"
31+
2832
def run(args = None):
2933
import sys
3034
import doctest

0 commit comments

Comments
 (0)