MCPcopy Create free account
hub / github.com/pytorch/executorch / get_docstring

Function get_docstring

backends/arm/scripts/docgen/docgen.py:25–55  ·  view source on GitHub ↗

Returns the docstring of an object, formatted in markdown to resemble pytorch-style docs, e.g. an argument list like: Args: arg1: description is converted to Args: - **arg1**: description - **arg2**: description

(obj)

Source from the content-addressed store, hash-verified

23
24
25def get_docstring(obj) -> str:
26 """Returns the docstring of an object, formatted in markdown to resemble
27 pytorch-style docs, e.g. an argument list like:
28
29 Args:
30 arg1: description
31
32 is converted to
33
34 Args:
35 - **arg1**: description
36 - **arg2**: description
37
38 """
39
40 docstring = inspect.getdoc(obj)
41 if docstring is None:
42 print(
43 f"WARNING: Docstring not found for object '{obj.__name__}'. Please document all user facing components of the Arm Backend properly."
44 )
45 docstring = ""
46
47 lines = docstring.split("\n")
48 for line in lines:
49 if ":" in line and line.startswith(" "):
50 new_line = line.strip()
51 pos = new_line.index(":")
52 new_line = f"- **{new_line[:pos]}**" + new_line[pos:]
53 docstring = docstring.replace(line, new_line)
54
55 return docstring
56
57
58def get_function_docstring(cls, func) -> str:

Callers 2

get_function_docstringFunction · 0.85
get_class_docstringFunction · 0.85

Calls 2

splitMethod · 0.80
indexMethod · 0.45

Tested by

no test coverage detected