MCPcopy Create free account
hub / github.com/apache/arrow / _get_docstring

Function _get_docstring

python/scripts/update_stub_docstrings.py:64–87  ·  view source on GitHub ↗

Extract and format a docstring for insertion into a stub file.

(name, module, indentation)

Source from the content-addressed store, hash-verified

62
63
64def _get_docstring(name, module, indentation):
65 """Extract and format a docstring for insertion into a stub file."""
66 obj, parent, obj_name = _resolve_object(module, name)
67 if obj is None:
68 print(f"{name} not found in {module.__name__}")
69 return None
70
71 docstring = inspect.getdoc(obj)
72 if not docstring:
73 return None
74
75 # Remove signature prefix
76 parent_name = getattr(parent, "__name__", None) if parent else None
77 if docstring.startswith(obj_name) or (
78 parent_name and docstring.startswith(f"{parent_name}.{obj_name}")
79 ):
80 docstring = "\n".join(docstring.splitlines()[2:])
81
82 # Skip empty docstrings
83 if not docstring.strip():
84 return None
85
86 prefix = " " * indentation
87 return '"""\n' + indent(docstring + '\n"""', prefix)
88
89
90class DocstringInserter(libcst.CSTTransformer):

Callers 3

leave_ModuleMethod · 0.85
leave_ClassDefMethod · 0.85
leave_FunctionDefMethod · 0.85

Calls 2

_resolve_objectFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected