From 9de994c0d1b03b53809a94565f35e5eb86177c16 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 6 Jun 2007 00:00:57 +0000 Subject: [PATCH] Hans Meine's extra new-line for epydoc with reST compatibility [SVN r37906] --- src/object/function.cpp | 3 ++- test/args.py | 20 ++++++++++---------- test/defaults.py | 6 +++--- test/docstring.py | 32 ++++++++++++++++---------------- test/keywords_test.py | 2 +- 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/object/function.cpp b/src/object/function.cpp index 1f094f42..8226bf59 100644 --- a/src/object/function.cpp +++ b/src/object/function.cpp @@ -507,7 +507,8 @@ void function::add_to_namespace( { if ( PyObject_HasAttrString(mutable_attribute.ptr(), "__doc__") && mutable_attribute.attr("__doc__")) { - mutable_attribute.attr("__doc__") += "\n"; + mutable_attribute.attr("__doc__") += ( + mutable_attribute.attr("__doc__")[-1] != "\n" ? "\n\n" : "\n"); } else { mutable_attribute.attr("__doc__") = ""; diff --git a/test/args.py b/test/args.py index 695a07dc..2dcd9d1b 100644 --- a/test/args.py +++ b/test/args.py @@ -84,24 +84,24 @@ (2, 4.25, 'wow') >>> q.f1() (1, 4.25, 'wow') ->>> q.f2.__doc__.splitlines()[-3] +>>> q.f2.__doc__.splitlines()[-4] "f2's docstring" ->>> X.f.__doc__.splitlines()[:2] -["This is X.f's docstring", 'C++ signature:'] +>>> X.f.__doc__.splitlines()[:3] +["This is X.f's docstring", '', 'C++ signature:'] >>> xfuncs = (X.inner0, X.inner1, X.inner2, X.inner3, X.inner4, X.inner5) >>> for f in xfuncs: ... print f(q,1).value(), ... print f(q, n = 1).value(), ... print f(q, n = 0).value(), -... print f.__doc__.splitlines()[:2] -1 1 0 ['docstring', 'C++ signature:'] -1 1 0 ['docstring', 'C++ signature:'] -1 1 0 ['docstring', 'C++ signature:'] -1 1 0 ['docstring', 'C++ signature:'] -1 1 0 ['docstring', 'C++ signature:'] -1 1 0 ['docstring', 'C++ signature:'] +... print f.__doc__.splitlines()[:3] +1 1 0 ['docstring', '', 'C++ signature:'] +1 1 0 ['docstring', '', 'C++ signature:'] +1 1 0 ['docstring', '', 'C++ signature:'] +1 1 0 ['docstring', '', 'C++ signature:'] +1 1 0 ['docstring', '', 'C++ signature:'] +1 1 0 ['docstring', '', 'C++ signature:'] >>> x = X(a1 = 44, a0 = 22) >>> x.inner0(0).value() diff --git a/test/defaults.py b/test/defaults.py index 0a7599ce..8022f7a4 100644 --- a/test/defaults.py +++ b/test/defaults.py @@ -113,7 +113,7 @@ ... doc = obj.__doc__.splitlines() ... return "\\n".join(["|"+doc[i] for i in args]) ->>> print selected_doc(X.__init__, 0, 2, 4, 6, 8, 9, 10, 12) +>>> print selected_doc(X.__init__, 0, 3, 6, 9, 11, 12, 14, 17) |C++ signature: |C++ signature: |C++ signature: @@ -123,11 +123,11 @@ |C++ signature: |C++ signature: ->>> print selected_doc(Y.__init__, 0, 1) +>>> print selected_doc(Y.__init__, 0, 2) |doc of Y init |C++ signature: ->>> print selected_doc(X.bar2, 0, 2, 4, 6, 8, 9, 10) +>>> print selected_doc(X.bar2, 0, 3, 6, 9, 11, 12, 14) |C++ signature: |C++ signature: |C++ signature: diff --git a/test/docstring.py b/test/docstring.py index d87fcab1..c350d210 100644 --- a/test/docstring.py +++ b/test/docstring.py @@ -8,23 +8,23 @@ ... doc = obj.__doc__.splitlines() ... return "\\n".join(["|"+doc[i] for i in args]) ->>> print selected_doc(X.__init__, 0, 1, 2) +>>> print selected_doc(X.__init__, 0, 1, 3) |this is the __init__ function |its documentation has two lines. |C++ signature: ->>> print selected_doc(X.value, 0, 1, 3, 4, 5) +>>> print selected_doc(X.value, 0, 2, 4, 5, 7) |gets the value of the object |C++ signature: | |also gets the value of the object |C++ signature: ->>> print selected_doc(create, 0, 1) +>>> print selected_doc(create, 0, 2) |creates a new X object |C++ signature: ->>> print selected_doc(fact, 0, 1) +>>> print selected_doc(fact, 0, 2) |compute the factorial |C++ signature: @@ -33,8 +33,8 @@ >>> print selected_doc(fact_usr_off_1, 0) |C++ signature: >>> len(fact_usr_on_1.__doc__.splitlines()) -3 ->>> print selected_doc(fact_usr_on_1, 0, 1) +4 +>>> print selected_doc(fact_usr_on_1, 0, 2) |usr on 1 |C++ signature: >>> len(fact_usr_off_2.__doc__.splitlines()) @@ -42,8 +42,8 @@ >>> print selected_doc(fact_usr_off_2, 0) |C++ signature: >>> len(fact_usr_on_2.__doc__.splitlines()) -3 ->>> print selected_doc(fact_usr_on_2, 0, 1) +4 +>>> print selected_doc(fact_usr_on_2, 0, 2) |usr on 2 |C++ signature: @@ -52,8 +52,8 @@ >>> print selected_doc(fact_sig_off_1, 0) |sig off 1 >>> len(fact_sig_on_1.__doc__.splitlines()) -3 ->>> print selected_doc(fact_sig_on_1, 0, 1) +4 +>>> print selected_doc(fact_sig_on_1, 0, 2) |sig on 1 |C++ signature: >>> len(fact_sig_off_2.__doc__.splitlines()) @@ -61,16 +61,16 @@ >>> print selected_doc(fact_sig_off_2, 0) |sig off 2 >>> len(fact_sig_on_2.__doc__.splitlines()) -3 ->>> print selected_doc(fact_sig_on_2, 0, 1) +4 +>>> print selected_doc(fact_sig_on_2, 0, 2) |sig on 2 |C++ signature: >>> print fact_usr_off_sig_off_1.__doc__ None >>> len(fact_usr_on_sig_on_1.__doc__.splitlines()) -3 ->>> print selected_doc(fact_usr_on_sig_on_1, 0, 1) +4 +>>> print selected_doc(fact_usr_on_sig_on_1, 0, 2) |usr on sig on 1 |C++ signature: >>> len(fact_usr_on_sig_off_1.__doc__.splitlines()) @@ -78,8 +78,8 @@ None >>> print selected_doc(fact_usr_on_sig_off_1, 0) |usr on sig off 1 >>> len(fact_usr_on_sig_on_2.__doc__.splitlines()) -3 ->>> print selected_doc(fact_usr_on_sig_on_2, 0, 1) +4 +>>> print selected_doc(fact_usr_on_sig_on_2, 0, 2) |usr on sig on 2 |C++ signature: >>> print fact_usr_off_sig_off_2.__doc__ diff --git a/test/keywords_test.py b/test/keywords_test.py index aa31b76b..fabf30eb 100644 --- a/test/keywords_test.py +++ b/test/keywords_test.py @@ -80,7 +80,7 @@ >>> f.set(1,1.0,"1") >>> f.a(), f.b(), f.n() (1, 1.0, '1') ->>> f.set2.__doc__.splitlines()[-3] +>>> f.set2.__doc__.splitlines()[-4] "set2's docstring" '''