Skip to content

Commit 8cfd3fb

Browse files
committed
epydoc friendlier formatting
[SVN r39368]
1 parent 62ef542 commit 8cfd3fb

2 files changed

Lines changed: 36 additions & 17 deletions

File tree

src/object/function.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,10 @@ void function::add_to_namespace(
543543

544544
if (docstring_options::show_cpp_signatures_)
545545
{
546-
if(len(_doc))
547-
_doc += "\n "+str(reinterpret_cast<const char*>(detail::cpp_signature_tag));
548-
else
549-
_doc += " "+str(reinterpret_cast<const char*>(detail::cpp_signature_tag));
546+
// if(len(_doc))
547+
// _doc += "\n"+str(reinterpret_cast<const char*>(detail::cpp_signature_tag));
548+
// else
549+
_doc += str(reinterpret_cast<const char*>(detail::cpp_signature_tag));
550550
}
551551
if(_doc)
552552
{
@@ -630,7 +630,7 @@ extern "C"
630630
list signatures = function_doc_signature_generator::function_doc_signatures(f);
631631
if(!signatures) return python::detail::none();
632632
signatures.reverse();
633-
return python::incref( str("\n ").join(signatures).ptr());
633+
return python::incref( str("\n").join(signatures).ptr());
634634
}
635635

636636
static int function_set_doc(PyObject* op, PyObject* doc, void*)

src/object/function_doc_signature.cpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ namespace boost { namespace python { namespace objects {
264264
}
265265

266266
namespace detail {
267-
char py_signature_tag[] = "PY signature : ";
268-
char cpp_signature_tag[] = "C++ signature:";
267+
char py_signature_tag[] = "PY signature :";
268+
char cpp_signature_tag[] = "C++ signature :";
269269
}
270270

271271
list function_doc_signature_generator::function_doc_signatures( function const * f)
@@ -280,24 +280,43 @@ namespace boost { namespace python { namespace objects {
280280
if(*sfi == *fi){
281281
if((*fi)->doc()){
282282
str func_doc = str((*fi)->doc());
283-
int doc_len = len(func_doc);
283+
int doc_len = len(func_doc);
284284
bool show_py_signature = doc_len >=int(sizeof(detail::py_signature_tag)/sizeof(char)-1)
285285
&& str(detail::py_signature_tag)==func_doc.slice(0, int(sizeof(detail::py_signature_tag)/sizeof(char))-1);
286-
bool show_cpp_signature = doc_len >=int(sizeof(detail::cpp_signature_tag)/sizeof(char))
286+
if(show_py_signature){
287+
func_doc = str(func_doc.slice(int(sizeof(detail::py_signature_tag)/sizeof(char))-1, _));
288+
doc_len = len(func_doc);
289+
}
290+
291+
bool show_cpp_signature = doc_len >=int(sizeof(detail::cpp_signature_tag)/sizeof(char)-1)
287292
&& str(detail::cpp_signature_tag)==func_doc.slice(- int(sizeof(detail::cpp_signature_tag)/sizeof(char))+1, _);
288293

289-
str res;
294+
if(show_cpp_signature){
295+
func_doc = str(func_doc.slice(_, 1 - int(sizeof(detail::cpp_signature_tag)/sizeof(char))));
296+
doc_len = len(func_doc);
297+
}
298+
299+
str res="\n";
300+
str pad = "\n";
290301
if(show_py_signature)
291302
{
292303
str sig = pretty_signature(*fi, n_overloads,false);
293304
res+=sig;
294-
if(doc_len > int(sizeof(detail::py_signature_tag)/sizeof(char))-1 )
295-
res+=" : "+func_doc.slice(int(sizeof(detail::py_signature_tag)/sizeof(char))-1,_);
296-
}else
297-
res+=func_doc;
298-
299-
if( show_cpp_signature)
300-
res+=str("\n ")+pretty_signature(*fi, n_overloads,true);
305+
if(doc_len || show_cpp_signature )res+=" :";
306+
pad+= str(" ");
307+
}
308+
309+
if(doc_len){
310+
if(show_py_signature)
311+
res+=pad;
312+
res+= pad.join(func_doc.split("\n"));
313+
}
314+
315+
if( show_cpp_signature){
316+
if(len(res)>1)
317+
res+="\n"+pad;
318+
res+=detail::cpp_signature_tag+pad+" "+pretty_signature(*fi, n_overloads,true);
319+
}
301320

302321
signatures.append(res);
303322
}

0 commit comments

Comments
 (0)