MCPcopy Create free account
hub / github.com/dot-agent/nextpy / _generate_docstrings

Function _generate_docstrings

scripts/pyi_generator.py:145–194  ·  view source on GitHub ↗

Generate the docstrings for the create method. Args: clzs: The classes to generate docstrings for. props: The props to generate docstrings for. Returns: The docstring for the create method.

(clzs: list[Type[Component]], props: list[str])

Source from the content-addressed store, hash-verified

143
144
145def _generate_docstrings(clzs: list[Type[Component]], props: list[str]) -> str:
146 """Generate the docstrings for the create method.
147
148 Args:
149 clzs: The classes to generate docstrings for.
150 props: The props to generate docstrings for.
151
152 Returns:
153 The docstring for the create method.
154 """
155 props_comments = {}
156 comments = []
157 for clz in clzs:
158 for line in inspect.getsource(clz).splitlines():
159 reached_functions = re.search("def ", line)
160 if reached_functions:
161 # We've reached the functions, so stop.
162 break
163
164 # Get comments for prop
165 if line.strip().startswith("#"):
166 comments.append(line)
167 continue
168
169 # Check if this line has a prop.
170 match = re.search("\\w+:", line)
171 if match is None:
172 # This line doesn't have a var, so continue.
173 continue
174
175 # Get the prop.
176 prop = match.group(0).strip(":")
177 if prop in props:
178 if not comments: # do not include undocumented props
179 continue
180 props_comments[prop] = [
181 comment.strip().strip("#") for comment in comments
182 ]
183 comments.clear()
184 clz = clzs[0]
185 new_docstring = []
186 for line in (clz.create.__doc__ or "").splitlines():
187 if "**" in line:
188 indent = line.split("**")[0]
189 for nline in [
190 f"{indent}{n}:{' '.join(c)}" for n, c in props_comments.items()
191 ]:
192 new_docstring.append(nline)
193 new_docstring.append(line)
194 return "\n".join(new_docstring)
195
196
197def _extract_func_kwargs_as_ast_nodes(

Calls 6

splitMethod · 0.80
joinMethod · 0.80
itemsMethod · 0.80
searchMethod · 0.45
appendMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected