MCPcopy
hub / github.com/ComposioHQ/composio / parse_docstring

Function parse_docstring

python/scripts/generate-docs.py:167–241  ·  view source on GitHub ↗

Parse docstring into components.

(docstring: str | None)

Source from the content-addressed store, hash-verified

165
166
167def parse_docstring(docstring: str | None) -> dict[str, Any]:
168 """Parse docstring into components."""
169 if not docstring:
170 return {
171 "description": "",
172 "params": {},
173 "returns": None,
174 "examples": [],
175 "deprecated": None,
176 }
177
178 lines = docstring.strip().split("\n")
179 description_lines = []
180 params: dict[str, str] = {}
181 returns = None
182 examples: list[str] = []
183 deprecated_lines: list[str] = []
184
185 section = "description"
186 current_param = None
187 example_lines: list[str] = []
188
189 for line in lines:
190 stripped = line.strip()
191
192 # Check for a ``.. deprecated::`` directive (reStructuredText).
193 if re.match(r"\.\.\s+deprecated::", stripped):
194 section = "deprecated"
195 rest = re.sub(r"\.\.\s+deprecated::\s*", "", stripped).strip()
196 if rest:
197 deprecated_lines.append(rest)
198 continue
199
200 # Check for :param name: description
201 param_match = re.match(r":param\s+(\w+):\s*(.*)", stripped)
202 if param_match:
203 section = "params"
204 current_param = param_match.group(1)
205 params[current_param] = param_match.group(2)
206 continue
207
208 # Check for :returns: or :return:
209 return_match = re.match(r":returns?:\s*(.*)", stripped)
210 if return_match:
211 section = "returns"
212 returns = return_match.group(1)
213 continue
214
215 # Check for Example section
216 if stripped.lower().startswith("example"):
217 section = "examples"
218 continue
219
220 # Add to appropriate section
221 if section == "description":
222 description_lines.append(stripped)
223 elif section == "params" and current_param and stripped:
224 params[current_param] += " " + stripped

Callers 2

extract_class_infoFunction · 0.85
mainFunction · 0.85

Calls 3

normalize_exampleFunction · 0.85
groupMethod · 0.80
appendMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…