Fix: bt2: _trim_docstring(): docstring can have 0 or 1 line
[babeltrace.git] / src / bindings / python / bt2 / bt2 / component.py
index f4aa8e8003104b5448937d7ddcfcc88b064be260..df62ae639bc3022c2d06db25c91f4404794eea0a 100644 (file)
@@ -345,17 +345,22 @@ def _create_component_class_from_const_ptr_and_get_ref(ptr, comp_cls_type):
 
 def _trim_docstring(docstring):
     lines = docstring.expandtabs().splitlines()
+
+    if len(lines) == 0:
+        return ''
+
     indent = sys.maxsize
 
-    for line in lines[1:]:
-        stripped = line.lstrip()
+    if len(lines) > 1:
+        for line in lines[1:]:
+            stripped = line.lstrip()
 
-        if stripped:
-            indent = min(indent, len(line) - len(stripped))
+            if stripped:
+                indent = min(indent, len(line) - len(stripped))
 
     trimmed = [lines[0].strip()]
 
-    if indent < sys.maxsize:
+    if indent < sys.maxsize and len(lines) > 1:
         for line in lines[1:]:
             trimmed.append(line[indent:].rstrip())
 
This page took 0.023222 seconds and 4 git commands to generate.