Parse the summary and long description from a docstring.
(docstring: str)
| 213 | |
| 214 | |
| 215 | def _parse_docstring_body(docstring: str) -> tuple[str, str]: |
| 216 | """Parse the summary and long description from a docstring.""" |
| 217 | lines = docstring.strip().split("\n") |
| 218 | summary = lines[0].strip() if lines else "" |
| 219 | body_lines = [] |
| 220 | in_body = False |
| 221 | for line in lines[1:]: |
| 222 | stripped = line.strip() |
| 223 | if stripped.startswith(":param") or stripped.startswith(":return"): |
| 224 | break |
| 225 | if stripped.startswith("Example"): |
| 226 | break |
| 227 | if not in_body and not stripped: |
| 228 | in_body = True |
| 229 | continue |
| 230 | if in_body: |
| 231 | body_lines.append(stripped) |
| 232 | |
| 233 | long_description = " ".join(body_lines).strip() |
| 234 | # collapse multiple spaces |
| 235 | long_description = re.sub(r"\s+", " ", long_description) |
| 236 | return summary, long_description |
| 237 | |
| 238 | |
| 239 | _FIELD_MARKER = re.compile(r":(?:param|returns?|rtype|type|raises?)\b") |
no test coverage detected