Extract :param name: description lines from a docstring.
(docstring: str)
| 240 | |
| 241 | |
| 242 | def _parse_param_docs(docstring: str) -> dict[str, str]: |
| 243 | """Extract :param name: description lines from a docstring.""" |
| 244 | params = {} |
| 245 | current_param = None |
| 246 | current_lines = [] |
| 247 | for line in docstring.split("\n"): |
| 248 | stripped = line.strip() |
| 249 | match = re.match(r":param\s+(\w+):\s*(.*)", stripped) |
| 250 | if match: |
| 251 | if current_param: |
| 252 | params[current_param] = " ".join(current_lines).strip() |
| 253 | current_param = match.group(1) |
| 254 | current_lines = [match.group(2)] |
| 255 | elif current_param and stripped and not _FIELD_MARKER.match(stripped): |
| 256 | current_lines.append(stripped) |
| 257 | elif _FIELD_MARKER.match(stripped) or (stripped == "" and current_param): |
| 258 | if current_param: |
| 259 | params[current_param] = " ".join(current_lines).strip() |
| 260 | current_param = None |
| 261 | current_lines = [] |
| 262 | if current_param: |
| 263 | params[current_param] = " ".join(current_lines).strip() |
| 264 | # collapse whitespace |
| 265 | return {k: re.sub(r"\s+", " ", v) for k, v in params.items()} |
| 266 | |
| 267 | |
| 268 | def _parse_return_doc(docstring: str) -> str: |