MetaGPT
1import re
2from typing import Tuple
3
4
5def remove_spaces(text):
6return re.sub(r"\s+", " ", text).strip() if text else ""
7
8
9class DocstringParser:
10@staticmethod
11def parse(docstring: str) -> Tuple[str, str]:
12"""Parse the docstring and return the overall description and the parameter description.
13
14Args:
15docstring (str): The docstring to be parsed.
16
17Returns:
18Tuple[str, str]: A tuple of (overall description, parameter description)
19"""
20
21
22class reSTDocstringParser(DocstringParser):
23"""A parser for reStructuredText (reST) docstring"""
24
25
26class GoogleDocstringParser(DocstringParser):
27"""A parser for Google-stype docstring"""
28
29@staticmethod
30def parse(docstring: str) -> Tuple[str, str]:
31if not docstring:
32return "", ""
33
34docstring = remove_spaces(docstring)
35
36if "Args:" in docstring:
37overall_desc, param_desc = docstring.split("Args:")
38param_desc = "Args:" + param_desc
39else:
40overall_desc = docstring
41param_desc = ""
42
43return overall_desc, param_desc
44