chiark / gitweb /
documentation/python: minor cleanup.
authorVladimír Vondruš <mosra@centrum.cz>
Tue, 27 Aug 2019 11:09:50 +0000 (13:09 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Tue, 27 Aug 2019 14:59:52 +0000 (16:59 +0200)
documentation/python.py

index a696772eea075ac3246bbe4fe72f9ea882b3e134..6c70b9f347d42f3ce00652a1c7f4ce86e549fd1b 100755 (executable)
@@ -719,13 +719,13 @@ def parse_pybind_signature(state: State, referrer_path: List[str], signature: st
         end = original_signature.find('\n')
         logging.warning("cannot parse pybind11 function signature %s", original_signature[:end if end != -1 else None])
         if end != -1 and len(original_signature) > end + 1 and original_signature[end + 1] == '\n':
-            summary = take_first_paragraph(inspect.cleandoc(original_signature[end + 1:]))
+            summary = inspect.cleandoc(original_signature[end + 1:]).partition('\n\n')[0]
         else:
             summary = ''
         return (name, summary, [('…', None, None, None)], None)
 
     if len(signature) > 1 and signature[1] == '\n':
-        summary = take_first_paragraph(inspect.cleandoc(signature[2:]))
+        summary = inspect.cleandoc(signature[2:]).partition('\n\n')[0]
     else:
         summary = ''
 
@@ -776,19 +776,15 @@ def format_value(state: State, referrer_path: List[str], value: str) -> Optional
     else:
         return None
 
-def take_first_paragraph(doc: str) -> str:
-    end = doc.find('\n\n')
-    return doc if end == -1 else doc [:end]
-
 def extract_summary(state: State, external_docs, path: List[str], doc: str) -> str:
     # Prefer external docs, if available
     path_str = '.'.join(path)
     if path_str in external_docs and external_docs[path_str]['summary']:
         return render_inline_rst(state, external_docs[path_str]['summary'])
 
-    if not doc: return '' # some modules (xml.etree) have that :(
+    # some modules (xml.etree) have None as a docstring :(
     # TODO: render as rst (config option for that)
-    return html.escape(take_first_paragraph(inspect.cleandoc(doc)))
+    return html.escape(inspect.cleandoc(doc or '').partition('\n\n')[0])
 
 def extract_docs(state: State, external_docs, path: List[str], doc: str) -> Tuple[str, str]:
     path_str = '.'.join(path)
@@ -803,7 +799,7 @@ def extract_docs(state: State, external_docs, path: List[str], doc: str) -> Tupl
     else:
         # some modules (xml.etree) have None as a docstring :(
         # TODO: render as rst (config option for that)
-        summary = html.escape(take_first_paragraph(inspect.cleandoc(doc or '')))
+        summary = html.escape(inspect.cleandoc(doc or '').partition('\n\n')[0])
 
     # Content
     if external_doc_entry and external_doc_entry['content']: