MCPcopy Create free account
hub / github.com/numpy/numpy / _parse_docstrings

Function _parse_docstrings

numpy/_typing/_add_docstring.py:27–57  ·  view source on GitHub ↗

Convert all docstrings in ``_docstrings_list`` into a single sphinx-legible text block.

()

Source from the content-addressed store, hash-verified

25
26
27def _parse_docstrings() -> str:
28 """Convert all docstrings in ``_docstrings_list`` into a single
29 sphinx-legible text block.
30
31 """
32 type_list_ret = []
33 for name, value, doc in _docstrings_list:
34 s = textwrap.dedent(doc).replace("\n", "\n ")
35
36 # Replace sections by rubrics
37 lines = s.split("\n")
38 new_lines = []
39 indent = ""
40 for line in lines:
41 m = re.match(r'^(\s+)[-=]+\s*$', line)
42 if m and new_lines:
43 prev = textwrap.dedent(new_lines.pop())
44 if prev == "Examples":
45 indent = ""
46 new_lines.append(f'{m.group(1)}.. rubric:: {prev}')
47 else:
48 indent = 4 * " "
49 new_lines.append(f'{m.group(1)}.. admonition:: {prev}')
50 new_lines.append("")
51 else:
52 new_lines.append(f"{indent}{line}")
53
54 s = "\n".join(new_lines)
55 s_block = f""".. data:: {name}\n :value: {value}\n {s}"""
56 type_list_ret.append(s_block)
57 return "\n".join(type_list_ret)
58
59
60add_newdoc('ArrayLike', 'typing.Union[...]',

Callers 1

_add_docstring.pyFile · 0.85

Calls 3

replaceMethod · 0.80
splitMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected