MetaGPT

Форк
0
/
parse_docstring.py 
43 строки · 1.1 Кб
1
import re
2
from typing import Tuple
3

4

5
def remove_spaces(text):
6
    return re.sub(r"\s+", " ", text).strip() if text else ""
7

8

9
class DocstringParser:
10
    @staticmethod
11
    def parse(docstring: str) -> Tuple[str, str]:
12
        """Parse the docstring and return the overall description and the parameter description.
13

14
        Args:
15
            docstring (str): The docstring to be parsed.
16

17
        Returns:
18
            Tuple[str, str]: A tuple of (overall description, parameter description)
19
        """
20

21

22
class reSTDocstringParser(DocstringParser):
23
    """A parser for reStructuredText (reST) docstring"""
24

25

26
class GoogleDocstringParser(DocstringParser):
27
    """A parser for Google-stype docstring"""
28

29
    @staticmethod
30
    def parse(docstring: str) -> Tuple[str, str]:
31
        if not docstring:
32
            return "", ""
33

34
        docstring = remove_spaces(docstring)
35

36
        if "Args:" in docstring:
37
            overall_desc, param_desc = docstring.split("Args:")
38
            param_desc = "Args:" + param_desc
39
        else:
40
            overall_desc = docstring
41
            param_desc = ""
42

43
        return overall_desc, param_desc
44

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.